Read the Dataset
import pandas as pd
df=pd.read_csv(path)
print(df.shape)
Convert categorical to numerical:
from sklearn.preprocessing import LabelEncoder
df[[columns]]=df[columns]].apply(LabelEncoder().fit_transform)
X and Y
X=df.iloc[:,:-1]
Y=df.iloc[:,-1]
from sklearn.model_selection import train_test_split
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
from sklearn.linear_model import LogisticRegression
models['Logistic Regression'] = LogisticRegression()
#similary create other models
from sklearn.metrics import accuracy_score, precision_score, recall_score
accuracy, precision, recall = {}, {}, {}
for key in models.keys():
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])
plt.plot(false_positive_rate, true_positive_rate)
plt.xlabel('FPR')
plt.ylabel('TPR')
plt.title('ROC curve')
plt.show()
sns.heatmap(confusion_matrix(Y_val,predictions),fmt='',annot=True) What is a binary classifier in machine learning?
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.
Информация по комментариям в разработке