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)

评分算法:

相关推荐
Julien200410 分钟前
管理机密(一)
运维·服务器·开发语言·学习方法
Chen_harmony13 分钟前
七、STL与string类
开发语言·c++
沐晓时光20 分钟前
C语言入门,字符串和字符串函数知识讲解
c语言·开发语言
小小张说故事32 分钟前
Python 的 obj.x 到底按什么顺序找?拆开数据描述符、实例字典和 __getattr__ 那条优先级链
python
xxxiugou12339 分钟前
C++命名空间与引用全解析
开发语言·c++
硅谷秋水2 小时前
DiscoveryRSI:通过递归学习发现有价值的假设
人工智能·机器学习·语言模型
用户11481867894842 小时前
水印的实现方式逻辑
前端·python
贾公子2 小时前
从单条内容到账号维度——AIGC 风险评分的工程实现
后端·python
hkNaruto2 小时前
【AI】游戏大模型智能体OODA过程记忆问题解决方案:AgenticSTS 有界记忆契约:技术分析与流水线改造操作手册
人工智能·游戏·机器学习
yangmu32032 小时前
编程语言发展简史:从机器指令到智能协作
开发语言