02房价预测

目录

代码

评分算法:


代码

复制代码
import numpy as np
from sklearn import datasets
from sklearn.linear_model import LinearRegression

# 指定版本才有数据集
# C:\Users\14817\PycharmProjects\pythonProject1\venv\Scripts\activate.bat
# pip install scikit-learn==1.0
# FutureWarning: Function load_boston is deprecated; `load_boston` is deprecated in 1.0 and will be removed in 1.2.

boston = datasets.load_boston()

X = boston['data']     # 数据
y = boston['target']   # 房价
feature_names = boston['feature_names']  # 具体指标

# 切分数据
index = np.array(range(506))
np.random.shuffle(index)

train_index = index[:405]
test_index = index[405:]

# 80%的训练数据
X_train = X[train_index]
y_train = y[train_index]

X_test = X[test_index]
y_test = y[test_index]

# 数据建模
np.set_printoptions(suppress=True)
model = LinearRegression(fit_intercept=True)
model.fit(X_train, y_train)

# 模型应用
y_pred = model.predict(X_test).round(2)
print(y_pred)
print(y_test)

#模型评分
#负数到1之间 ,1 最高分
score = model.score(X_test,y_test)
print(score)

评分算法:

相关推荐
战略性的菠萝12 分钟前
研究生基础-Python快速入门(终)——面向对象
python
陈皮波比茶17 分钟前
Python项目实战-网络机器人(爬虫)
开发语言·网络·爬虫·python·机器人
winfredzhang1 小时前
从零构建家庭照片管理系统:Django 模块化单体实战,以及我踩到的 4 个真实坑
python·postgresql·django·sqlite·bootsrap
jyOverQ1 小时前
LangGraph 流式执行详解:stream、astream 与 stream_mode 怎么选?
python·langchain
法哥20121 小时前
用 C++ 控制 CMW100,到底在干什么?
开发语言·c++
闲猫1 小时前
LangGraph / Capabilities / Stores
python·agent·langgraph
QH139292318801 小时前
NVIDIA H200 H300服务器
运维·服务器·开发语言·网络·信息与通信
pjj198542 小时前
机器学习-NumPy2
人工智能·python·机器学习
OPEN-F2 小时前
Python进阶教程:单元测试与代码质量
开发语言·python·单元测试
阿里嘎多学长2 小时前
2026-08-20 GitHub 热点项目精选
开发语言·程序员·github·代码托管