text_plain_output_2.png application_vnd.jupyter.stderr_output_1.png
from sklearn.linear_model import LogisticRegression

from sklearn.tree import DecisionTreeClassifier

import pandas as pd

act_train = pd.read_csv('../input/act_train.csv')
act_test = pd.read_csv('../input/act_test.csv')

act_train_char_10 = act_train[act_train['char_10'].notnull().values]
act_test_char_10 = act_test[act_test['char_10'].notnull().values]
drop_list = ['char_1', 'char_2', 'char_3', 'char_4', 'char_5', 'char_6', 'char_7', 'char_8', 'char_9']
act_train_char_10.drop(drop_list, axis=1, inplace=True)
act_test_char_10.drop(drop_list, axis=1, inplace=True)
act_train_char_X = act_train[act_train['char_10'].isnull().values]
act_test_char_X = act_test[act_test['char_10'].isnull().values]
drop_list = ['char_10']
act_train_char_X.drop(drop_list, axis=1, inplace=True)
act_test_char_X.drop(drop_list, axis=1, inplace=True)

people = pd.read_csv('../input/people.csv')

act_train_char_10 = pd.merge(act_train_char_10, people, on='people_id', how='left')
act_test_char_10 = pd.merge(act_test_char_10, people, on='people_id', how='left')
act_train_char_X = pd.merge(act_train_char_X, people, on='people_id', how='left')
act_test_char_X = pd.merge(act_test_char_X, people, on='people_id', how='left')

act_train_char_10.drop(['date_x', 'date_y'], axis=1, inplace=True)
act_test_char_10.drop(['date_x', 'date_y'], axis=1, inplace=True)
rename_dict = {'char_10_x': 'char_10_act', 'char_10_y': 'char_10_peo'}
act_train_char_10.rename(columns=rename_dict, inplace=True)
act_test_char_10.rename(columns=rename_dict, inplace=True)

act_train_char_X.drop(['date_x', 'date_y'], axis=1, inplace=True)
act_test_char_X.drop(['date_x', 'date_y'], axis=1, inplace=True)
rename_dict = {'char_1_x': 'char_1_act', 'char_2_x': 'char_2_act', 'char_3_x': 'char_3_act', 'char_4_x': 'char_4_act', 'char_5_x': 'char_5_act', 'char_6_x': 'char_6_act', 'char_7_x': 'char_7_act', 'char_8_x': 'char_8_act', 'char_9_x': 'char_9_act', 'char_1_y': 'char_1_peo', 'char_2_y': 'char_2_peo', 'char_3_y': 'char_3_peo', 'char_4_y': 'char_4_peo', 'char_5_y': 'char_5_peo', 'char_6_y': 'char_6_peo', 'char_7_y': 'char_7_peo', 'char_8_y': 'char_8_peo', 'char_9_y': 'char_9_peo'}
act_train_char_X.rename(columns=rename_dict, inplace=True)
act_test_char_X.rename(columns=rename_dict, inplace=True)

act_train_char_10 = act_train_char_10.astype(str)
act_test_char_10 = act_test_char_10.astype(str)
act_train_char_X = act_train_char_X.astype(str)
act_test_char_X = act_test_char_X.astype(str)
act_train_char_10 = act_train_char_10.replace(['True', 'False'], [1, 0])
act_test_char_10 = act_test_char_10.replace(['True', 'False'], [1, 0])
act_train_char_X = act_train_char_X.replace(['True', 'False'], [1, 0])
act_test_char_X = act_test_char_X.replace(['True', 'False'], [1, 0])

features_char_10 = list(act_train_char_10.columns.values)
features_char_X = list(act_train_char_X.columns.values)
features_char_10.remove('people_id')
features_char_10.remove('activity_id')
features_char_10.remove('outcome')
features_char_X.remove('people_id')
features_char_X.remove('activity_id')
features_char_X.remove('outcome')
label = ['outcome']
VALIDATION_SIZE = 10000

dtc_char_10 = DecisionTreeClassifier()
dtc_char_10.fit(act_train_char_10[features_char_10].ix[VALIDATION_SIZE:], act_train_char_10[label].ix[VALIDATION_SIZE:])
print('Accuracy_Char_10 = ' + str(dtc_char_10.score(act_train_char_10[features_char_10].ix[:VALIDATION_SIZE], act_train_char_10[label].ix[:VALIDATION_SIZE])))
dct_char_X = LogisticRegression()
dct_char_X.fit(act_train_char_X[features_char_X].ix[VALIDATION_SIZE:], act_train_char_X[label].ix[VALIDATION_SIZE:])
print('Accuracy_Char_X = ' + str(dct_char_X.score(act_train_char_X[features_char_X].ix[:VALIDATION_SIZE], act_train_char_X[label].ix[:VALIDATION_SIZE])))