<jupyter_start><jupyter_text>Data Science in Visual Studio Code* https://code.visualstudio.com/docs/python/data-science-tutorial<jupyter_code>import numpy as np
import pandas as pd

data = pd.read_csv("titanic3.csv")
data.dtypes

data.replace('?', np.nan, inplace= True)
data = data.astype({"age": np.float64, "fare": np.float64})
data.dtypes

import seaborn as sns
import matplotlib.pyplot as plt

fig, axs = plt.subplots(ncols=5, figsize=(30,5))
sns.violinplot(x="survived", y="age", hue="sex", data=data, ax=axs[0])
sns.pointplot(x="sibsp", y="survived", hue="sex", data=data, ax=axs[1])
sns.pointplot(x="parch", y="survived", hue="sex", data=data, ax=axs[2])
sns.pointplot(x="pclass", y="survived", hue="sex", data=data, ax=axs[3])
sns.violinplot(x="survived", y="fare", hue="sex", data=data, ax=axs[4])
data.replace({'male': 1, 'female': 0}, inplace=True)

data.corr().abs()[["survived"]]

data['relatives'] = data.apply (lambda row: int((row['sibsp'] + row['parch']) > 0), axis=1)

data.corr().abs()[["survived"]]
data = data[['sex', 'pclass','age','relatives','fare','survived']].dropna()

from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(data[['sex','pclass','age','relatives','fare']], data.survived, test_size=0.2, random_state=0)
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(x_train)
X_test = sc.transform(x_test)
from sklearn.naive_bayes import GaussianNB
model = GaussianNB()
model.fit(X_train, y_train)
from sklearn import metrics
predict_test = model.predict(X_test)
print(metrics.accuracy_score(y_test, predict_test))<jupyter_output>0.7464114832535885<jupyter_text>Use a neural network to increase accuracy<jupyter_code>from keras.models import Sequential
from keras.layers import Dense

model = Sequential()
model.add(Dense(5, kernel_initializer = 'uniform', activation = 'relu', input_dim = 5))
model.add(Dense(5, kernel_initializer = 'uniform', activation = 'relu'))
model.add(Dense(1, kernel_initializer = 'uniform', activation = 'sigmoid'))
model.summary()
model.compile(optimizer="adam", loss='binary_crossentropy', metrics=['accuracy'])
model.fit(X_train, y_train, batch_size=32, epochs=50)
y_pred = model.predict_classes(X_test)
print(metrics.accuracy_score(y_test, y_pred))<jupyter_output>0.7894736842105263
{'fraction_non_alphanumeric': 0.17343015805211448, 'fraction_numerical': 0.02691157624946604, 'mean_word_length': 8.405622489959839, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 1, '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': '650283', 'license': 'MIT', 'n_tokens_mistral': 927, 'n_tokens_neox': 883, 'n_words': 164, 'path': 'ml-titanic/hello.ipynb', 'repo_name': 'wences-dc-uba-ar/python-vscode-sandbox', 'size': '2341'}