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)

评分算法:

相关推荐
禾小西31 分钟前
07丨Redis 哨兵机制:主库故障后,如何恢复服务?
java·开发语言·redis
我不是阵雨35 分钟前
JDK 21虚拟线程Pinning陷阱:一文拔钉解困
java·开发语言
全栈练习生1 小时前
AI Agent 沙箱
python·ai
徐小黑ACG1 小时前
Golang 基础05 结构体struct
开发语言·算法·golang
优橙教育1 小时前
零基础学AI应用开发要多久?3个月能到什么水平
服务器·开发语言·网络·php
SEO_juper2 小时前
用 Python 写一个 GEO 可见性检查脚本:你的网站现在能被 AI 引用吗
开发语言·人工智能·爬虫·python·seo·外贸独立站
西柚小萌新2 小时前
【LLM&&AI应用开发 八股文】--4.3.Agent智能体(下)
java·开发语言·数据库
北极有牛2 小时前
cpp学习笔记--常量指针
java·开发语言·算法
半杯咖啡半行码3 小时前
C++ 编程与 STL 模板:从泛型编程到内存安全详解
开发语言·c++
caoerzhong3 小时前
JeeWMS 开源 WMS 部署避坑指南:Java 仓库管理系统的环境基线、四类根因与可复现交付
java·开发语言·开源