calssifcation models algortihms code example
Example 1: best algorithm for classification
for clf in classifiers: clf.fit(X_train, y_train) y_pred= clf.predict(X_test) acc = accuracy_score(y_test, y_pred) print("Accuracy of %s is %s"%(clf, acc)) cm = confusion_matrix(y_test, y_pred) print("Confusion Matrix of %s is %s"%(clf, cm)
Example 2: best algorithm for classification
Accuracy of XGBClassifier is 95.55Confusion Matrix of XGBClassifier is [[ 9 0 0] [ 0 15 1] [ 0 1 19]]Accuracy of SVC is 95.55Confusion Matrix of SVC is [[ 9 0 0] [ 0 16 0] [ 0 2 18]]Accuracy of DecisionTreeClassifier is 88.88Confusion Matrix of DecisionTreeClassifier is [[ 9 0 0] [ 0 15 1] [ 0 4 16]]Accuracy of RandomForestClassifier is 84.44Confusion Matrix of RandomForestClassifier is [[ 9 0 0] [ 0 15 1] [ 0 6 14]]