samedi 16 novembre 2019

What is the best method to calculate acuuracy test for machine learning model

I want to know the correct method for calculate accuracy test

This is a code for training model then calculate acuracy for testing. I used three method for calculate accuracy:

  • 1-accuracy_score()
  • 2-model.score
  • 3-confusion_matrix

    SVMclassifier = SVC() SVMclassifier.fit(X_train, Y_train) SVMpred=SVMclassifier.predict(X_test) print('accuracy score for test:',accuracy_score(Y_test, SVMpred)*100) SVMres = model.score(X_test, Y_test) print("Accuracy res: %.3f%%" % (SVMres*100.0)) SVMconf = metrics.confusion_matrix(Y_test,SVMpred) TP = conf[1, 1] TN = conf[0, 0] FP = conf[0, 1] FN = conf[1, 0] SVMacc = (TP+TN)/(TP+TN+FP+FN) SVMspec= TN / (TN + FP) SVMsens = TP / float(FN + TP) print('confusion_matrix',SVMconf) print('accuracy ', SVMacc*100.0)

The output accuracy:

  1. accuracy_score(): 98.456

  2. model.score : 98.45

  3. confusion_matrix: 97.2

Aucun commentaire:

Enregistrer un commentaire