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)

评分算法:

相关推荐
张铁霖10 分钟前
深度解析:AI三次浪潮与机器学习三种范式,
python
会议咨询17 分钟前
2026年计算机技术、信息工程与机器学习国际会议(CIML 2026)
机器学习·计算机技术·信息工程
学也学不废19 分钟前
论文阅读:Advancing Semantic Textual Similarity Modeling
python
悠仁さん31 分钟前
【C++】vector 类
开发语言·c++
风早爽太35 分钟前
Python 开发笔记:配置生产环境中 Celery Worker 的独立进程启动方式
python·fastapi
_upupup41 分钟前
智能指针的原理及简单模拟实现(C++)
开发语言·c++
打工仔折腾 AI1 小时前
飞牛OS上用Docker Compose部署ExerciseDiary运动记录并配置远程访问
运维·人工智能·后端·python·docker·容器·ai agent 实战
en.en..1 小时前
C语言---宏
c语言·开发语言
郝学胜-神的一滴1 小时前
C++ Templates 01:拨开迷雾,读懂C++模板经典著作
开发语言·c++·程序人生·游戏·游戏引擎·软件构建
小蒜学长1 小时前
基于Python的动物救助站管理系统的设计与实现(代码+数据库+LW)
数据库·后端·python·django·动物救助