<jupyter_start><jupyter_text>Build Classification Model<jupyter_code>import pandas as pd
cuisines_df = pd.read_csv("../data/cleaned_cuisines.csv")
cuisines_df.head()
cuisines_label_df = cuisines_df['cuisine']
cuisines_label_df.head()
cuisines_feature_df = cuisines_df.drop(['Unnamed: 0', 'cuisine'], axis=1)
cuisines_feature_df.head()
from sklearn.neighbors import KNeighborsClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier
from sklearn.model_selection import train_test_split, cross_val_score
from sklearn.metrics import accuracy_score,precision_score,confusion_matrix,classification_report, precision_recall_curve
import numpy as np

X_train, X_test, y_train, y_test = train_test_split(cuisines_feature_df, cuisines_label_df, test_size=0.3)
# SVM - support vector machines
# SVC - support vector clustering, child of above
# C - regularization, and regulates the influence of parameters
# kernel - how to cluster the labels, we set to 'linear' to make sure we get linear SVC
# set probability to true b/c we want to capture that data
# set random state to 0 to shuffle data to get probabilities

C = 10
# create the different classifiers (for others these would be models)
classifiers = {
    # 'Linear SVC': SVC(kernel='linear', C=C, probability=True,random_state=0),
    # points placed  is created and data are gathered around these points so the labels can be predicted
    # 'KNN classifier': KNeighborsClassifier(C),
    # Support-Vector classifiers: map training samples to points in space to max distance btw 2 categories, later data is mapped onto space to predict category
    # 'SVC': SVC(),
    'RFST': RandomForestClassifier(n_estimators=100),
    'ADA': AdaBoostClassifier(n_estimators=100)
}

n_classifiers = len(classifiers)
for index, (name, classifier) in enumerate(classifiers.items()):
    classifier.fit(X_train, np.ravel(y_train))

    y_pred = classifier.predict(X_test)
    accuracy = accuracy_score(y_test, y_pred)
    print("Accuracy (train) for %s: %0.1f%% " % (name, accuracy * 100))
    np.set_printoptions(threshold=sys.maxsize)
    print(classification_report(y_test,y_pred))<jupyter_output>Accuracy (train) for RFST: 83.9% 
              precision    recall  f1-score   support

     chinese       0.79      0.74      0.77       224
      indian       0.89      0.94      0.91       240
    japanese       0.84      0.82      0.83       248
      korean       0.83      0.80      0.81       219
        thai       0.84      0.88      0.86       268

    accuracy                           0.84      1199
   macro avg       0.84      0.84      0.84      1199
weighted avg       0.84      0.84      0.84      1199

Accuracy (train) for ADA: 71.0% 
              precision    recall  f1-score   support

     chinese       0.61      0.48      0.54       224
      indian       0.77      0.86      0.81       240
    japanese       0.78      0.65      0.71       248
      korean       0.64      0.81      0.72       219
        thai       0.73      0.74      0.73       268

    accuracy                           0.71      1199
   macro avg       0.71      0.71      0.70      1199
weighted a[...]
{'fraction_non_alphanumeric': 0.07801418439716312, 'fraction_numerical': 0.061979648473635525, 'mean_word_length': 2.4919268030139934, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '506675', 'license': 'MIT', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1023, 'n_words': 300, 'path': '4-Classification/3-Classifiers-2/notebook.ipynb', 'repo_name': 'JuliaWada/ML-For-Beginners', 'size': '3243'}