【问题标题】:predict is not giving the highest probabilitypredict 没有给出最高的概率
【发布时间】:2018-04-21 01:46:42
【问题描述】:

我正在使用来自 sklearn (Python 3) 的 SVM。预测的类概率小于所有类中的最高概率。谁能解释一下。

    clf = Pipeline([('vect', TfidfVectorizer()), ('clf', svm.SVC())])
    parameters = {'vect__ngram_range': [(1, 2)], 'vect__stop_words': ['english'],
                  'vect__lowercase': [True], 'clf__C': [1,2, 5, 10, 20, 100],
                  'clf__kernel': [str('linear')], 'clf__class_weight':['balanced'],
                  'clf__probability': [True]}
    vec_clf = GridSearchCV(clf, parameters, scoring='f1_weighted')
    vec_clf.fit(x_train, y_train)

打印报表。

    pred_data = model.predict(input_series)
    probability_lst = model.predict_proba(input_series)[0]
    print ("probability lst: ", probability_lst)
    print ("predicted data: ", pred_data)
    print ("classes: ", model.best_estimator_.classes_)

这是我正在使用的代码。请找到下面的打印输出。

    probability lst:  [ 0.29004279  0.38866277  0.04441053  0.1173824   0.0300703   0.0983329   0.03109831]
    predicted data:  ['1']
    classes:  ['1' '2' '3' '4' '5' '6' '7']

从逻辑上讲,它应该预测类“2”,因为它具有最高的概率。请解释这个输出

【问题讨论】:

  • 你为什么访问model.predict_proba(input_series)[0],强调[0]
  • 这是一个列表,所以我拿了[0]
  • @VivekKumar 正如你分享的另一个链接中提到的,我也尝试了决策功能。但无法理解输出。这是输出。
  • 癸乐趣:[[4.24585270e-02 4.96189478e-01 2.49730266e-01 5.74115210e-01 2.91674509e-01 5.43911786e-01 6.57224118e-01 2.65190816e-01 7.28700141e-01 3.96157293 E-01 1.10457723e + 00 -2.27747710e-01 1.64406656e-01 -2.79911772e-01 8.23904997e-02 3.42637709e-01 -9.38947411e-05 3.42586750e-01 -4.11551164e-01 -8.49533033e-02 3.48155592e -01]]

标签: python machine-learning scikit-learn svm


【解决方案1】:

我已经阅读了一些关于 predict 的文档,我认为它的工作方式与 predict_proba 不同步。

所以使用 predic_proba 并取最高概率及其对应的类(来自 model.classes_)

我们可以关闭这张票。

【讨论】:

    猜你喜欢
    • 2021-08-27
    • 2015-06-18
    • 1970-01-01
    • 2011-05-24
    • 2023-03-18
    • 1970-01-01
    • 2021-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多