Created
July 21, 2020 14:32
-
-
Save rikturr/88bd4365fd404261a34629942376a98e to your computer and use it in GitHub Desktop.
scikit grid search
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
from sklearn.pipeline import Pipeline | |
from sklearn.linear_model import ElasticNet | |
from sklearn.compose import ColumnTransformer | |
from sklearn.preprocessing import StandardScaler, OneHotEncoder | |
from sklearn.model_selection import GridSearchCV | |
pipeline = Pipeline(steps=[ | |
('preprocess', ColumnTransformer(transformers=[ | |
('num', StandardScaler(), numeric_feat), | |
('cat', OneHotEncoder(handle_unknown='ignore', sparse=False), categorical_feat), | |
])), | |
('clf', ElasticNet(normalize=False, max_iter=100)), | |
]) | |
# this is our grid | |
params = { | |
'clf__l1_ratio': np.arange(0, 1.01, 0.01), | |
'clf__alpha': [0, 0.5, 1, 2], | |
} | |
grid_search = GridSearchCV(pipeline, params, cv=3, n_jobs=-1, scoring='neg_mean_squared_error') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment