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)

评分算法:

相关推荐
mounter6254 分钟前
GCCRS 突破与 Rust 入核:Linux 工具链的重大变革
linux·开发语言·rust·linux kernel·kernel
Buke..5 分钟前
【APP 逆向】哔哩哔哩 sign 参数逆向(上):Frida 反调试绕过与 unidbg 调用
java·开发语言·爬虫·python·安卓
147API15 分钟前
蒸馏训练效果差,怎样判断问题是不是出在数据
人工智能·深度学习·机器学习
abcefg_h23 分钟前
MCP 实战指南:如何在项目中使用 Model Context Protocol 及其通信原理
开发语言·后端·golang·mcp
头发够用的程序员34 分钟前
ImportError: libopenblas.so.0: cannot open shared object file 完整复盘与解决方案
python·ubuntu
何以解忧,唯有..1 小时前
Python 线程编程:从入门到实战
开发语言·python
l1258651 小时前
# RAG上线评估指标体系:六大核心指标与压测实战全解析
数据库·人工智能·python·mysql·langchain·milvus
我命由我123451 小时前
人脸识别 - 人脸识别选帧
java·人工智能·python·算法·安全·java-ee·人脸识别
SomeB1oody2 小时前
【RustyML入门】7.2. 深入模型持久化
开发语言·后端·机器学习·rust·教程