<jupyter_start><jupyter_text>Naive Bayes Part 1: Predicting survival from titanic crash<jupyter_code>import pandas as pd
df = pd.read_csv("titanic.csv")
df.head()
df.drop(['PassengerId','Name','SibSp','Parch','Ticket','Cabin','Embarked'],axis='columns',inplace=True)
df.head()
inputs = df.drop('Survived',axis='columns')
target = df.Survived
dummies = pd.get_dummies(inputs.Sex)
dummies.head(3)
inputs = pd.concat([inputs,dummies],axis='columns')
inputs.head(3)<jupyter_output><empty_output><jupyter_text>**I am dropping male column as well because of dummy variable trap theory. One column is enough to repressent male vs female**<jupyter_code>inputs.drop(['Sex','male'],axis='columns',inplace=True)
inputs.head(3)
inputs.columns[inputs.isna().any()]
inputs.Age[:10]
inputs.Age = inputs.Age.fillna(inputs.Age.mean())
inputs.head()
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(inputs,target,test_size=0.3)
from sklearn.naive_bayes import GaussianNB
model = GaussianNB()
model.fit(X_train,y_train)
model.score(X_test,y_test)
X_test[0:10]
y_test[0:10]
model.predict(X_test[0:10])
model.predict_proba(X_test[:10])
model.predict([[3,26.000000,7.8875,0]])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16129032258064516, 'fraction_numerical': 0.027419354838709678, 'mean_word_length': 9.428571428571429, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '610068', 'license': 'MIT', 'n_tokens_mistral': 495, 'n_tokens_neox': 467, 'n_words': 76, 'path': 'Week03/Day01/Naive Bayes/naive_bayes_1_titanic_survival_prediction.ipynb', 'repo_name': 'harunshimanto/Machine-Learning-With-Python-Training-session-', 'size': '1240'}