Created
October 25, 2020 19:30
-
-
Save HeenaR17/ded6eb075d7a5d0f3765103b2ee2aaeb to your computer and use it in GitHub Desktop.
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
from sklearn.linear_model import LogisticRegression | |
lr_classifier = LogisticRegression(random_state=0)lr_classifier.fit(X_train, y_train) | |
lr_y_pred = lr_classifier.predict(X_test) | |
from sklearn.metrics import accuracy_score, precision_score, recall_score | |
score1 = accuracy_score(y_test, lr_y_pred) | |
score2 = precision_score(y_test, lr_y_pred) | |
score3 = recall_score(y_test, lr_y_pred) | |
print("---- Scores ----") | |
print("Accuracy score is: {}%".format(round(score1*100,2))) | |
print("Precision score is: {}".format(round(score2,2))) | |
print("Recall score is: {}".format(round(score3,2))) | |
best_accuracy = 0.0 | |
c_val = 0.0 | |
for i in np.arange(0.1,1.1,0.1): | |
temp_classifier = LogisticRegression(C=i, random_state=0) | |
temp_classifier.fit(X_train, y_train) | |
temp_y_pred = temp_classifier.predict(X_test) | |
score = accuracy_score(y_test, temp_y_pred) | |
print("Accuracy score for C={} is: {}%".format(round(i,1), round(score*100,2))) | |
if score>best_accuracy: | |
best_accuracy = score | |
c_val = I | |
print('--------------------------------------------') | |
print('The best accuracy is {}% with C value as {}'.format(round(best_accuracy*100, 2), round(c_val,1))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment