Skip to content

Instantly share code, notes, and snippets.

@MechCoder
Last active September 25, 2015 20:51
Show Gist options
  • Save MechCoder/5557d5837e72bb0b73cf to your computer and use it in GitHub Desktop.
Save MechCoder/5557d5837e72bb0b73cf to your computer and use it in GitHub Desktop.
Example code for the HuberEstimator
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