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)

评分算法:

相关推荐
小雨中_1 分钟前
2.9 TRPO 与 PPO:从“信赖域约束”到“近端裁剪”的稳定策略优化
人工智能·python·深度学习·机器学习·自然语言处理
小雨中_3 分钟前
2.5 动态规划方法
人工智能·python·深度学习·算法·动态规划
癫狂的兔子7 分钟前
【Python】【机器学习】DBSCAN算法
人工智能·机器学习
FirstFrost --sy9 分钟前
高并发内存池:tcmalloc核心实现
开发语言
彩妙不是菜喵12 分钟前
C++:深入浅出讲解=>多态
开发语言·c++
癫狂的兔子28 分钟前
【Python】【机器学习】决策树
python·决策树·机器学习
智算菩萨37 分钟前
【Python小游戏】基于Pygame的递归回溯迷宫生成与BFS寻路实战:从算法原理到完整游戏架构的深度解析
python·算法·pygame
Zzz 小生43 分钟前
LangChain Short-term memory:短期记忆使用完全指南
人工智能·python·langchain·github
qq_24218863321 小时前
使用 PyInstaller 打包 Python 脚本为 EXE(教程)
开发语言·python
苦学编程的谢1 小时前
好运buff机 ------ 测试报告
java·开发语言·功能测试