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)

评分算法:

相关推荐
larance1 分钟前
Flask 发送邮件
后端·python·flask
m0_748240253 分钟前
python轻量级框架-flask
开发语言·python·flask
论迹15 分钟前
【JavaEE】-- 多线程(初阶)2
java·开发语言·java-ee
pk_xz12345616 分钟前
基于Python和Neo4j开发的医疗辅助诊断系统的详细实现步骤和代码示例
python·oracle·neo4j
+72025 分钟前
如何在java中用httpclient实现rpc post 请求
java·开发语言·rpc
学习两年半的Javaer34 分钟前
Rust语言基础知识详解【一】
开发语言·rust
PyAIGCMaster35 分钟前
50周学习go语言:第四周 函数与错误处理深度解析
开发语言·学习·golang
全栈开发圈36 分钟前
新书速览|Rust汽车电子开发实践
开发语言·rust·汽车
PyAIGCMaster37 分钟前
第二周补充:Go语言中&取地址符与fmt函数详解
开发语言·后端·golang
星霜旅人39 分钟前
开源机器学习框架
人工智能·机器学习·开源