<jupyter_start><jupyter_text>Data Pre-processing<jupyter_code>from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
print("X_train:\n", X_train)
print("\n")
print("X_test:\n", X_test)<jupyter_output>X_train:
 [[-0.13807361  0.74073163  0.08960794  0.20786696]
 [-0.63177254 -0.28028795 -0.11301437  1.30501681]
 [ 1.35320992 -1.14850598  0.47129287  0.27628242]
 ...
 [ 1.2155146  -0.81135505  0.18893193  0.69849633]
 [-0.70405647 -0.12961769 -0.48659588  0.151778  ]
 [-0.08470315  0.01679686 -1.08020277  0.25717776]]


X_test:
 [[-0.97191171  1.80889306 -0.1595149  -3.06321954]
 [ 1.60404076 -0.40259703 -0.20561823  1.07879248]
 [-0.8552527  -1.46297345  1.76003372  0.59926221]
 ...
 [ 0.05985076  0.35536978 -1.41383068 -1.54323612]
 [-0.65671608 -0.63091532  0.6076353   0.81437314]
 [ 0.57465751 -1.47856404  1.63242053  0.26457557]]<jupyter_text>1. Logisctic regression<jupyter_code>from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import cross_val_score
classifier = LogisticRegression(solver='liblinear',random_state=1)
classifier.fit(X_train,y_train)
y_pred = classifier.predict(X_test)
from sklearn.metrics import classification_report,confusion_matrix
print(classification_report(y_test,y_pred))
cm = confusion_matrix(y_test,y_pred)
cm
df_cm = pd.DataFrame(cm,index=[0,1],columns=['predicted_0','predicted_1'])
sns.heatmap(df_cm,annot=True)<jupyter_output><empty_output><jupyter_text>2. Support vector mechine<jupyter_code>from sklearn.svm import SVC
svm_classifier = SVC(kernel='linear')
svm_classifier.fit(X_train,y_train)

svm_accuracies = cross_val_score(estimator=svm_classifier,X=X_train,y=y_train,cv=10)
print("Mean Accuracy:",svm_accuracies.mean())
y_pred_svc = svm_classifier.predict(X_test)
print(classification_report(y_test,y_pred_svc))
cm_svm = confusion_matrix(y_test,y_pred_svc)
df_cm_svm = pd.DataFrame(cm_svm,index=[0,1],columns=['predicted_0','predicted_1'])
sns.heatmap(df_cm_svm,annot=True)<jupyter_output><empty_output><jupyter_text>3.Random Forest Classifier<jupyter_code>from sklearn.ensemble import RandomForestClassifier
rfc_classifier = RandomForestClassifier(criterion='entropy')
rfc_classifier.fit(X_train,y_train)
rfc_accuracies = cross_val_score(estimator=rfc_classifier,X=X_train,y=y_train,cv=10)
print("Mean Accuracy:",rfc_accuracies.mean())
print("RandomTreeClassifier Train Score: ", rfc.score(X_train, y_train))
print("RandomTreeClassifier Test Score: ", rfc.score(X_test, y_test))
y_pred_rfc = rfc_classifier.predict(X_test)
print(classification_report(y_test,y_pred_svc))
cm_rfc = confusion_matrix(y_test,y_pred_rfc)
df_cm_rfc = pd.DataFrame(cm_rfc,index=[0,1],columns=['predicted_0','predicted_1'])
sns.heatmap(df_cm_rfc,annot=True)<jupyter_output><empty_output><jupyter_text>4.KNN Classifier<jupyter_code>from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import KFold, GridSearchCV
param_grid = {'leaf_size': [2,5,7,9,11],'n_neighbors':[2,5,7,9,11],'p':[1,2]}

grid = GridSearchCV(KNeighborsClassifier(),param_grid=param_grid)

grid.fit(X_train, y_train)

grid.best_params_
KNN = KNeighborsClassifier(n_neighbors=2 ,p=1 ,leaf_size=2 )
KNN.fit(X_train, y_train)
KNN_pred = KNN.predict(X_test)
knn_accuracies = cross_val_score(estimator=KNN,X=X_train,y=y_train,cv=10)
print("Mean Accuracy:",knn_accuracies.mean())
print(classification_report(y_test,KNN_pred))
cm_knn = confusion_matrix(y_test,KNN_pred)
df_cm_knn = pd.DataFrame(cm_knn,index=[0,1],columns=['predicted_0','predicted_1'])
sns.heatmap(df_cm_knn,annot=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1361027603170265, 'fraction_numerical': 0.12845039628313748, 'mean_word_length': 8.786096256684491, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '470278', 'license': 'Apache-2.0', 'n_tokens_mistral': 1810, 'n_tokens_neox': 1548, 'n_words': 176, 'path': 'Bank_Note_Authentication.ipynb', 'repo_name': 'fahad-ui/Bank_Note_Authentication', 'size': '3659'}