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?
JavaScript
x
30
30
1
from sklearn.svm import SVR
2
from sklearn.model_selection import GridSearchCV
3
from sklearn.multioutput import MultiOutputRegressor
4
5
svr = SVR()
6
svr_regr = MultiOutputRegressor(svr)
7
8
from sklearn.model_selection import KFold
9
kfold_splitter = KFold(n_splits=6, random_state = 0,shuffle=True)
10
11
12
svr_gs = GridSearchCV(svr_regr,
13
param_grid = {'estimator__kernel': ('linear','poly','rbf','sigmoid'),
14
'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],
15
'estimator__degree': [3,8],
16
'estimator__coef0': [0.01,0.1,0.5],
17
'estimator__gamma': ('auto','scale'),
18
'estimator__tol': [1e-3, 1e-4, 1e-5, 1e-6]},
19
cv=kfold_splitter,
20
n_jobs=-1,
21
scoring='r2')
22
23
24
25
svr_gs.fit(X_train, y_train)
26
27
28
print(svr_gs.best_params_)
29
#print(gs.best_score_)
30
Output:
JavaScript
1
2
1
{'estimator__C': 10, 'estimator__coef0': 0.01, 'estimator__degree': 3, 'estimator__gamma': 'auto', 'estimator__kernel': 'rbf', 'estimator__tol': 1e-06}
2
Trying to create a model using the output:
JavaScript
1
7
1
SVR_model = svr_regr (kernel='rbf',C=10,
2
coef0=0.01,degree=3,
3
gamma='auto',tol=1e-6,random_state=42)
4
SVR_model.fit(X_train, y_train)
5
SVR_model_y_predict = SVR_model.predict((X_test))
6
SVR_model_y_predict
7
Error:
JavaScript
1
11
11
1
---------------------------------------------------------------------------
2
TypeError Traceback (most recent call last)
3
/var/folders/mm/r4gnnwl948zclfyx12w803040000gn/T/ipykernel_96269/769104914.py in <module>
4
----> 1 SVR_model = svr_regr (estimator__kernel='rbf',estimator__C=10,
5
2 estimator__coef0=0.01,estimator__degree=3,
6
3 estimator__gamma='auto',estimator__tol=1e-6,random_state=42)
7
4
8
5
9
10
TypeError: 'MultiOutputRegressor' object is not callable
11
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.