TImporting Libray
library(randomForest)
## randomForest 4.6-14
## Type rfNews() to see new features/changes/bug fixes.
Loading Data into the dataframe from CSV
dataframe <- read.csv("~/AI/DataSet/DecisionTreeDataSet.csv",header=T, na.strings=c("","NA"))
names(dataframe)
## [1] "Temperature" "Outlook" "Humidity" "Windy" "Golf"
Seperating Test and Train Data
train <- na.omit(dataframe)
test <- dataframe[is.na(dataframe$Golf),]
Visualizing train data
train
Visualizing test data where golf is to be predicted by decision tree later
test
rf <- randomForest(
as.factor(Golf) ~ .,
data=train,
importance = TRUE
)
summary(rf)
## Length Class Mode
## call 4 -none- call
## type 1 -none- character
## predicted 14 factor numeric
## err.rate 1500 -none- numeric
## confusion 6 -none- numeric
## votes 28 matrix numeric
## oob.times 14 -none- numeric
## classes 2 -none- character
## importance 16 -none- numeric
## importanceSD 12 -none- numeric
## localImportance 0 -none- NULL
## proximity 0 -none- NULL
## ntree 1 -none- numeric
## mtry 1 -none- numeric
## forest 14 -none- list
## y 14 factor numeric
## test 0 -none- NULL
## inbag 0 -none- NULL
## terms 3 terms call
getTree(rf, 1, labelVar=TRUE)
importance(rf)
## No Yes MeanDecreaseAccuracy MeanDecreaseGini
## Temperature -5.011112 -5.03988484 -7.360167 0.6459323
## Outlook 6.660717 2.96561307 6.415526 2.2072407
## Humidity 4.622113 -0.51422958 2.596054 1.3663751
## Windy -2.561929 0.09603357 -1.122286 1.0114805
predTrain <- predict(rf, test, type = "class")
test$Golf = predTrain
test