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)

评分算法:

相关推荐
databook6 小时前
Manim实现脉冲闪烁特效
后端·python·动效
程序设计实验室6 小时前
2025年了,在 Django 之外,Python Web 框架还能怎么选?
python
倔强青铜三8 小时前
苦练Python第46天:文件写入与上下文管理器
人工智能·python·面试
用户25191624271111 小时前
Python之语言特点
python
刘立军12 小时前
使用pyHugeGraph查询HugeGraph图数据
python·graphql
数据智能老司机15 小时前
精通 Python 设计模式——创建型设计模式
python·设计模式·架构
数据智能老司机16 小时前
精通 Python 设计模式——SOLID 原则
python·设计模式·架构
c8i18 小时前
django中的FBV 和 CBV
python·django
c8i18 小时前
python中的闭包和装饰器
python
这里有鱼汤21 小时前
小白必看:QMT里的miniQMT入门教程
后端·python