Created
August 23, 2016 21:26
-
-
Save mattlewissf/8dc0ca4f666417aa713d5e4120933519 to your computer and use it in GitHub Desktop.
Kaggle | Digit Recognizer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" 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