2017-02-27 7 views
0

텍스트 분류 및 지침 here에 scikit-learn SVM을 사용하고 있습니다.scikit-learn/svm - 'predict_proba'뒤에 확률 및 관련 레이블을 가져옵니다.

TypeError: only integer arrays with one element can be converted to an index

: 그러나 나는이 예외가 올바른 라벨, 동료를 확률을 가져 오도록 predict_proba 방법을 사용하여 위의 코드를 실행에 상위 3

vectorizer = HashingVectorizer() 
clf = svm.SVC(probability=True,class_weight='balanced') 

test_data = [...] 

test_vectors = vectorizer.transform(test_data) 
predicted = clf.predict_proba(test_vectors) 
for doc, pred in zip(test_labels, predicted): 
    print('%r => %s' % (doc, test_labels[pred])) 

를 가져 오는 방법에 관한 혼란 스러워요

이것은 test_labels이 확률의 배열이기 때문에 이해할 수 있지만 관련 레이블과 확률을 가져 오는 방법을 모르겠습니다.

+0

전체 오류 스택 추적을 게시하십시오. 어느 라인에서 오류가 발생합니까? 또한 데이터 샘플을 보여줍니다. –

답변

0

이것은 결국 내가 끝내고 나에게 도움이되었습니다. 희망이 누군가에게 도움이 될 것입니다 :

clf = cPickle.load(...) 
    test_data, test_labels = load_testfiles(_testpath) 

    for td in zip(test_data,test_labels): 
     X = vectorizer.transform([td[0]]) 
     label = td[1] 
     res = clf.predict_proba(X)[0] 
     # sd = np.std(res) 
     # max = np.amax(res) 
     # min = np.amin(res) 
     # mean = np.mean(res) 
     # median = np.median(res) 
     print("test--->actual=",label,"pred=",res)