classifier of chains

from skmultilearn.problem_transform import ClassifierChain
from sklearn.naive_bayes import GaussianNB
#scikit-learn version>=0.21
from sklearn.metrics import multilabel_confusion_matrix
from scipy.sparse import csr_matrix
def svm():
  
  clf = ClassifierChain(GaussianNB())
  S = csr_matrix(train_labels)
  #S为sprase matrix
  clf.fit(train_features, S)
  
  prediction = clf.predict(csr_matrix(test_features))
  
  cnf_matrix = multilabel_confusion_matrix(y_true, y_prediction)
# print(cnf_matrix)

  TN = cnf_matrix[:, 0, 0]
  TP = cnf_matrix[:, 1, 1]
  FN = cnf_matrix[:, 1, 0]
  FP = cnf_matrix[:, 0, 1]
  
  ACC = accuracy_score(y_true, y_prediction)
  TPR = metrics.recall_score(y_true, y_prediction, average='macro')
  TNR = np.mean(TN / (TN + FP))
  F1_score = metrics.f1_score(y_true, y_prediction, average='macro')
 
posted @ 2019-09-19 16:32  夕颜mu  阅读(434)  评论(0编辑  收藏  举报