<jupyter_start><jupyter_text>Logistic Regression<jupyter_code>from sklearn.linear_model import LogisticRegression
LogReg_clf = LogisticRegression(solver='liblinear',random_state = 0)
LogReg_clf.fit(x_train, y_train)
train_score=LogReg_clf.score(x_train,y_train)
train_score
test_score=LogReg_clf.score(x_test,y_test)
test_score
y_pred = LogReg_clf.predict(x_test)
y_pred
from sklearn.metrics import confusion_matrix, accuracy_score
acc =  accuracy_score(y_test, y_pred)
cm = confusion_matrix(y_test, y_pred)
print(acc)
print(cm)
from sklearn.metrics import classification_report
print(classification_report(y_test, y_pred))
# calculate roc curves
from sklearn.metrics import roc_curve
from sklearn.metrics import roc_auc_score
ns_fpr, ns_tpr, _ = roc_curve(y_test, y_pred)
lr_fpr, lr_tpr, _ = roc_curve(y_test, y_pred)
# plot the roc curve for the model
plt.plot(ns_fpr, ns_tpr, linestyle='--', label='0')
plt.plot(lr_fpr, lr_tpr, marker='.', label='1')
# axis labels
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
# show the legend
plt.legend()
# show the plot
plt.show()
# calculate precision and recall for each threshold
from sklearn.metrics import precision_recall_curve
from sklearn.metrics import f1_score
from sklearn.metrics import auc
lr_precision, lr_recall, _ = precision_recall_curve(y_test, y_pred)
# calculate scores
lr_f1, lr_auc = f1_score(y_test,y_pred), auc(lr_recall, lr_precision)
# summarize scores
print('Logistic: f1=%.3f auc=%.3f' % (lr_f1, lr_auc))
# plot the precision-recall curves
no_skill = len(y_test[y_test==1]) / len(y_test)
plt.plot([0, 1], [no_skill, no_skill], linestyle='--', label='0')
plt.plot(lr_recall, lr_precision, marker='.', label='1')
# axis labels
plt.xlabel('Recall')
plt.ylabel('Precision')
# show the legend
plt.legend()
# show the plot
plt.show()<jupyter_output>Logistic: f1=0.588 auc=0.657<jupyter_text>Navie Bayes Algorithm<jupyter_code># splitting X and y into training and testing sets 
from sklearn.model_selection import train_test_split 
X_train, X_test, y_train, y_test = train_test_split(image_dataset.data,image_dataset.target, random_state=1) 
# training the model on training set 
from sklearn.naive_bayes import GaussianNB 
gnb = GaussianNB() 
gnb.fit(X_train, y_train) 
train_score=gnb.score(X_train,y_train)
train_score
test_score=gnb.score(X_test,y_test)
test_score
# making predictions on the testing set 
y_pred_gnb= gnb.predict(X_test) 
  
