text_plain_output_1.png
from scipy.stats import skew

from sklearn.ensemble import RandomForestClassifier

from sklearn.linear_model import LogisticRegression

import matplotlib

import numpy as np

import pandas as pd

all_data = pd.concat((train.loc[:, 'Pclass':'Embarked'], test.loc[:, 'Pclass':'Embarked']))

matplotlib.rcParams['figure.figsize'] = (14.0, 7.0)
prices = pd.DataFrame({'Fare': train['Fare'], 'log(Fare + 1)': np.log1p(train['Fare'])})

numeric_feats = all_data.dtypes[all_data.dtypes != 'object'].index
skewed_feats = train[numeric_feats].apply(lambda X: skew(X.dropna()))
skewed_feats = skewed_feats[skewed_feats > 0.75]
skewed_feats = skewed_feats.index
all_data[skewed_feats] = np.log1p(all_data[skewed_feats])

all_data = pd.get_dummies(all_data)

all_data = all_data.fillna(all_data.mean())

X_train = all_data[:train.shape[0]]
X_test = all_data[train.shape[0]:]
y = train.Survived

logreg = LogisticRegression()
logreg.fit(X_train, y)
accuracy = round(logreg.score(X_train, y) * 100, 2)
logreg_preds = logreg.predict(X_test)

from sklearn.ensemble import RandomForestClassifier
random_forest = RandomForestClassifier(n_estimators=100)
random_forest.fit(X_train, y)
random_forest_preds = random_forest.predict(X_test)
random_forest.score(X_train, y)
accuracy = round(random_forest.score(X_train, y) * 100, 2)
print(accuracy)