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)

评分算法:

相关推荐
SailingCoder1 小时前
Go 线上偶发数据错乱:值拷贝、slice、并发 map 的识别与规避
开发语言·后端·golang
峥嵘life1 小时前
Android 17 具体代码新特性总结
android·开发语言·网络
HackTwoHub1 小时前
ARTEX 开源后继版本持续维护,AI 自主渗透测试系统保留完整能力12月持续更新
开发语言·人工智能·web安全·网络安全·开源·系统安全·php
Lethehong1 小时前
从轻点到落块:Rokid AIUI 游戏《叠叠乐》开发实践
java·开发语言·游戏
zc.z1 小时前
Context Engineering:深度学习知识点
python·prompt·上下文工程
5G微创业2 小时前
短视频去水印接口怎么对接?一篇讲清 GET 参数、返回字段与多语言示例
python·小程序·api·短视频·去水印
全速向光2 小时前
用 Three.js 从零打造一棵会发光的 3D 圣诞树
开发语言·javascript·3d
布语world2 小时前
某东pc滑块分析
前端·javascript·网络·python·安全
codeejun2 小时前
每日一Go·MySQL-28、账户转账事务设计
开发语言·mysql·golang
m0_646429972 小时前
Python pytest 单元测试基础
python