Last active
September 25, 2015 20:51
-
-
Save MechCoder/5557d5837e72bb0b73cf to your computer and use it in GitHub Desktop.
Example code for the HuberEstimator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sklearn.datasets import make_regression, load_boston | |
from sklearn.linear_model import HuberRegressor | |
from sklearn.metrics import mean_squared_error | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.grid_search import GridSearchCV | |
from sklearn.utils.estimator_checks import NotAnArray, _boston_subset | |
boston = load_boston() | |
X, y = boston.data, boston.target | |
X = StandardScaler().fit_transform(X) | |
y = StandardScaler().fit_transform(y) | |
huber = HuberRegressor(fit_intercept=True) | |
huber.fit(X, y) | |
y_pred = huber.predict(X) | |
print(mean_squared_error(y, y_pred)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment