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)

评分算法:

相关推荐
麻瓜老宋5 分钟前
AI开发C语言应用按步走,表达式计算器calc的第四步,交互式 REPL 模式
c语言·开发语言·atomcode
旅僧11 分钟前
王树森老师强化学习--同声传译版3
python·深度学习
梦想不只是梦与想15 分钟前
python中精度处理:decimal
python·float·精度丢失·decimal·浮点运算
猫猫不是喵喵.15 分钟前
双亲委派机制与类加载过程
java·开发语言
大模型码小白18 分钟前
向量化引擎与 AI 排障:当 SIMD 遇到异常检测,存储诊断的范式转移
java·大数据·数据库·人工智能·python
布朗克16829 分钟前
Go入门到精通-22-同步原语
开发语言·后端·golang·同步原语
fpcc29 分钟前
AI和大模型——梯度散度和旋度
人工智能·机器学习
雪的季节31 分钟前
【无标题】
linux·服务器·python
帅次42 分钟前
Kotlin Flow 与 StateFlow:UI 单向数据流基础
开发语言·ui·kotlin·stateflow·onlifecycle
艾伦野鸽ggg1 小时前
JavaScript 浏览器本地存储
开发语言·javascript·ecmascript