
library(randomForest)
library(readr)

set.seed(0)

numTrain <- 10000
numTrees <- 25

train <- read_csv("../input/train.csv")

rows <- sample(1:nrow(train), numTrain)
labels <- as.factor(train[rows,]$label)
test <- train[-rows,]
train <- train[rows,-1]
print(labels)
rf <- randomForest(train, labels, xtest=test[,-1], ntree=numTrees)
predictions <- data.frame(ImageId=1:nrow(test[,-1]), rf$test$predicted)
predictions['actual']=test[,1]
colnames(predictions)[2]='Label'
predictions['matched']=(predictions['Label']==predictions['actual'])
print(colSums(predictions['matched']))