<jupyter_start><jupyter_text>Implementation of Naive Bayes Classifier Author: <NAME> Reg No: 20MAI0044<jupyter_code>#1: Importing necessary Libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score
from sklearn.metrics import classification_report
#2: Tweaking the datasets
train = pd.read_csv("trainT.csv") #Titanic data-set
df = train[['Survived','Pclass','Sex','Age','Fare']] #implies columns
df['Sex'] = df['Sex'].apply(lambda sex:1 if sex=='male' else 0)
print(df.isna().sum())
df['Age'] = df['Age'].fillna(df['Age']).median()
print(df['Age'].isnull().sum())
print(df.isna().sum())
X = df.drop('Survived',axis=1)
Y = df['Survived']
from sklearn.naive_bayes import GaussianNB
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.3, random_state=0)
gnb = GaussianNB()
y_pred_gnb = gnb.fit(X_train, y_train).predict(X_test)
cnf_matrix_gnb = confusion_matrix(y_test, y_pred_gnb)
print(cnf_matrix_gnb)
accuracy_score(y_test,y_pred_gnb)
#13: Classification Report
report = classification_report(y_test,y_pred_gnb)
print(report)<jupyter_output>precision    recall  f1-score   support

           0       0.84      0.80      0.82       168
           1       0.69      0.75      0.72       100

    accuracy                           0.78       268
   macro avg       0.77      0.77      0.77       268
weighted avg       0.79      0.78      0.78       268
{'fraction_non_alphanumeric': 0.11538461538461539, 'fraction_numerical': 0.046027742749054225, 'mean_word_length': 3.751497005988024, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '352335', 'license': 'MIT', 'n_tokens_mistral': 603, 'n_tokens_neox': 554, 'n_words': 129, 'path': 'ML_Lab_Assignment4_2.ipynb', 'repo_name': 'tejaswini212/ML-Techniques---Lab', 'size': '1595'}