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)

评分算法:

相关推荐
工业一体机老司机3 小时前
Python实现工业一体机Modbus-TCP通信-从协议解析到多设备轮询实战
开发语言·python·tcp/ip
爱分享的康康3 小时前
自动驾驶 HiL 测试选型|主流方案、供应商评估与仿真技术解析
人工智能·机器学习·自动驾驶
fpcc3 小时前
跟我学C++中级篇—static_assert和assert
开发语言·c++
2401_885885043 小时前
国际语音php接口代码示例:PHP使用cURL快速调用语音发送API
android·开发语言·前端·人工智能·python·php·语音识别
萌动的小火苗3 小时前
Linux进程线程面试题【无答案】
linux·运维·服务器·c语言·开发语言
EW Frontier3 小时前
基于 Python + NumPy 的雷达信号处理仿真平台设计与实现——从 LFM 波形到 CFAR 检测的完整信号链
python·雷达信号处理·cfar\]·mti·mtd
axinawang4 小时前
Tesseract入门--把图片里印刷文字提取成文本
python
️学习的小王4 小时前
AI Agent Skills实战教程:从原理到上手编写SKILL.md
人工智能·深度学习·学习·机器学习
青 春 记 忆4 小时前
LeetCode 283. 移动零|Python 解法详解
python·算法·leetcode
Zenova EdgeOS4 小时前
C++ 工业边缘 Boost.Asio 高级实战
开发语言·c++·边缘计算·工业网关