Skip to content
Advertisement

Error while doing SVR for multiple outputs

Trying to do SVR for multiple outputs. Started by hyper-parameter tuning which worked for me. Now I want to create the model using the optimum parameters but I am getting an error. How to fix this?

from sklearn.svm import SVR
from sklearn.model_selection import GridSearchCV
from sklearn.multioutput import MultiOutputRegressor

svr = SVR()
svr_regr = MultiOutputRegressor(svr)

from sklearn.model_selection import KFold
kfold_splitter = KFold(n_splits=6, random_state = 0,shuffle=True)


svr_gs = GridSearchCV(svr_regr,
                  param_grid = {'estimator__kernel': ('linear','poly','rbf','sigmoid'),
                                'estimator__C': [1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,6.5,7,7.5,8,8.5,9,9.5,10],
                                'estimator__degree': [3,8],
                                'estimator__coef0': [0.01,0.1,0.5],
                                'estimator__gamma': ('auto','scale'),
                                'estimator__tol': [1e-3, 1e-4, 1e-5, 1e-6]},
                  cv=kfold_splitter,
                  n_jobs=-1,
                  scoring='r2') 



svr_gs.fit(X_train, y_train)


print(svr_gs.best_params_)
#print(gs.best_score_)

Output:

 {'estimator__C': 10, 'estimator__coef0': 0.01, 'estimator__degree': 3, 'estimator__gamma': 'auto', 'estimator__kernel': 'rbf', 'estimator__tol': 1e-06}

Trying to create a model using the output:

SVR_model = svr_regr (kernel='rbf',C=10,
                      coef0=0.01,degree=3,
                      gamma='auto',tol=1e-6,random_state=42)
SVR_model.fit(X_train, y_train)
SVR_model_y_predict = SVR_model.predict((X_test))
SVR_model_y_predict

Error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/var/folders/mm/r4gnnwl948zclfyx12w803040000gn/T/ipykernel_96269/769104914.py in <module>
----> 1 SVR_model = svr_regr (estimator__kernel='rbf',estimator__C=10,
      2                       estimator__coef0=0.01,estimator__degree=3,
      3                       estimator__gamma='auto',estimator__tol=1e-6,random_state=42)
      4 
      5 

TypeError: 'MultiOutputRegressor' object is not callable

Advertisement

Answer

Please consult the MultiOutputRegressor docs.

The regressor you got back is the model. It is not a method, but it does offer a bunch of fun methods that you can call, such as .fit(), .predict(), and .score().

You are trying to specify kernel and a few other parameters. It appears you wanted to offer those to SVR(), at the top of your code.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement