机器学习波士顿房价

流程

  1. 数据获取
  2. 导入需要的包
  3. 引入文件,查看内容
  4. 划分训练集和测试集
  5. 调用模型
  6. 查看准确率

数据获取

链接:https://pan.baidu.com/s/1deECYRPQFx8h28BvoZcbWw?pwd=ft5a 
提取码:ft5a 
--来自百度网盘超级会员V1的分享

导入需要的包

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error

引入文件查看内容

data= pd.read_csv("boston.csv")
data.head()

波士顿房价
波士顿房价

划分训练集和测试集

x ,r = data[data.columns.delete(-1)], data['MEDV']
x_train, x_test, r_train, r_test = train_test_split(x, r, test_size=0.2, random_state=888)

查看训练集和测试集合大小

print(x_train.shape,r_train.shape)
print(x_test.shape,r_test.shape)
#(404, 13) (404,)
#(102, 13) (102,)

调用模型训练数据

linear_model = LinearRegression()
linear_model.fit(x_train, r_train)

查看准确率

line_pre = linear_model.predict(x_test)
print('SCORE:{:.4f}'.format(linear_model.score(x_test, r_test)))
#SCORE:0.7559

相关推荐

  1. sklearn教程:boston波士顿房价数据集

    2024-04-20 18:58:04       55 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-20 18:58:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-20 18:58:04       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-20 18:58:04       82 阅读
  4. Python语言-面向对象

    2024-04-20 18:58:04       91 阅读

热门阅读

  1. 机器学习实验------随机森林

    2024-04-20 18:58:04       36 阅读
  2. 富格林:翻出虚假陷阱保障安全

    2024-04-20 18:58:04       28 阅读
  3. Elasticsearch 索引文档的过程

    2024-04-20 18:58:04       34 阅读
  4. Kafka 源码解析 - Kafka Consumer设计解析

    2024-04-20 18:58:04       37 阅读
  5. vue+vite+elements

    2024-04-20 18:58:04       29 阅读
  6. python模式设计之责任链模式

    2024-04-20 18:58:04       36 阅读
  7. Git常用命令

    2024-04-20 18:58:04       32 阅读
  8. Hive:日期函数

    2024-04-20 18:58:04       41 阅读
  9. IP地址和物理地址的理解

    2024-04-20 18:58:04       37 阅读
  10. 匿名函数lambda

    2024-04-20 18:58:04       38 阅读