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)

评分算法:

相关推荐
天水幼麟2 分钟前
python学习笔记(深度学习)
笔记·python·学习
巴里巴气5 分钟前
安装GPU版本的Pytorch
人工智能·pytorch·python
wt_cs26 分钟前
银行回单ocr api集成解析-图像文字识别-文字识别技术
开发语言·python
_WndProc1 小时前
【Python】Flask网页
开发语言·python·flask
互联网搬砖老肖1 小时前
Python 中如何使用 Conda 管理版本和创建 Django 项目
python·django·conda
测试者家园1 小时前
基于DeepSeek和crewAI构建测试用例脚本生成器
人工智能·python·测试用例·智能体·智能化测试·crewai
liujing102329291 小时前
Day04_刷题niuke20250703
java·开发语言·算法
大模型真好玩1 小时前
准确率飙升!Graph RAG如何利用知识图谱提升RAG答案质量(四)——微软GraphRAG代码实战
人工智能·python·mcp
前端付豪1 小时前
11、打造自己的 CLI 工具:从命令行到桌面效率神器
后端·python
前端付豪1 小时前
12、用类写出更可控、更易扩展的爬虫框架🕷
后端·python