为什么SVC在输出

时间:2018-06-17 14:08:18

标签: python-3.x machine-learning scikit-learn classification svm

我的目标是使用支持向量机对CNN中提取的特征进行分类。

提取的要素有一个形状(2186,128),这是一个保存在X_tr中的np数组。

Y的形状(2186,)是一个数组([0,0,0,...,0,0,0])

将这些应用于SVC。

输入:

from sklearn.svm import SVC
clf = SVC()
clf.fit(X_train, y)
SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
    decision_function_shape='ovr', degree=3, gamma='auto', kernel='rbf',
    max_iter=-1, probability=False, random_state=None, shrinking=True,
    tol=0.001, verbose=False)

输出:

SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
  decision_function_shape='ovr', degree=3, gamma='auto', kernel='rbf',
  max_iter=-1, probability=False, random_state=None, shrinking=True,
  tol=0.001, verbose=False)

为什么它将参数作为输出而不是分类?

2 个答案:

答案 0 :(得分:0)

你期待看到什么?您已经在训练数据上训练了分类器,现在您需要在测试数据上评估分类器。在scikit-learn中,您可以使用以下方法训练分类器:

clf.fit(X_train, y_train)

并使用以下内容对受过训练的分类器进行预测:

predictions = clf.predict(X_test)

答案 1 :(得分:0)

from sklearn.svm import SVC
clf = SVC()
clf.fit(X_train, y)
SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
    decision_function_shape='ovr', degree=3, gamma='auto', kernel='rbf',
    max_iter=-1, probability=False, random_state=None, shrinking=True,
    tol=0.001, verbose=False)

不会给出任何输出。 如果您想测试分类和预测,请使用

from sklearn.svm import SVC
clf = SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
            decision_function_shape='ovr', degree=3, gamma='auto', kernel='rbf',
                max_iter=-1, probability=False, random_state=None, shrinking=True,
                    tol=0.001, verbose=False)
clf.fit(X_train, y)
pred = clf.predict(X_test)
print pred
SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
               decision_function_shape='ovr', degree=3, gamma='auto', kernel='rbf',
               max_iter=-1, probability=False, random_state=None, shrinking=True,
               tol=0.001, verbose=False)

在SVC C中,cache_size,class_weight等这些是SVC采用的参数。您可以使用这些参数进行调整,就像您想要使用线性'或者' rbf'内核用' C:1000'。 有关详情,请查看:http://scikit-learn.org/stable/modules/svm.html

相关问题