<jupyter_start><jupyter_text>Titanic 2<jupyter_code>%load_ext autoreload
%autoreload 2

%matplotlib inline
from fastai.imports import *
from fastai.structured import *

from pandas_summary import DataFrameSummary
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
from IPython.display import display

from sklearn import metrics
from sklearn.model_selection import train_test_split
PATH = "data/titanic/"
df_raw = pd.read_csv(f'{PATH}train.csv')
df_raw.isnull().sum() / len(df_raw.isnull())
df_raw.head()
df_raw.drop('Cabin', axis=1, inplace=True)
df_raw.isnull().sum() / len(df_raw.isnull())
df_raw.Age.fillna(df_raw['Age'].mean(), inplace=True)
df_raw.dropna(inplace=True)
df_raw.isnull().sum() / len(df_raw.isnull())
df_raw.info()
df_raw.drop(['PassengerId', 'Fare', 'Ticket', 'Name'], axis=1, inplace=True)
df_raw.info()
df = pd.get_dummies(df_raw, columns=['Sex', 'Embarked'], drop_first=True)
df.head()
X = df.drop('Survived', axis=1)
y = df['Survived']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.44, random_state=42)
m = RandomForestClassifier(n_jobs=-1)
%time m.fit(X_train, y_train)
m.score(X_test, y_test)<jupyter_output>CPU times: user 151 ms, sys: 56.3 ms, total: 208 ms
Wall time: 149 ms
{'fraction_non_alphanumeric': 0.15027977617905675, 'fraction_numerical': 0.01838529176658673, 'mean_word_length': 7.2368421052631575, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '423309', 'license': 'Apache-2.0', 'n_tokens_mistral': 520, 'n_tokens_neox': 495, 'n_words': 99, 'path': 'courses/ml1/Untitled1.ipynb', 'repo_name': 'qabbasi/fastai', 'size': '1251'}