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)

评分算法:

相关推荐
快乐的哈士奇几秒前
【Next.js实战①】Gmail API 按柜号检索邮件:OAuth 双 Cookie 与搜索 Fallback
开发语言·javascript·ecmascript
weixin_307779135 分钟前
Python写入Shell文件使用Linux系统的换行符
linux·开发语言·python·自动化
zmzb010324 分钟前
Python课后习题训练记录Day130
开发语言·python
阿里嘎多学长38 分钟前
2026-06-13 GitHub 热点项目精选
开发语言·程序员·github·代码托管
xiaoshuaishuai81 小时前
C# 委托与事件
开发语言·c#
kmblack11 小时前
javascript计算年龄
开发语言·javascript·ecmascript
高洁011 小时前
医疗行业的数字孪生革命
python·机器学习·数据挖掘·transformer·知识图谱
MATLAB代码顾问1 小时前
Python Pandas数据分析入门指南
python·数据分析·pandas
肖爱Kun1 小时前
STL标准模块库操作
开发语言·音视频
风之所往_1 小时前
Python 3.6 新特性全面总结
python