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)

评分算法:

相关推荐
Mrliu__7 分钟前
Python数据结构(七):Python 高级排序算法:希尔 快速 归并
数据结构·python·排序算法
C嘎嘎嵌入式开发12 分钟前
(22)100天python从入门到拿捏《【网络爬虫】网络基础与HTTP协议》
网络·爬虫·python
脚踏实地的大梦想家14 分钟前
【Go】P11 掌握 Go 语言函数(二):进阶玩转高阶函数、闭包与 Defer/Panic/Recover
开发语言·后端·golang
秋空樱雨23 分钟前
C++入门
开发语言·c++
咬_咬43 分钟前
C++仿mudo库高并发服务器项目:Buffer模块
服务器·开发语言·c++·缓冲区·buffer·muduo库
江公望1 小时前
Qt qmlplugindump浅谈
开发语言·qt·qml
曦樂~1 小时前
【Qt】文件操作/事件--mainwindow做编辑器
开发语言·qt
zzzyulin1 小时前
huggingface transformers调试问题--加载本地路径模型时pdb断点消失
python·transformer
敲代码的瓦龙1 小时前
西邮移动应用开发实验室2025年二面题解
开发语言·c++·算法
laocooon5238578861 小时前
一个适合新手的训练C题
c语言·开发语言