-
Notifications
You must be signed in to change notification settings - Fork 10
/
topic_005.r
63 lines (48 loc) · 1.66 KB
/
topic_005.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Dataset overview
# https://vincentarelbundock.github.io/Rdatasets/datasets.html
USArrests
data <- USArrests
help(USArrests)
#Feature construction
last.letter.vowel = c()
for(i in 1:dim(data)[1]) {
state.name = rownames(data)[i]
lenth.of.state.name = nchar(state.name)
last.letter = substr(state.name,lenth.of.state.name, lenth.of.state.name)
if (last.letter %in% c('a','e','i','o','u','y')) {
last.letter.vowel<-c(last.letter.vowel,1)
}
else {
last.letter.vowel<-c(last.letter.vowel,0)
}
}
data = cbind(data,last.letter.vowel)
# Random Forest execution
install.packages('randomForest')
library(randomForest)
#https://cran.r-project.org/web/packages/randomForest/randomForest.pdf
data(iris)
# https://www.rdocumentation.org/packages/utils/versions/3.4.3/topics/data
iris.rf <- randomForest(iris[,-5], iris[,5], prox=TRUE)
# -5 removes column 5
# 5 selects only column 5
# note use of = sign
# Note documentation doesn't indicate boolean type expected
importance(iris.rf)
#iris.rf.2 <- randomForest(iris[,3:4], iris[,5], prox=TRUE)
#iris.rf.2
#Plotting nice
#iris.p <- classCenter(iris[,-5], iris[,5], iris.rf$prox)
#plot(iris[,3], iris[,4], pch=21, xlab=names(iris)[3], ylab=names(iris)[4],
#bg=c("red", "blue", "green")[as.numeric(factor(iris$Species))],
#main="Iris Data with Prototypes")
#points(iris.p[,3], iris.p[,4], pch=21, cex=2, bg=c("red", "blue", "green"))
#library(randomForest)
#M = iris[,-5] # messurment ddata
#L = iris[,5] # Species categories, discrete labels Levels == setosa versicolor virginica
#iris.rf <- randomForest(M, L, prox=TRUE)
#hist(iris[,1]+iris[,2])
#hist(iris[,1]-iris[,2], breaks=30)
#
#predict(iris.rf, iris[1,-5])
#plot