Error passing my data to SVR and SVC

0

I have a problem with my code: I want to use Sklearn's SVR method but mark an error saying that 'SVR' is not a callable object when I use the SVR() function.

import numpy as np
from sklearn.svm import SVR

This is how I use the function SVR and the parameters I give it:

svr_lin = SVR(kernel='linear', C=1e3)
svr_poli = SVR(kernel='poly', C=1e3, degree = 2)
svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)

This is how the error marks me:

<ipython-input-1-6f926795cb9b> in prediccion(fechas, precios, x)

    24     svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)
    25 
    26     svr_lin(fechas, precios) <----
    27     svr_poli(fechas, precios)
    28     svr_rbf(fechas, precios)

TypeError: 'SVR' object is not callable

The same thing also happens if I want to use SVC instead of SVR. I do not know what is due and I hope someone can help me.

    
asked by Tonatiu 05.08.2018 в 06:43
source

1 answer

0

sklearn.svm.SVR (Support Vector Regression ) is not a function, it is a class, so svr_lin , svr_poly and svr_rbf are instances of sklearn.svm.SVR .

When you make svr_lin(fechas, precios) you are calling the object and trying to pass two arguments, but as the exception shows the instances of sklearn.svm.SVR are not "callable" since they do not implement the __call__ method.

I guess you're trying to train the model with fechas the training vector and precios the target values, in which case what you should use is the method fit of the instance, do not call it:

svr_lin = SVR(kernel='linear', C=1e3)
svr_poli = SVR(kernel='poly', C=1e3, degree = 2)
svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)

svr_lin.fit(fechas, precios) 
svr_poli.fit(fechas, precios)
svr_rbf.fit(fechas, precios)

The exact same thing applies to sklearn.svm.SVC

    
answered by 05.08.2018 в 12:40