为什么 SVM 的所有结果在 scikit learn 中都是一样的?

Why are all of my results from SVM the same in scikit learn?

我正在尝试使用 scikit learn 计算多 class 数据集的概率。但是,出于某种原因,我对每个示例都获得了相同的概率。知道发生了什么吗?这与我的模型、我对库的使用或其他什么有关吗?感谢任何帮助!

svm_model = svm.SVC(probability=True, kernel='rbf',C=1, decision_function_shape='ovr', gamma=0.001,verbose=100)
svm_model.fit(train_X,train_y)
preds= svm_model.predict_proba(test_X)

train_X 看起来像这样

array([[2350, 5550, 2750.0, ..., 23478, 1, 3],
       [2500, 5500, 3095.5, ..., 23674, 0, 3],
       [3300, 6900, 3600.0, ..., 6529, 0, 3],
       ..., 
       [2150, 6175, 2500.0, ..., 11209, 0, 3],
       [2095, 5395, 2595.4, ..., 10070, 0, 3],
       [1650, 2850, 2000.0, ..., 25463, 1, 3]], dtype=object)

train_y 看起来像这样

0        1
1        2
10       2
100      2
1000     2
10000    2
10001    2
10002    2
10003    2
10004    2
10005    2
10006    2
10007    2
10008    1
10009    1
1001     2
10010    2

test_X 看起来像这样

array([[2190, 3937, 2200.5, ..., 24891, 1, 5],
       [2695, 7000, 2850.0, ..., 5491, 1, 4],
       [2950, 12000, 4039.5, ..., 22367, 0, 4],
       ..., 
       [2850, 5200, 3000.0, ..., 15576, 1, 1],
       [3200, 16000, 4100.0, ..., 1320, 0, 3],
       [2100, 3750, 2400.0, ..., 6022, 0, 1]], dtype=object)

我的结果看起来像

array([[ 0.07819139,  0.22727628,  0.69453233],
       [ 0.07819139,  0.22727628,  0.69453233],
       [ 0.07819139,  0.22727628,  0.69453233],
       ..., 
       [ 0.07819139,  0.22727628,  0.69453233],
       [ 0.07819139,  0.22727628,  0.69453233],
       [ 0.07819139,  0.22727628,  0.69453233]])

从预处理开始!

将数据标准化为零均值和单位方差非常重要。 scikit-learn 文档说 this:

Support Vector Machine algorithms are not scale invariant, so it is highly recommended to scale your data. For example, scale each attribute on the input vector X to [0,1] or [-1,+1], or standardize it to have mean 0 and variance 1. Note that the same scaling must be applied to the test vector to obtain meaningful results. See section Preprocessing data for more details on scaling and normalization

此后的下一步是参数调整(C、伽玛和系数)。这通常由 GridSearch 完成。 但我通常希望人们在尝试 Kernel-SVM 之前先尝试一个简单的 LinearSVM(更少的超参数,更少的计算时间,更好地概括非最佳参数选择).