机器学习保姆级入门案例-波士顿房价预测

利用scikit-learn进行机器学习入门案例

相信很多人都是知道波士顿房价的数据集,一个非常经典的机器学习入门案例数据集。在这个案例中直接使用sklearn中自带的数据集来进行数据分析和建模,主要内容包含:

  • 数据探索
  • 相关性分析
  • 变量研究
  • 线性回归模型探索
  • 模型改进

机器学习保姆级入门案例-波士顿房价预测

; 导入库

import numpy as np
import pandas as pd
import hvplot.pandas
import matplotlib.pyplot as plt
%matplotlib inline

%config InlineBackend.figure_format = 'retina'
import seaborn as sns

plt.style.use("fivethirtyeight")

pd.set_option('display.float_format', lambda x: '{:.3f}'.format(x))

from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error

import warnings

导入内置数据

导数据

从sklearn中导入内置的波士顿房价数据集:

boston = datasets.load_boston()
X = boston.data
y = boston.target

df = pd.DataFrame(
    X,
    columns = boston.feature_names
)
df.head()

机器学习保姆级入门案例-波士顿房价预测
df["MEDV"] = y
df.head()

机器学习保姆级入门案例-波士顿房价预测

查看数据字段、类型:

机器学习保姆级入门案例-波士顿房价预测

`python
df.info()


RangeIndex: 506 entries, 0 to 505
Data columns (total 14 columns):

Original: https://blog.csdn.net/qq_25443541/article/details/123466330
Author: 尤尔小屋的猫
Title: 机器学习保姆级入门案例-波士顿房价预测

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/613324/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球