Instantly share code, notes, and snippets.

anonymous /DecisionTreeRegressor.py
Created Jun 5, 2016

Embed
What would you like to do?
Sample submission for Mirocana tournament
from sklearn.tree import DecisionTreeRegressor
import pandas as pd
import numpy as np
train = pd.read_csv('train.csv').set_index('_id')
X = np.array(train.drop(['gain'], 1))
y = np.array(train['gain'])
model = DecisionTreeRegressor(max_depth=7)
model.fit(X, y)
def get_prediction(row):
x = np.array(row).reshape(1, -1)
prediction = model.predict(x)[0]
return prediction
test = pd.read_csv('test.csv').set_index('_id')
test['prediction'] = test.apply(get_prediction, 1)
test[['prediction']].to_csv('submission.csv')
_id prediction
56fb76d167fea07b8205a157 0.21214776666666663
56fa9e3567fea07b82033970 0.1020773
56fd3ecb67fea07b82097baf 0.07168892500000001
56fd352a67fea07b8209699a -0.07677525833333332
56f8d41ccae8eb6b5e93ef66 -0.14174491666666672
56fb586b67fea07b82055356 -0.07245079999999998
56f898e2cae8eb6b5e923585 -0.07270148333333332
56fba5b767fea07b8206163c 0.14422668214285714
56f8c1dccae8eb6b5e937ede 0.14851565
56f9e31967fea07b82009dee 0.05341395
56fba58d67fea07b820615d3 1.2297312
56fdc0ed67fea07b820a6bb4 0.19956689999999996
56fd3f3567fea07b82097c77 0.0462007
56fd3fbf67fea07b82097d80 0.04459721166666666
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment