text_plain_output_1.png
import pandas as pd

import seaborn as sns

import pandas as pd
import numpy as np
import seaborn as sns
baseDir = '../input/'
people = pd.read_csv('{0}people.csv'.format(baseDir)).drop_duplicates()
act_train = pd.read_csv('{0}act_train.csv'.format(baseDir)).drop_duplicates()
act_test = pd.read_csv('{0}act_test.csv'.format(baseDir)).drop_duplicates()

unqTrain = act_train.drop(['activity_id', 'outcome'], axis=1).drop_duplicates()
unqTest = act_test.drop(['activity_id'], axis=1).drop_duplicates()
total = pd.concat([unqTrain, unqTest], axis=0)

def addPrefix(df, suffix, exclude):
    for c in df.columns:
        if c not in exclude:
            df.rename(columns={c: suffix + c}, inplace=True)

train = pd.merge(act_train, people, on='people_id', how='left')
test = pd.merge(act_test, people, on='people_id', how='left')

trainUnique = train[~train.drop(['people_id', 'activity_id'], axis=1).duplicated()]
testUnique = test[~test.drop(['people_id', 'activity_id'], axis=1).duplicated()]

nonCategoricalColumns = ['people_id', 'activity_id', 'outcome', 'ppl_char_38', 'ppl_date', 'act_date']
valCounts = {}
def calcCountSuffix(df, exclude):
    for c in df.columns:
        if c not in exclude:
            cnt = len(df[c].value_counts())
            valCounts[c] = cnt
calcCountSuffix(trainUnique, nonCategoricalColumns)

def addCountSuffix(df, exclude):
    for c in df.columns:
        if c not in exclude:
            cnt = valCounts[c]
            df.rename(columns={c: c + '_cnt_' + str(cnt)}, inplace=True)
addCountSuffix(train, nonCategoricalColumns)
addCountSuffix(test, nonCategoricalColumns)
addCountSuffix(trainUnique, nonCategoricalColumns)
addCountSuffix(testUnique, nonCategoricalColumns)

def getColumnsBySuffix(df, minValue, maxValue, exclude):
    return [c for c in df.columns if c not in exclude if int(c.split('_')[-1]) >= minValue and int(c.split('_')[-1]) <= maxValue]
def drawViolin(df, minCnt, maxCnt, indexFrom, indexTo, size=3.5):
    g = sns.PairGrid(df, x_vars=getColumnsBySuffix(train, minCnt, maxCnt, nonCategoricalColumns)[indexFrom:indexTo], y_vars=['outcome'], aspect=0.75, size=size)
    g.map(sns.violinplot, palette='pastel')

sam10k = trainUnique.sample(10000)
sam100k = trainUnique.sample(100000)
sam500k = trainUnique.sample(500000)

drawViolin(sam10k, 2, 2, 0, 6)