Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridSearch over MultiOutputRegressor?

Tags:

Let's consider a multivariate regression problem (2 response variables: Latitude and Longitude). Currently, a few machine learning model implementations like Support Vector Regression sklearn.svm.SVR do not currently provide naive support of multivariate regression. For this reason, sklearn.multioutput.MultiOutputRegressor can be used.

Example:

from sklearn.multioutput import MultiOutputRegressor svr_multi = MultiOutputRegressor(SVR(),n_jobs=-1)  #Fit the algorithm on the data svr_multi.fit(X_train, y_train) y_pred= svr_multi.predict(X_test) 

My goal is to tune the parameters of SVR by sklearn.model_selection.GridSearchCV. Ideally, if the response was a single variable and not multiple, I would perform an operation as follows:

from sklearn.svm import SVR from sklearn.model_selection import GridSearchCV from sklearn.pipeline import Pipeline  pipe_svr = (Pipeline([('scl', StandardScaler()),                   ('reg', SVR())]))  grid_param_svr = {     'reg__C': [0.01,0.1,1,10],     'reg__epsilon': [0.1,0.2,0.3],     'degree': [2,3,4] }  gs_svr = (GridSearchCV(estimator=pipe_svr,                    param_grid=grid_param_svr,                    cv=10,                   scoring = 'neg_mean_squared_error',                   n_jobs = -1))  gs_svr = gs_svr.fit(X_train,y_train) 

However, as my response y_train is 2-dimensional, I need to use the MultiOutputRegressor on top of SVR. How can I modify the above code to enable this GridSearchCV operation? If not possible, is there a better alternative?

like image 409
S. Naribole Avatar asked Apr 21 '17 02:04

S. Naribole


People also ask

What is MultiOutputRegressor?

MultiOutputRegressor (estimator, n_jobs=1)[source] Multi target regression. This strategy consists of fitting one regressor per target. This is a simple strategy for extending regressors that do not natively support multi-target regression.

Can we use GridSearchCV for regression?

Let's take example of common machine learning algorithms starting with regression models: There are two different approaches which you can take, use gridsearchcv to perform hyperparameter tuning on one model or multiple models.

What does grid search CV do?

GridSearchCV is a technique to search through the best parameter values from the given set of the grid of parameters. It is basically a cross-validation method. the model and the parameters are required to be fed in. Best parameter values are extracted and then the predictions are made.


1 Answers

For use without pipeline, put estimator__ before parameters:

param_grid = {'estimator__min_samples_split':[10, 50],               'estimator__min_samples_leaf':[50, 150]}  gb = GradientBoostingRegressor() gs = GridSearchCV(MultiOutputRegressor(gb), param_grid=param_grid)  gs.fit(X,y) 
like image 86
Marco Antonio Yamada Avatar answered Oct 13 '22 18:10

Marco Antonio Yamada