GridSearch over MultiOutputRegressor?

前端 未结 3 1777
小鲜肉
小鲜肉 2021-02-01 06:31

Let\'s consider a multivariate regression problem (2 response variables: Latitude and Longitude). Currently, a few machine learning model implementations like Support Vector Reg

3条回答
  •  后悔当初
    2021-02-01 06:52

    I just found a working solution. In the case of nested estimators, the parameters of the inner estimator can be accessed by estimator__.

    from sklearn.multioutput import MultiOutputRegressor
    from sklearn.svm import SVR
    from sklearn.model_selection import GridSearchCV
    from sklearn.pipeline import Pipeline
    
    pipe_svr = Pipeline([('scl', StandardScaler()),
            ('reg', MultiOutputRegressor(SVR()))])
    
    grid_param_svr = {
        'reg__estimator__C': [0.1,1,10]
    }
    
    gs_svr = (GridSearchCV(estimator=pipe_svr, 
                          param_grid=grid_param_svr, 
                          cv=2,
                          scoring = 'neg_mean_squared_error',
                          n_jobs = -1))
    
    gs_svr = gs_svr.fit(X_train,y_train)
    gs_svr.best_estimator_    
    
    Pipeline(steps=[('scl', StandardScaler(copy=True, with_mean=True, with_std=True)), 
    ('reg', MultiOutputRegressor(estimator=SVR(C=10, cache_size=200,
     coef0=0.0, degree=3, epsilon=0.1, gamma='auto', kernel='rbf', max_iter=-1,    
     shrinking=True, tol=0.001, verbose=False), n_jobs=1))])
    

提交回复
热议问题