5-9 scikit-learn中的回归算法
import matplotlib.pyplot as plt
from sklearn import datasets
boston = datasets.load_boston()
x = boston.data
y = boston.target
x = x[y < 50.0]
y = y[y < 50.0]Linear Regression
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=666)
from sklearn.linear_model import LinearRegression
lin_reg = LinearRegression()
lin_reg.fit(X_train, y_train)
lin_reg.score(X_test, y_test)KNN Regressor
默认算法
网络搜索
输入:grid_search.best_params_
输出:{'n_neighbors': 5, 'p': 1, 'weights': 'distance'}
输入:grid_search.best_score_
输出:0.6340477954176972
输入:grid_search.best_estimator_.score(X_test, y_test)
输出:0.7044357727037996
Last updated