y_pred_gnb
# comparing actual response values (y_test) with predicted response values (y_pred) 
from sklearn import metrics 
print("Gaussian Naive Bayes model accuracy(in %):", metrics.accuracy_score(y_test, y_pred_gnb)*100)
from sklearn.metrics import classification_report
print(classification_report(y_test, y_pred_gnb))
from sklearn.metrics import confusion_matrix, accuracy_score
acc =  accuracy_score(y_test, y_pred_gnb)
cm = confusion_matrix(y_test, y_pred_gnb)
print(acc)
print(cm)
# calculate roc curves
from sklearn.metrics import roc_curve
from sklearn.metrics import roc_auc_score
ns_fpr, ns_tpr, _ = roc_curve(y_test, y_pred_gnb)
lr_fpr, lr_tpr, _ = roc_curve(y_test, y_pred_gnb)
# plot the roc curve for the model
plt.plot(ns_fpr, ns_tpr, linestyle='--', label='cat')
plt.plot(lr_fpr, lr_tpr, marker='.', label='dog')
# axis labels
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
# show the legend
plt.legend()
# show the plot
plt.show()
# calculate precision and recall for each threshold
from sklearn.metrics import precision_recall_curve
from sklearn.metrics import f1_score
from sklearn.metrics import auc
lr_precision, lr_recall, _ = precision_recall_curve(y_test, y_pred_gnb)
# calculate scores
lr_f1, lr_auc = f1_score(y_test,y_pred_gnb), auc(lr_recall, lr_precision)
# summarize scores
print('Logistic: f1=%.3f auc=%.3f' % (lr_f1, lr_auc))
# plot the precision-recall curves
no_skill = len(y_test[y_test==1]) / len(y_test)
plt.plot([0, 1], [no_skill, no_skill], linestyle='--', label='cat')
plt.plot(lr_recall, lr_precision, marker='.', label='dog')
# axis labels
plt.xlabel('Recall')
plt.ylabel('Precision')
# show the legend
plt.legend()
# show the plot
plt.show()<jupyter_output>Logistic: f1=0.250 auc=0.379<jupyter_text>KNN Algorithm<jupyter_code>X_train, X_test, y_train, y_test = train_test_split(image_dataset.data,image_dataset.target,random_state=5)
from sklearn.neighbors import KNeighborsClassifier
classifier_knn = KNeighborsClassifier(n_neighbors = 8)
classifier_knn.fit(X_train, y_train)
train_score=classifier_knn.score(X_train,y_train)
train_score
test_score=classifier_knn.score(X_test,y_test)
test_score
y_pred_knn = classifier.predict(X_test)
y_pred_knn
from sklearn.metrics import confusion_matrix, accuracy_score
acc =  accuracy_score(y_test, y_pred_knn)
cm = confusion_matrix(y_test, y_pred_knn)
print(acc)
print(cm)
from sklearn.metrics import classification_report
print(classification_report(y_test, y_pred_knn))
# calculate roc curves
from sklearn.metrics import roc_curve
from sklearn.metrics import roc_auc_score
ns_fpr, ns_tpr, _ = roc_curve(y_test, y_pred_knn)
lr_fpr, lr_tpr, _ = roc_curve(y_test, y_pred_knn)
# plot the roc curve for the model
plt.plot(ns_fpr, ns_tpr, linestyle='--', label='cat')
plt.plot(lr_fpr, lr_tpr, marker='.', label='dog')
# axis labels
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
# show the legend
plt.legend()
# show the plot
plt.show()
# calculate precision and recall for each threshold
from sklearn.metrics import precision_recall_curve
from sklearn.metrics import f1_score
from sklearn.metrics import auc
lr_precision, lr_recall, _ = precision_recall_curve(y_test, y_pred_knn)
# calculate scores
lr_f1, lr_auc = f1_score(y_test,y_pred_knn), auc(lr_recall, lr_precision)
# summarize scores
print('Logistic: f1=%.3f auc=%.3f' % (lr_f1, lr_auc))
# plot the precision-recall curves
no_skill = len(y_test[y_test==1]) / len(y_test)
plt.plot([0, 1], [no_skill, no_skill], linestyle='--', label='cat')
plt.plot(lr_recall, lr_precision, marker='.', label='dog')
# axis labels
plt.xlabel('Recall')
plt.ylabel('Precision')
# show the legend
plt.legend()
# show the plot
plt.show()<jupyter_output>Logistic: f1=0.000 auc=0.150
{'fraction_non_alphanumeric': 0.11312803889789302, 'fraction_numerical': 0.011021069692058346, 'mean_word_length': 7.407356948228883, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '578020', 'license': 'MIT', 'n_tokens_mistral': 2440, 'n_tokens_neox': 2336, 'n_words': 518, 'path': 'ComputerVision/Cat_Dog_Classifications.ipynb', 'repo_name': 'KarinkiManikanta/Linear-Regression', 'size': '6170'}