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)

评分算法:

相关推荐
爱写代码的小朋友5 分钟前
从零开始学 Win32 API:C++ 窗口编程实战(VS Code + MinGW-w64 命令行详解)
开发语言·c++
yangshicong8 分钟前
第19章:AI安全防护与AI安全
人工智能·python·安全·prompt·ai编程
果汁华9 分钟前
Function Calling 与 Python 实战完整指南
开发语言·网络·python
c_lb728821 分钟前
2026年不同基础做量化,先找AI能参与的位置
人工智能·python
小小晓.28 分钟前
C++:语句和作用域
开发语言·c++
wanderist.1 小时前
Lambda表达式在算法竞赛中的应用
java·开发语言·算法
chenment2 小时前
ComfyUI 自定义节点开发:从零扩展你的图像生成工作流
python·stable diffusion
海天鹰2 小时前
PHP上传文件
android·开发语言·php
chenyuhao20242 小时前
第一章_自动驾驶中的社会交互
人工智能·机器学习·自动驾驶