text_plain_output_1.png
from sklearn.ensemble import RandomForestClassifier

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

train_set = pd.read_csv('../input/train.csv')
test_set = pd.read_csv('../input/test.csv')

image_array = np.asfarray(train_set.iloc[3, 1:]).reshape((28, 28))

X_train = train_set.iloc[:, 1:].values
y_train = train_set.label.values

from sklearn.ensemble import RandomForestClassifier
classifier = RandomForestClassifier(criterion='entropy', n_estimators=10, max_depth=3, random_state=0)
classifier.fit(X_train, y_train)

classifier.score(X_train, y_train)

pred = classifier.predict(test_set)
pred

sub_lines = []
for i in range(0, len(pred)):
    sub_lines.append([i + 1, pred[i]])
submission = pd.DataFrame(sub_lines, columns=['ImageId', 'Label'])
submission.to_csv('submission.csv', index=False)
submission.head()