text_plain_output_5.png text_plain_output_4.png text_plain_output_6.png text_plain_output_3.png text_plain_output_7.png text_plain_output_2.png text_plain_output_1.png
from keras.layers.core import Dense, Dropout, Activation, Flatten, MaxoutDense

from keras.models import Sequential

from keras.optimizers import Adam , RMSprop, Adadelta, SGD

from sklearn import preprocessing

from sklearn.cross_validation import train_test_split

import pandas as pd

import numpy as np
import pandas as pd
from keras.models import Model
from keras.layers import Input, merge, Convolution2D, MaxPooling2D, UpSampling2D, ZeroPadding2D
from keras.optimizers import Adam, RMSprop, Adadelta, SGD
from keras.callbacks import ModelCheckpoint, LearningRateScheduler, EarlyStopping
from keras.layers.normalization import BatchNormalization
from keras import backend as K
from keras.layers.core import Dense, Dropout, Activation, Flatten, MaxoutDense
from keras.layers.advanced_activations import PReLU, ELU
act_train = pd.read_csv('../input/act_train.csv')
act_test = pd.read_csv('../input/act_test.csv')
people = pd.read_csv('../input/people.csv')
test_ids = act_test['activity_id']
def preprocess_acts(data, train_set=True):
    data = data.drop(['date', 'activity_id'], axis=1)
    if train_set:
        data = data.drop(['outcome'], axis=1)
    data['people_id'] = data['people_id'].apply(lambda x: x.split('_')[1])
    data['people_id'] = pd.to_numeric(data['people_id']).astype(int)
    columns = list(data.columns)
    for col in columns[1:]:
        data[col] = data[col].fillna('type 0')
        data[col] = data[col].apply(lambda x: x.split(' ')[1])
        data[col] = pd.to_numeric(data[col]).astype(int)
    return data
def preprocess_people(data):
    data = data.drop(['date'], axis=1)
    data['people_id'] = data['people_id'].apply(lambda x: x.split('_')[1])
    data['people_id'] = pd.to_numeric(data['people_id']).astype(int)
    columns = list(data.columns)
    bools = columns[11:]
    strings = columns[1:11]
    for col in bools:
        data[col] = pd.to_numeric(data[col]).astype(int)
    for col in strings:
        data[col] = data[col].fillna('type 0')
        data[col] = data[col].apply(lambda x: x.split(' ')[1])
        data[col] = pd.to_numeric(data[col]).astype(int)
    return data
peeps = preprocess_people(people)
actions_train = preprocess_acts(act_train)
actions_test = preprocess_acts(act_test, train_set=False)
features = actions_train.merge(peeps, how='left', on='people_id')
labels = act_train['outcome']
test = actions_test.merge(peeps, how='left', on='people_id')
features.sample(10)

from keras.models import Sequential
from keras.layers.normalization import BatchNormalization
from keras.layers.advanced_activations import PReLU
from keras.callbacks import ModelCheckpoint, LearningRateScheduler, EarlyStopping
def create_model_v1(input_dim):
    nb_classes = 1
    model = Sequential()
    model.add(Dense(100, input_dim=input_dim, activation='relu'))
    model.add(Dense(100, activation='relu'))
    model.add(Dense(nb_classes))
    model.add(Activation('sigmoid'))
    sgd = SGD(lr=0.05, decay=0, momentum=0.95, nesterov=True)
    model.compile(loss='binary_crossentropy', optimizer=sgd, metrics=['accuracy'])
    return model
from sklearn import preprocessing
from sklearn.cross_validation import train_test_split
features = features.as_matrix()
scaler = preprocessing.StandardScaler().fit(features)
features = scaler.transform(features)
num_test = 0.2
X_train, X_test, y_train, y_test = train_test_split(features, labels.as_matrix(), test_size=num_test, random_state=1337)

print(features[0, :])