Created
December 1, 2013 10:53
-
-
Save aivarasko/7731958 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # -*- coding: utf-8 -*- | |
| # <nbformat>3.0</nbformat> | |
| # <codecell> | |
| import pandas as pd | |
| from pandas import Series | |
| # <codecell> | |
| train_data = pd.read_csv('digit_recognizer/data/train.csv') | |
| test_data = pd.read_csv('digit_recognizer/data/test.csv') | |
| # <codecell> | |
| digits = train_data.pop('label') | |
| # <codecell> | |
| from sklearn.ensemble import RandomForestClassifier | |
| from sklearn.tree import DecisionTreeClassifier | |
| ''' | |
| from sklearn.neighbors import KNeighborsClassifier | |
| from sklearn.svm import SVC | |
| from sklearn.ensemble import GradientBoostingClassifier | |
| from sklearn.naive_bayes import GaussianNB | |
| from sklearn.lda import LDA | |
| from sklearn.qda import QDA | |
| classifiers = [ | |
| KNeighborsClassifier(3), | |
| KNeighborsClassifier(15), | |
| SVC(kernel="linear", C=0.025), | |
| # SVC(kernel="poly", C=0.025), | |
| SVC(gamma=2, C=1), | |
| DecisionTreeClassifier(max_depth=5), | |
| RandomForestClassifier(max_depth=None, n_estimators=100, random_state=0), | |
| # RandomForestClassifier(max_depth=20, n_estimators=25, max_features=3), | |
| GaussianNB(), | |
| # LDA(), | |
| QDA(), | |
| SVC(), | |
| GradientBoostingClassifier(n_estimators=100, learning_rate=1.0, max_depth=1, random_state=0), | |
| GradientBoostingClassifier(n_estimators=100, learning_rate=1.0, max_depth=3, random_state=0) | |
| ] | |
| ''' | |
| cl = RandomForestClassifier(max_depth=None, n_estimators=100, random_state=0) | |
| # cl = DecisionTreeClassifier(max_depth=5), | |
| # <codecell> | |
| # cl = classifiers[5] | |
| cl.fit(train_data, digits) | |
| # <codecell> | |
| # <codecell> | |
| # cl.score(train_data[100:], digits[100:]) | |
| # <codecell> | |
| predictions = cl.predict(test_data) | |
| Series(predictions).to_csv('digit_recognizer/results/results_random_forest.csv', index=False) | |
| # <codecell> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment