Skip to content

Instantly share code, notes, and snippets.

@mattlewissf
Created August 23, 2016 21:26
Show Gist options
  • Save mattlewissf/8dc0ca4f666417aa713d5e4120933519 to your computer and use it in GitHub Desktop.
Save mattlewissf/8dc0ca4f666417aa713d5e4120933519 to your computer and use it in GitHub Desktop.
Kaggle | Digit Recognizer
""" First attempt at Kaggle Digit Recognizer | https://www.kaggle.com/c/digit-recognizer/
Basic approach w/ random trees results in 0.96486 accuracy
"""
import pandas as pd
import numpy as np
from numpy import savetxt
from sklearn.ensemble import RandomForestClassifier
# import data
train = pd.read_csv('train.csv')
test = pd.read_csv('test.csv')
# format Y
Y = train['label']
Y = Y.values.tolist()
# format X
X = train.drop('label', axis=1)
X = X.values.tolist()
# fit the model
rf = RandomForestClassifier(n_estimators=100)
print rf # see if it works
rf.fit(X,Y) # fits in place, right?
# trying out predict
prediction = rf.predict(test).tolist()
index = range(1,2801)
# create output csv
np.savetxt('prediction.csv', (index,prediction), delimiter=' ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment