<jupyter_start><jupyter_text>KNN Model<jupyter_code>from sklearn.neighbors import KNeighborsClassifier

knn= KNeighborsClassifier(n_neighbors = 7)
knn.fit(x_train,y_train)

y_pred= knn.predict(x_test)
from sklearn.metrics import accuracy_score

#accuracy score
print(accuracy_score(y_test, y_pred))
from sklearn.model_selection import cross_val_predict
from sklearn.metrics import confusion_matrix

#confusion matrix
predictions = cross_val_predict(knn, x_train, y_train, cv=3)
confusion_matrix(y_train, predictions)
from sklearn.metrics import log_loss

#logarthmic loss
log_loss(y_test, y_pred, eps=1e-15)
from sklearn.metrics import f1_score

#f1 score
f1_score(y_train, predictions)
from sklearn.metrics import roc_auc_score

#area under curve
probs = knn.predict_proba(x_test)
probs = probs[:, 1]
auc = roc_auc_score(y_test, probs)
print(auc)
from sklearn.metrics import classification_report
y_true, y_pred = y_test, knn.predict(x_test)
print(classification_report(y_true, y_pred))

# import warnings filter
from warnings import simplefilter
# ignore all future warnings
simplefilter(action='ignore', category=FutureWarning)<jupyter_output><empty_output><jupyter_text>Logistic Regression<jupyter_code>from sklearn.linear_model import LogisticRegression

logreg = LogisticRegression()
logreg.fit(x_train, y_train)

y_pred = logreg.predict(x_test)
#accuracy score
print(accuracy_score(y_test, y_pred))
#confusion matrix
predictions = cross_val_predict(logreg, x_train, y_train, cv=3)
confusion_matrix(y_train, predictions)
#logarthmic loss
log_loss(y_test, y_pred, eps=1e-15)
#f1 score
f1_score(y_train, predictions)
#area under curve
probs = logreg.predict_proba(x_test)
probs = probs[:, 1]
auc = roc_auc_score(y_test, probs)
print(auc)<jupyter_output>0.5013951078296506<jupyter_text>Decision Tree<jupyter_code>from sklearn.tree import DecisionTreeClassifier
classifier = DecisionTreeClassifier(max_leaf_nodes=10)
classifier.fit(x_train,y_train)
y_pred = classifier.predict(x_test)
#accuracy score
print(accuracy_score(y_test, y_pred))
#confusion matrix
predictions = cross_val_predict(classifier, x_train, y_train, cv=3)
confusion_matrix(y_train, predictions)
#logarthmic loss
log_loss(y_test, y_pred, eps=1e-15)
#f1 score
f1_score(y_train, predictions)
#area under curve
probs = classifier.predict_proba(x_test)
probs = probs[:, 1]
auc = roc_auc_score(y_test, probs)
print(auc)<jupyter_output>0.5012345800649644<jupyter_text>Random Forest<jupyter_code>from sklearn.ensemble import RandomForestClassifier
rnd_clf = RandomForestClassifier(max_leaf_nodes=18, n_estimators=16, random_state=0)
rnd_clf.fit(x_train, y_train)
y_pred = rnd_clf.predict(x_test)
#accuracy score
print(accuracy_score(y_test, y_pred))
#confusion matrix
predictions = cross_val_predict(rnd_clf, x_train, y_train, cv=3)
confusion_matrix(y_train, predictions)
#logarthmic loss
log_loss(y_test, y_pred, eps=1e-15)
#f1 score
f1_score(y_train, predictions)
#area under curve
probs = rnd_clf.predict_proba(x_test)
probs = probs[:, 1]
auc = roc_auc_score(y_test, probs)
print(auc)<jupyter_output>0.5014104406068841<jupyter_text>SVM<jupyter_code>from sklearn.svm import SVC

svm= SVC()
svm.fit(x_train, y_train)
y_pred = svm.predict(x_test)
#accuracy score
print(accuracy_score(y_test, y_pred))
#confusion matrix
predictions = cross_val_predict(svm, x_train, y_train, cv=3)
confusion_matrix(y_train, predictions)
#logarthmic loss
log_loss(y_test, y_pred, eps=1e-15)
#f1 score
f1_score(y_train, predictions)<jupyter_output><empty_output><jupyter_text>Naive bayes<jupyter_code>from sklearn.naive_bayes import GaussianNB

gaussian = GaussianNB() 
gaussian.fit(x_train, y_train)  
y_pred = gaussian.predict(x_test)  
acc_gaussian = round(gaussian.score(x_train, y_train) * 100, 2)
#accuracy score
print(accuracy_score(y_test, y_pred))
#confusion matrix
predictions = cross_val_predict(gaussian, x_train, y_train, cv=3)
confusion_matrix(y_train, predictions)
#f1 score
f1_score(y_train, predictions)
#area under curve
probs = gaussian.predict_proba(x_test)
probs = probs[:, 1]
auc = roc_auc_score(y_test, probs)
print(auc)
#logarthmic loss
log_loss(y_test, y_pred, eps=1e-15)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09834492684096906, 'fraction_numerical': 0.025185895898296954, 'mean_word_length': 9.451127819548873, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '633820', 'license': 'MIT', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1633, 'n_words': 305, 'path': 'Code_safe-driving.ipynb', 'repo_name': 'aman-thind/Safe_Driving', 'size': '4169'}