關於SVMs的文檔意味着存在一個名爲'classes_'的屬性,它有望揭示模型如何在內部表示類。識別sklearn模型的類
我想獲得這些信息,以便解釋像'predict_proba'這樣的函數的輸出,該函數可以爲多個樣本生成類的概率。希望知道(完全隨機選擇的值,只是爲了舉例說明)
model.classes_
>> [1, 2, 4]
手段,我可以假設
model.predict_proba([[1.2312, 0.23512, 6.], [3.7655, 8.2353, 0.86323]])
>> [[0.032, 0.143, 0.825], [0.325, 0.143, 0.532]]
裝置,該概率轉換爲相同的數量級的類,即對於第一組特徵:
probability of class 1: 0.032
probability of class 2: 0.143
probability of class 4: 0.825
但是在SVM上調用'classes_'會導致錯誤。有沒有一種好的方法來獲取這些信息?我無法想象在訓練完模型後無法再訪問它。
編輯: 我建立我的模型是多還是少這樣的方式:
from sklearn.svm import SVC
from sklearn.grid_search import GridSearchCV
from sklearn.pipeline import Pipeline, FeatureUnion
pipeline = Pipeline([
('features', FeatureUnion(transformer_list[ ... ])),
('svm', SVC(probability=True))
])
parameters = { ... }
grid_search = GridSearchCV(
pipeline,
parameters
)
grid_search.fit(get_data(), get_labels())
clf = [elem for elem in grid_search.estimator.steps if elem[0] == 'svm'][0][1]
print(clf)
>> SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, degree=3, gamma=0.0,
kernel='rbf', max_iter=-1, probability=True, random_state=None,
shrinking=True, tol=0.001, verbose=False)
print(clf.classes_)
>> Traceback (most recent call last):
File "path/to/script.py", line 284, in <module>
File "path/to/script.py", line 181, in re_train
print(clf.classes_)
AttributeError: 'SVC' object has no attribute 'classes_'
謝謝,它現在可以工作=) – Arne