print('acc:', clf.score(np.array(testX), np.array(testY))) print("\n====== Random Forest ======") for c in [10, 30, 50, 70, 90, 100, 120]: clf = RandomForestClassifier(n_estimators=c) clf.fit(trainX, trainY) proY = clf.predict_proba(testX) print(">>> # tree: ", c) print('other measure: ', scoreother_measured(proY, testY)) print("acc: ", clf.score(np.array(testX), np.array(testY))) print("\n====== SVM ======") # for c in [0.8, 1.0]: # clf = SVC(C =c,probability = True) # clf.fit(trainX, trainY) # clf.probability = True # proY = clf.predict_proba(testX) # print('add other_measured acc', scoreother_measured(proY, testY)) # print('SVM acc when penalty C = ', c, clf.score(np.array(testX), np.array(testY))) print("----- kernel -----") print("----this will take more time, please be patient....") for c in ['linear', 'poly', 'rbf']: clf = SVC(kernel=c, probability=True) #, probability = True) clf.fit(trainX, trainY) clf.probability = True # proY = clf.predict_proba(testX) proY = clf.predict_proba(testX) print(">>> kernel:", c) print('other measure: ', scoreother_measured(proY, testY)) print('acc:', clf.score(np.array(testX), np.array(testY)))
ax.set_xticklabels(data.columns) ax.set_yticklabels(data.columns) fig.savefig('correlation.png') #fig.show() # Plot ROC Curve plt.clf() plt.figure(figsize=(8, 6)) d_tree.probability = True probas = d_tree.predict_proba(X_test_d) fpr, tpr, thresholds = met.roc_curve(y_test_d, probas[:, 1]) roc_auc = met.auc(fpr, tpr) plt.plot(fpr, tpr, label='%s ROC (area = %0.2f)' % ('Decision Tree', roc_auc)) naivebayes.probability = True probas = naivebayes.predict_proba(X_test_n) fpr, tpr, thresholds = met.roc_curve(y_test_n, probas[:, 1]) roc_auc = met.auc(fpr, tpr) plt.plot(fpr, tpr, label='%s ROC (area = %0.2f)' % ('Naive Bayes', roc_auc)) probas = rbf_kernel_clf.predict_proba(X_test_s) fpr, tpr, thresholds = met.roc_curve(y_test_s, probas[:, 1]) roc_auc = met.auc(fpr, tpr) plt.plot(fpr, tpr, label='%s ROC (area = %0.2f)' % ('SVM', roc_auc)) mlp.probability = True probas = mlp.predict_proba(X_test_a) fpr, tpr, thresholds = met.roc_curve(y_test_a, probas[:, 1]) roc_auc = met.auc(fpr, tpr) plt.plot(fpr, tpr, label='%s ROC (area = %0.2f)' % ('Neural Network', roc_auc))