<jupyter_start><jupyter_text>Classification<jupyter_code># imports
import pandas as pd
import numpy as np<jupyter_output><empty_output><jupyter_text>Import Data<jupyter_code>df = pd.read_csv('../data/raw/titanic_prepared_data.csv')
df.head()<jupyter_output><empty_output><jupyter_text>Separating Features and Labels<jupyter_code>X = df.iloc[:, 1:].values
y = df.iloc[:, 0:1].values
print(X.shape, y.shape)<jupyter_output>(891, 10) (891, 1)<jupyter_text>Splitting into Train and Test set<jupyter_code>from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3, random_state = 0)
print(X_train.shape, y_train.shape)<jupyter_output>(623, 10) (623, 1)<jupyter_text>Classification and Accuracy<jupyter_code>from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
clf = LogisticRegression()
clf.fit(X_train, y_train.ravel()) #Trivia : What does ravel do?
y_pred_log_reg = clf.predict(X_test)
acc_log_reg = round( accuracy_score(y_pred_log_reg, y_test) * 100, 2)
print(str(acc_log_reg) + ' %')
print(y_train.shape)
print(y_train.ravel().shape)<jupyter_output>(623, 1)
(623,)<jupyter_text>Regularisation Constant<jupyter_code>clf2 = LogisticRegression(C=0.08)
clf2.fit(X_train, y_train.ravel()) #Trivia : What does ravel do?
y_pred_log_reg2 = clf2.predict(X_test)
acc_log_reg2 = round( accuracy_score(y_pred_log_reg2, y_test) * 100, 2)
print (str(acc_log_reg2) + ' %')<jupyter_output>81.34 %<jupyter_text>k -Nearest Neighbors<jupyter_code>from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score
clf = KNeighborsClassifier(n_neighbors = 3)
clf.fit(X_train, y_train.ravel())
y_pred_knn = clf.predict(X_test)
acc_knn = round(accuracy_score(y_pred_knn, y_test) * 100, 2)
print (str(acc_knn) + ' %')<jupyter_output>68.28 %<jupyter_text>Gaussian Naive Bayes<jupyter_code>from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()
clf.fit(X_train, y_train.ravel())
y_pred_gnb = clf.predict(X_test)
acc_gnb = round(accuracy_score(y_pred_gnb, y_test) * 100, 2)
print (str(acc_gnb) + ' %')<jupyter_output>78.36 %<jupyter_text>Decision Trees<jupyter_code>from sklearn.tree import DecisionTreeClassifier
clf = DecisionTreeClassifier()
clf.fit(X_train, y_train.ravel())
y_pred_decision_tree = clf.predict(X_test)
acc_decision_tree = round(accuracy_score(y_pred_decision_tree, y_test) * 100, 2)
print (str(acc_decision_tree) + ' %')<jupyter_output>75.75 %<jupyter_text>Random Forest<jupyter_code>from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
clf = RandomForestClassifier(n_estimators=100)
clf.fit(X_train, y_train.ravel())
y_pred_random_forest = clf.predict(X_test)
acc_random_forest = round(accuracy_score(y_pred_random_forest, y_test) * 100, 2)
print (str(acc_random_forest) + ' percent')<jupyter_output>80.6 percent<jupyter_text>Comparing Models<jupyter_code>models = pd.DataFrame({
    'Model': ['Logistic Regression', 'KNN', 'Decision Tree', 
              'Random Forest', 'Naive Bayes'],
    
    'Score': [acc_log_reg, acc_knn,  acc_decision_tree, 
              acc_random_forest, acc_gnb]
    })

models.sort_values(by='Score', ascending=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12457809143909175, 'fraction_numerical': 0.02700214789812826, 'mean_word_length': 8.030470914127424, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '298789', 'license': 'MIT', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1300, 'n_words': 208, 'path': 'notebooks/Classification.ipynb', 'repo_name': 'sanattaori/Titanic-DS', 'size': '3259'}