【发布时间】:2019-06-07 08:29:52
【问题描述】:
我目前已经为二进制类实现了概率(至少我是这么认为的)。现在我想扩展这种回归方法,并尝试将它用于波士顿数据集。不幸的是,我的算法似乎卡住了,我当前运行的代码如下所示:
from sklearn import decomposition
from sklearn import svm
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import train_test_split
import warnings
warnings.filterwarnings("ignore")
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_boston
boston = load_boston()
X = boston.data
y = boston.target
inputs_train, inputs_test, targets_train, targets_test = train_test_split(X, y, test_size=0.33, random_state=42)
def plotting():
param_C = [0.01, 0.1]
param_grid = {'C': param_C, 'kernel': ['poly', 'rbf'], 'gamma': [0.1, 0.01]}
clf = GridSearchCV(svm.SVR(), cv = 5, param_grid= param_grid)
clf.fit(inputs_train, targets_train)
clf = SVR(C=clf.best_params_['C'], cache_size=200, class_weight=None, coef0=0.0,
decision_function_shape='ovr', degree=5, gamma=clf.best_params_['gamma'],
kernel=clf.best_params_['kernel'],
max_iter=-1, probability=True, random_state=None, shrinking=True,
tol=0.001, verbose=False)
clf.fit(inputs_train, targets_train)
a = clf.predict(inputs_test[0])
print(a)
plotting()
有人能告诉我,这种方法有什么问题吗,这不是我收到一些错误消息的事实(我知道,我已经在上面阻止了它们),但代码永远不会停止运行。非常感谢任何建议。
【问题讨论】:
-
您已将
max_iter参数设置为-1,因此只有在达到容差tol=0.001时才会停止训练。大概没有达到这个容忍度。尝试将max_iter设置为非负整数。 -
我刚刚尝试更改 tol = 1 和 max_iter = 15,但遗憾的是没有更改,您看到的还有什么奇怪的吗?
标签: python machine-learning scikit-learn svm