Created
November 30, 2019 04:05
-
-
Save Mehdi-Amine/262290248e5be5d796fffe0dbb0f96f1 to your computer and use it in GitHub Desktop.
generating three models, training them on the make_moons dataset, then evaluating their accuracy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Creating three models with three different algorithms | |
from sklearn.tree import DecisionTreeClassifier | |
from sklearn.linear_model import LogisticRegression | |
from sklearn.svm import SVC | |
tree_clf = DecisionTreeClassifier(random_state=42) | |
log_clf = LogisticRegression(solver="lbfgs", random_state=42) | |
svm_clf = SVC(gamma="scale", random_state=42) | |
# Training, predicting, then evaluating the predictions | |
# of all three models | |
from sklearn.metrics import accuracy_score | |
for clf in (tree_clf, log_clf, svm_clf): | |
clf.fit(X_train, y_train) # training | |
y_pred = clf.predict(X_test) # predicting | |
print(clf.__class__.__name__, accuracy_score(y_test, y_pred)) # evaluating | |
# Output of the evaluation: | |
# DecisionTreeClassifier 0.856 | |
# LogisticRegression 0.864 | |
# SVC 0.896 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment