text_html_output_1.png
from sklearn.preprocessing import LabelEncoder

import pandas as pd

ks = pd.read_csv('../input/kickstarter-projects/ks-projects-201801.csv', parse_dates=['deadline', 'launched'])

pd.unique(ks.state)

ks.groupby('state')['ID'].count()

ks = ks.query('state != "live"')
ks = ks.assign(outcome=(ks['state'] == 'successful').astype(int))

ks = ks.assign(hour=ks.launched.dt.hour, day=ks.launched.dt.day, month=ks.launched.dt.month, year=ks.launched.dt.year)

cat_features = ['category', 'currency', 'country']
encoder = LabelEncoder()
encoded = ks[cat_features].apply(encoder.fit_transform)

data = ks[['goal', 'hour', 'day', 'month', 'year', 'outcome']].join(encoded)

valid_fraction = 0.1
valid_size = int(len(data) * valid_fraction)
train = data[:-2 * valid_size]
valid = data[-2 * valid_size:-valid_size]
test = data[-valid_size:]

for each in [train, valid, test]:
    print(f'Outcome fraction = {each.outcome.mean():.4f}')