SVR 对象不可调用

SVR object is not callable

我想使用 sklearn SVR 方法,但是当我编写 SVR() 函数时它会抛出错误。它说 SVR is not a callable.

我是这样称呼它的

from sklearn.svm import SVR

这是我得到错误的代码

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)

这是我得到的错误:

error 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

我也尝试过其他方法,如 SVC,但出现了同样的错误。

提前致谢。

你必须使用 fit() 方法

svr_lin.fit(fechas, precios)

更多信息here

您需要在 SVR 对象上调用函数 fit(),例如:

svr_lin.fit(fechas, precios)

阅读更多here