filmov
tv
Binary Classification Models in Machine Learning

Показать описание
Read the Dataset
import pandas as pd
Convert categorical to numerical:
df[[columns]]=df[columns]].apply(LabelEncoder().fit_transform)
X and Y
X_train,X_val,Y_train,Y_val=train_test_split(X,Y,test_size=0.2,random_state=42)
To create more than one model
models = {} //dictionary
# Logistic Regression
models['Logistic Regression'] = LogisticRegression()
#similary create other models
accuracy, precision, recall = {}, {}, {}
# Fit the classifier model
models[key].fit(X_train, Y_train)
# Prediction
predictions = models[key].predict(X_val)
# Calculate Accuracy, Precision and Recall Metrics
accuracy[key] = accuracy_score(predictions, Y_val)
precision[key] = precision_score(predictions, Y_val)
recall[key] = recall_score(predictions, Y_val)
Y_predict = models[key].predict(X_val)
auc = roc_auc_score(Y_val, Y_predict)
print('Classification Report:',key)
print(classification_report(Y_val,predictions))
false_positive_rate, true_positive_rate, thresholds = roc_curve(Y_val, predictions)
print('ROC_AUC_SCORE is',roc_auc_score(Y_val, predictions))
#fpr, tpr, _ = roc_curve(y_test, predictions[:,1])
Binary Classification: In binary classification, the goal is to classify the input into one of two classes or categories. Example – On the basis of the given health conditions of a person, we have to determine whether the person has a certain disease or not.
import pandas as pd
Convert categorical to numerical:
df[[columns]]=df[columns]].apply(LabelEncoder().fit_transform)
X and Y
X_train,X_val,Y_train,Y_val=train_test_split(X,Y,test_size=0.2,random_state=42)
To create more than one model
models = {} //dictionary
# Logistic Regression
models['Logistic Regression'] = LogisticRegression()
#similary create other models
accuracy, precision, recall = {}, {}, {}
# Fit the classifier model
models[key].fit(X_train, Y_train)
# Prediction
predictions = models[key].predict(X_val)
# Calculate Accuracy, Precision and Recall Metrics
accuracy[key] = accuracy_score(predictions, Y_val)
precision[key] = precision_score(predictions, Y_val)
recall[key] = recall_score(predictions, Y_val)
Y_predict = models[key].predict(X_val)
auc = roc_auc_score(Y_val, Y_predict)
print('Classification Report:',key)
print(classification_report(Y_val,predictions))
false_positive_rate, true_positive_rate, thresholds = roc_curve(Y_val, predictions)
print('ROC_AUC_SCORE is',roc_auc_score(Y_val, predictions))
#fpr, tpr, _ = roc_curve(y_test, predictions[:,1])
Binary Classification: In binary classification, the goal is to classify the input into one of two classes or categories. Example – On the basis of the given health conditions of a person, we have to determine whether the person has a certain disease or not.
Комментарии