Created
June 19, 2017 01:17
-
-
Save robert8138/574905fc63f2d9c247d0ee9721b537cf to your computer and use it in GitHub Desktop.
ML Automator Example
This file contains hidden or 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
def fit(X_train, y_train): | |
import multiprocessing | |
from ml_helpers.sklearn_extensions import DenseMatrixConverter | |
from ml_helpers.data import split_records | |
from xgboost import XGBRegressor | |
global model | |
model = {} | |
n_subset = N_EXAMPLES | |
X_subset = {k: v[:n_subset] for k, v in X_train.iteritems()} | |
model['transformations'] = ExtendedPipeline([ | |
('features', features), | |
('densify', DenseMatrixConverter()), | |
]).fit(X_subset) | |
# apply transforms in parallel | |
Xt = model['transformations'].transform_parallel(X_train) | |
# fit the model in parallel | |
model['regressor'] = XGBRegressor().fit(Xt, y_train) | |
def transform(X): | |
# return dictionary | |
global model | |
Xt = model['transformations'].transform(X) | |
return {'score': model['regressor'].predict(Xt)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment