text_plain_output_1.png
from plotly.offline import init_notebook_mode, iplot

from sklearn import metrics

from sklearn.discriminant_analysis import LinearDiscriminantAnalysis

from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis

from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier, GradientBoostingClassifier, BaggingClassifier

from sklearn.model_selection import GridSearchCV

from sklearn.naive_bayes import GaussianNB

from sklearn.neighbors import KNeighborsClassifier

from sklearn.svm import SVC, LinearSVC, NuSVC

from sklearn.tree import DecisionTreeClassifier

import matplotlib.pyplot as plt  # Matlab-style plotting

import os

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

import warnings

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode(connected=True)
import seaborn as sns
color = sns.color_palette()
sns.set_style('darkgrid')
import warnings
def ignore_warn(*args, **kwargs):
    pass
warnings.warn = ignore_warn
from scipy import stats
from scipy.stats import norm, skew
pd.set_option('display.float_format', lambda x: '{:.3f}'.format(x))
import os

train = pd.read_csv('../input/train.csv')
test = pd.read_csv('../input/test.csv')

train_ID = train['id']
test_ID = test['id']
train.drop('id', axis=1, inplace=True)
test.drop('id', axis=1, inplace=True)

corrmat = train.corr()

missing = train.isnull().sum()

train_dummy = pd.get_dummies(pd.read_csv('../input/train.csv'))

ghost_num = {'type': {'Ghoul': 1, 'Goblin': 2, 'Ghost': 3}}

train.replace(ghost_num, inplace=True)

ntrain = train.shape[0]
ntest = test.shape[0]
y = train.type.values
all_data = pd.concat((train, test)).reset_index(drop=True)
all_data.drop(['type'], axis=1, inplace=True)

all_data.drop(['color'], axis=1, inplace=True)

all_data_simple = pd.DataFrame()
all_data_simple['bone_hair'] = all_data['bone_hair']
all_data_simple['rotting_flesh'] = all_data['rotting_flesh']
all_data_simple['bone_soul'] = all_data['bone_soul']
all_data_simple['hair_soul'] = all_data['hair_soul']

from sklearn.metrics import accuracy_score, log_loss
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC, LinearSVC, NuSVC
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier, GradientBoostingClassifier, BaggingClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis
classifiers = [KNeighborsClassifier(3), SVC(kernel='rbf', C=0.025, probability=True), NuSVC(probability=True), DecisionTreeClassifier(), RandomForestClassifier(), AdaBoostClassifier(), GradientBoostingClassifier(), GaussianNB(), LinearDiscriminantAnalysis(), QuadraticDiscriminantAnalysis()]
log_cols = ['Classifier', 'Accuracy', 'Log Loss']
log = pd.DataFrame(columns=log_cols)
for clf in classifiers:
    clf.fit(train_X, train_y)
    name = clf.__class__.__name__
    score = clf.score(val_X, val_y)

from sklearn.model_selection import GridSearchCV
from sklearn import metrics
accuracy_scorer = metrics.make_scorer(metrics.accuracy_score)
params = {'n_estimators': [10, 20, 50, 100], 'criterion': ['gini', 'entropy'], 'max_depth': [None, 5, 10, 25, 50]}
rf = RandomForestClassifier(random_state=0)
clf = GridSearchCV(rf, param_grid=params, scoring=accuracy_scorer, cv=5, n_jobs=-1)
clf.fit(train_X, train_y)

params = {'n_estimators': [10, 25, 50, 100], 'max_samples': [1, 3, 5, 10]}
bag = BaggingClassifier(random_state=0)
clf = GridSearchCV(bag, param_grid=params, scoring=accuracy_scorer, cv=5, n_jobs=-1)
clf.fit(train_X, train_y)
print('Best score: {}'.format(clf.best_score_))
print('Best parameters: {}'.format(clf.best_params_))