import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from sklearn import datasets,metrics
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import TruncatedSVD
%matplotlib inline
导入数据
boston = datasets.load_boston()
boston.feature_names
划分训练集和测试集并使数据正规化
X = boston.data
y = boston.target
scale = StandardScaler()
normal_X = scale.fit_transform(X)
X_train, X_test, y_train, y_test = train_test_split(normal_X, y, test_size=0.1, random_state=42)
显示数据直方图
# 显示数据
plt.hist(X_train[:,0], bins=20)
plt.hist(X_train[:,2], bins=20, alpha=0.3)<