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 分钟前
110-多模型热切换-API网关-LiteLLM代理-负载均衡故障转移
运维·python·负载均衡
牛油果子哥q5 分钟前
C++STL算法超全精讲:排序/查找/去重/遍历/最值/合并全套API、仿函数、Lambda适配、实战避坑
开发语言·c++·算法
Xeon_CC12 分钟前
用C++编写屏幕准星
开发语言·c++
孤存52217 分钟前
c语言动态内存管理
c语言·开发语言·算法
Ali8852019 分钟前
Python字符串方法速查表大全
前端·python
开源量化GO22 分钟前
近期量化实现:API 数据、策略逻辑和交易执行要连成一条线
人工智能·python
小柯南敲键盘27 分钟前
跨马翻译:跨境电商批量图片翻译与视频字幕工具推荐
人工智能·python·音视频
冰暮流星30 分钟前
javascript之webstorage用法
开发语言·javascript·ecmascript
我一定会有钱33 分钟前
打造完美工作流:Git 配置”一次推送,三端同步”(Gitee/GitCode/GitHub)
开发语言·windows·vscode·搜索引擎·gitlab·github·visual studio code
matlab代码1 小时前
基于matlab肤色人脸标记检测系统 GUI界面【源码53期】
开发语言·matlab·人脸标记