**RMarkdown** enables you to interleave Markdown text, blocks of code, and output.

If you're in the editor, the resulting notebook will be shown on the HTML tab to the right.

This R environment comes with all of CRAN preinstalled, as well as many other helpful packages

The environment is defined by the [kaggle/rstats docker image](https://github.com/kaggle/docker-rstats).

For example, here's several helpful packages to load in 

```{r}
# This is a code block
library(ggplot2) # Data visualization
library(readr) # CSV file I/O, e.g. the read_csv function
library(caret)
library(ranger)
```

Input data files are available in the "../input/" directory.

For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory

```{r}
system("ls ../input", intern=TRUE)
```

Any results you write to the current directory are saved as output.
```{r}
train=read_csv("../input/train.csv")
test=read_csv("../input/test.csv")
```

```{r}
train$label=as.factor(train$label)
```

```{r}
  model5 <- train(label~., data=train, method = "ranger", tuneGrid = data.frame(mtry=c(2,3,7)), trControl=trainControl(method="cv", number=5))
```

```{r}
p=predict(model5, newdata=test)
predictions <- data.frame(ImageId=1:nrow(test), Label=p)
head(predictions)
```

```{r}
write_csv(predictions, "rf_benchmark.csv") 
```