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)

评分算法:

相关推荐
Irissgwe11 分钟前
十、LangGraph能力详解:LangGraph 的其他特性
python·ai·langchain·langgraph
阿文的代码库14 分钟前
机器学习任务二分类的应用案例
人工智能·机器学习·分类
吴阿福|一人公司17 分钟前
类变量和实例变量的命名规范有哪些避坑点?
开发语言·python
Aaswk18 分钟前
Java项目:文件批量处理工具
java·开发语言·vscode·idea
zhoupenghui16826 分钟前
AI大模型应用部署之Flask框架使用
运维·python·docker·容器·flask·flask框架
ckjoker30 分钟前
手敲三Agent串行流水线,我发现了多Agent协作的隐形杀手
python·agent
稷下元歌30 分钟前
七天学会plc加机器视觉之AI 接入 外设模块开发全详细操作文档(全程配套视频按文档实操)
python·sql·qt·贪心算法·r语言·wpf·时序数据库
晚风吹红霞31 分钟前
深入浅出 STL 之 map 与 set:从入门到实战
开发语言·c++
じ☆冷颜〃31 分钟前
Picard–Lindelöf定理在CS中的应用:理论框架与算法基础
人工智能·经验分享·笔记·算法·机器学习
不知名的老吴36 分钟前
机器学习评价之基础指标
人工智能·算法·机器学习