SlideShare a Scribd company logo
file<-'c://Users/rk215/Data/heart.csv'
heart<-read.csv(file,head=T,sep=',',stringsAsFactors=F)
unlist(lapply(names(heart),FUN=function(x,data=heart){c(cname=x,uvalfreq=len
gth(unique(data[[x]])))}))
M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore...
1 of 14 11/23/2020, 5:44 PM
## cname uvalfreq cname uvalfreq cname uvalfreq cn
ame
## "age" "41" "sex" "2" "cp" "4" "trestb
ps"
## uvalfreq cname uvalfreq cname uvalfreq cname uvalf
req
## "49" "chol" "152" "fbs" "2" "restecg"
"3"
## cname uvalfreq cname uvalfreq cname uvalfreq cn
ame
## "thalach" "91" "exang" "2" "oldpeak" "40" "slo
pe"
## uvalfreq cname uvalfreq cname uvalfreq cname uvalf
req
## "3" "ca" "5" "thal" "4" "target"
"2"
nvpairsdf3<-do.call('rbind',lapply(names(heart),FUN=function(x,data=heart){c
(cname=x,uvalfreq=length(unique(data[[x]])))}))
categoricalFeatures<-function(dset,ncol=7)
{
df4<-as.data.frame(do.call('rbind',lapply(names(dset),FUN=function(x,data=
dset){c(cname=x,uvalfreq=length(unique(data[[x]])))})))
df4$uvalfreq=as.numeric(df4$uvalfreq)
dset[,df4$uvalfreq<=ncol]
}
X<-categoricalFeatures(heart)
table(heart$target)
##
## 0 1
## 138 165
dim(X)
## [1] 303 9
M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore...
2 of 14 11/23/2020, 5:44 PM
class_col<-which(names(X)=='target')
fvcnt<-ncol(X[,-c(class_col)])
#set.seed if you want to repeatability
#RF implementations consider sqrt(p) features
# to avoid too many common features
# here we are seeking to establish that it matters
# we are concerned about features being present in both
exp_fset1<-sample(1:fvcnt,fvcnt-1,replace=F)
exp_fset2<-sample(1:fvcnt,fvcnt-1,replace=F)
table(sort(exp_fset1)==sort(exp_fset2))
##
## TRUE
## 7
exp_fset1
## [1] 1 2 5 4 3 6 7
exp_fset2
## [1] 7 3 1 2 5 6 4
M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore...
3 of 14 11/23/2020, 5:44 PM
##
## rcpALL 0 1
## 0 116 14
## 1 22 151
## [1] 0.8778656
## [1] 0.0000000 0.1594203 1.0000000
## [1] 0.0000000 0.9151515 1.0000000
X1<-X[,c(exp_fset1,9)]
rpart.model1<-rpart(target~.,data=X1,minsplit=3)
rpart.plot(rpart.model1)
M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore...
4 of 14 11/23/2020, 5:44 PM
rcp1<-predict(rpart.model1,
X1[,-c(which(names(X1)=="target"))],type="
class")
(rpart_mtab1<-table(rcp1,X$target))
##
## rcp1 0 1
## 0 107 15
## 1 31 150
L1<-getMetrics(X1$target,as.numeric(rcp1))
L1$auc
## [1] 0.8422266
L1$fpr
## [1] 0.0000000 0.2246377 1.0000000
L1$tpr
M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore...
5 of 14 11/23/2020, 5:44 PM
## [1] 0.0000000 0.9090909 1.0000000
X2<-X[,c(exp_fset2,9)]
rpart.model2<-rpart(target~.,data=X2,minsplit=3)
rpart.plot(rpart.model2)
rcp2<-predict(rpart.model2,
X2[,-c(which(names(X2)=="target"))],type="
class")
(rpart_mtab2<-table(rcp2,X2$target))
##
## rcp2 0 1
## 0 107 15
## 1 31 150
L2<-getMetrics(X2$target,as.numeric(rcp2))
L2$auc
## [1] 0.8422266
M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore...
6 of 14 11/23/2020, 5:44 PM
L2$fpr
## [1] 0.0000000 0.2246377 1.0000000
L2$tpr
## [1] 0.0000000 0.9090909 1.0000000
exp_fset3<-sample(1:fvcnt,fvcnt-1,replace=F)
X3<-X[,c(exp_fset3,9)]
rpart.model3<-rpart(target~.,data=X3,minsplit=3)
rpart.plot(rpart.model2)
rcp3<-predict(rpart.model3,
X3[,-c(which(names(X3)=="target"))],type="
class")
(rpart_mtab3<-table(rcp3,X3$target))
M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore...
7 of 14 11/23/2020, 5:44 PM
##
## rcp3 0 1
## 0 111 24
## 1 27 141
L3<-getMetrics(X3$target,as.numeric(rcp3))
L3$auc
## [1] 0.8294466
L3$fpr
## [1] 0.0000000 0.1956522 1.0000000
L3$tpr
## [1] 0.0000000 0.8545455 1.0000000
dfpred<-data.frame(actual=X$target,rcpALL,rcp1,rcp2,rcp3)
head(dfpred)
## actual rcpALL rcp1 rcp2 rcp3
## 1 1 1 1 1 1
## 2 1 1 1 1 1
## 3 1 1 1 1 1
## 4 1 1 1 1 1
## 5 1 1 1 1 0
## 6 1 1 1 1 1
table(X$target,rcpALL)
## rcpALL
## 0 1
## 0 116 22
## 1 14 151
table(X$target,rcp1)
M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore...
8 of 14 11/23/2020, 5:44 PM
## rcp1
## 0 1
## 0 107 31
## 1 15 150
table(X$target,rcp2)
## rcp2
## 0 1
## 0 107 31
## 1 15 150
table(X$target,rcp3)
## rcp3
## 0 1
## 0 111 27
## 1 24 141
…
…
if(!require(randomForest))require(randomForest)
## Loading required package: randomForest
## randomForest 4.6-14
## Type rfNews() to see new features/changes/bug fixes.
rf_model<-randomForest(target~.,data=X)
rf_pred<-predict(rf_model,X[,-c(which(names(X)=="target"))])
rf_mtab<-table(X$target,rf_pred)
rf_cmx<-caret::confusionMatrix(rf_mtab)
rf_mtab
## rf_pred
## 0 1
## 0 124 14
## 1 10 155
(rf_accuracy<-sum(diag(rf_mtab))/sum(rf_mtab))
M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore...
9 of 14 11/23/2020, 5:44 PM
## [1] 0.9207921
rf_cmx$overall
## Accuracy Kappa AccuracyLower AccuracyUpper AccuracyNul
l
## 9.207921e-01 8.399366e-01 8.844364e-01 9.485923e-01 5.577558e-0
1
## AccuracyPValue McnemarPValue
## 1.441683e-44 5.402914e-01
rf_cmx$byClass
## Sensitivity Specificity Pos Pred Value
## 0.9253731 0.9171598 0.8985507
## Neg Pred Value Precision Recall
## 0.9393939 0.8985507 0.9253731
## F1 Prevalence Detection Rate
## 0.9117647 0.4422442 0.4092409
## Detection Prevalence Balanced Accuracy
## 0.4554455 0.9212664
rf1k_model<-randomForest(target~.,data=X,ntree=1000)
rf1k_pred<-predict(rf1k_model,X[,-c(which(names(X)=="target"))])
rf1k_mtab<-table(X$target,rf1k_pred)
rf1k_cmx<-caret::confusionMatrix(rf1k_mtab)
rf1k_mtab
## rf1k_pred
## 0 1
## 0 121 17
## 1 8 157
(rf1k_accuracy<-sum(diag(rf1k_mtab))/sum(rf1k_mtab))
## [1] 0.9174917
rf1k_cmx$overall
M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore...
10 of 14 11/23/2020, 5:44 PM
## Accuracy Kappa AccuracyLower AccuracyUpper AccuracyNul
l
## 9.174917e-01 8.327704e-01 8.806106e-01 9.458942e-01 5.742574e-0
1
## AccuracyPValue McnemarPValue
## 1.656736e-40 1.095986e-01
rf1k_cmx$byClass
## Sensitivity Specificity Pos Pred Value
## 0.9379845 0.9022989 0.8768116
## Neg Pred Value Precision Recall
## 0.9515152 0.8768116 0.9379845
## F1 Prevalence Detection Rate
## 0.9063670 0.4257426 0.3993399
## Detection Prevalence Balanced Accuracy
## 0.4554455 0.9201417
rf100_model<-randomForest(target~.,data=X,ntree=100)
rf100_pred<-predict(rf100_model,X[,-c(which(names(X)=="target"))])
rf100_mtab<-table(X$target,rf100_pred)
rf100_cmx<-caret::confusionMatrix(rf100_mtab)
rf100_mtab
## rf100_pred
## 0 1
## 0 123 15
## 1 11 154
(rf100_accuracy<-sum(diag(rf100_mtab))/sum(rf100_mtab))
## [1] 0.9141914
rf100_cmx$overall
## Accuracy Kappa AccuracyLower AccuracyUpper AccuracyNul
l
## 9.141914e-01 8.265980e-01 8.767989e-01 9.431813e-01 5.577558e-0
1
## AccuracyPValue McnemarPValue
## 1.093523e-42 5.562985e-01
rf100_cmx$byClass
M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore...
11 of 14 11/23/2020, 5:44 PM
## Sensitivity Specificity Pos Pred Value
## 0.9179104 0.9112426 0.8913043
## Neg Pred Value Precision Recall
## 0.9333333 0.8913043 0.9179104
## F1 Prevalence Detection Rate
## 0.9044118 0.4422442 0.4059406
## Detection Prevalence Balanced Accuracy
## 0.4554455 0.9145765
rf50_model<-randomForest(target~.,data=X,ntree=50)
rf50_pred<-predict(rf50_model,X[,-c(which(names(X)=="target"))])
rf50_mtab<-table(X$target,rf50_pred)
rf50_cmx<-caret::confusionMatrix(rf50_mtab)
rf50_mtab
## rf50_pred
## 0 1
## 0 124 14
## 1 11 154
(rf1k_accuracy<-sum(diag(rf50_mtab))/sum(rf50_mtab))
## [1] 0.9174917
rf1k_cmx$overall
## Accuracy Kappa AccuracyLower AccuracyUpper AccuracyNul
l
## 9.174917e-01 8.327704e-01 8.806106e-01 9.458942e-01 5.742574e-0
1
## AccuracyPValue McnemarPValue
## 1.656736e-40 1.095986e-01
rf1k_cmx$byClass
## Sensitivity Specificity Pos Pred Value
## 0.9379845 0.9022989 0.8768116
## Neg Pred Value Precision Recall
## 0.9515152 0.8768116 0.9379845
## F1 Prevalence Detection Rate
## 0.9063670 0.4257426 0.3993399
## Detection Prevalence Balanced Accuracy
## 0.4554455 0.9201417
M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore...
12 of 14 11/23/2020, 5:44 PM
rfgrow<-grow(rf50_model,50)
rfgrow_pred<-predict(rfgrow,X[,-c(which(names(X)=="target"))])
rfgrow_mtab<-table(X$target,rfgrow_pred)
rfgrow_cmx<-caret::confusionMatrix(rfgrow_mtab)
rfgrow_mtab
## rfgrow_pred
## 0 1
## 0 123 15
## 1 9 156
(rfgrow_accuracy<-sum(diag(rfgrow_mtab))/sum(rfgrow_mtab))
## [1] 0.9207921
rfgrow_cmx$overall
## Accuracy Kappa AccuracyLower AccuracyUpper AccuracyNul
l
## 9.207921e-01 8.397461e-01 8.844364e-01 9.485923e-01 5.643564e-0
1
## AccuracyPValue McnemarPValue
## 2.685766e-43 3.074342e-01
rfgrow_cmx$byClass
## Sensitivity Specificity Pos Pred Value
## 0.9318182 0.9122807 0.8913043
## Neg Pred Value Precision Recall
## 0.9454545 0.8913043 0.9318182
## F1 Prevalence Detection Rate
## 0.9111111 0.4356436 0.4059406
## Detection Prevalence Balanced Accuracy
## 0.4554455 0.9220494
M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore...
13 of 14 11/23/2020, 5:44 PM
M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore...
14 of 14 11/23/2020, 5:44 PM

More Related Content

What's hot

Redis 101
Redis 101Redis 101
Redis 101
Doğan Can
 
Command
CommandCommand
Command
gajshield
 
Five
FiveFive
Association Rule Mining with R
Association Rule Mining with RAssociation Rule Mining with R
Association Rule Mining with R
Yanchang Zhao
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
Wim Godden
 
Data manipulation and visualization in r 20190711 myanmarucsy
Data manipulation and visualization in r 20190711 myanmarucsyData manipulation and visualization in r 20190711 myanmarucsy
Data manipulation and visualization in r 20190711 myanmarucsy
SmartHinJ
 
Gevent rabbit rpc
Gevent rabbit rpcGevent rabbit rpc
Gevent rabbit rpc
Aleksandr Mokrov
 
Beyond php it's not (just) about the code
Beyond php   it's not (just) about the codeBeyond php   it's not (just) about the code
Beyond php it's not (just) about the code
Wim Godden
 
Regression and Classification with R
Regression and Classification with RRegression and Classification with R
Regression and Classification with R
Yanchang Zhao
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
akaptur
 
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
akaptur
 
Parallel Computing With Dask - PyDays 2017
Parallel Computing With Dask - PyDays 2017Parallel Computing With Dask - PyDays 2017
Parallel Computing With Dask - PyDays 2017
Christian Aichinger
 
System Calls
System CallsSystem Calls
System Calls
David Evans
 
Cooking pies with Celery
Cooking pies with CeleryCooking pies with Celery
Cooking pies with Celery
Aleksandr Mokrov
 
Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on Autonomous
Connor McDonald
 
Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolest
Connor McDonald
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the code
Wim Godden
 
Python testing-frameworks overview
Python testing-frameworks overviewPython testing-frameworks overview
Python testing-frameworks overview
Jachym Cepicky
 
python高级内存管理
python高级内存管理python高级内存管理
python高级内存管理
rfyiamcool
 
Agile Database Development with JSON
Agile Database Development with JSONAgile Database Development with JSON
Agile Database Development with JSON
Chris Saxon
 

What's hot (20)

Redis 101
Redis 101Redis 101
Redis 101
 
Command
CommandCommand
Command
 
Five
FiveFive
Five
 
Association Rule Mining with R
Association Rule Mining with RAssociation Rule Mining with R
Association Rule Mining with R
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
Data manipulation and visualization in r 20190711 myanmarucsy
Data manipulation and visualization in r 20190711 myanmarucsyData manipulation and visualization in r 20190711 myanmarucsy
Data manipulation and visualization in r 20190711 myanmarucsy
 
Gevent rabbit rpc
Gevent rabbit rpcGevent rabbit rpc
Gevent rabbit rpc
 
Beyond php it's not (just) about the code
Beyond php   it's not (just) about the codeBeyond php   it's not (just) about the code
Beyond php it's not (just) about the code
 
Regression and Classification with R
Regression and Classification with RRegression and Classification with R
Regression and Classification with R
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
 
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
 
Parallel Computing With Dask - PyDays 2017
Parallel Computing With Dask - PyDays 2017Parallel Computing With Dask - PyDays 2017
Parallel Computing With Dask - PyDays 2017
 
System Calls
System CallsSystem Calls
System Calls
 
Cooking pies with Celery
Cooking pies with CeleryCooking pies with Celery
Cooking pies with Celery
 
Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on Autonomous
 
Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolest
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the code
 
Python testing-frameworks overview
Python testing-frameworks overviewPython testing-frameworks overview
Python testing-frameworks overview
 
python高级内存管理
python高级内存管理python高级内存管理
python高级内存管理
 
Agile Database Development with JSON
Agile Database Development with JSONAgile Database Development with JSON
Agile Database Development with JSON
 

Similar to M12 random forest-part01

R (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support SystemR (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support System
Maithreya Chakravarthula
 
Spark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj Talk
Spark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj TalkSpark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj Talk
Spark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj Talk
Zalando Technology
 
R is a very flexible and powerful programming language, as well as a.pdf
R is a very flexible and powerful programming language, as well as a.pdfR is a very flexible and powerful programming language, as well as a.pdf
R is a very flexible and powerful programming language, as well as a.pdf
annikasarees
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
Sander Kieft
 
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
The Statistical and Applied Mathematical Sciences Institute
 
Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)
David de Boer
 
Seminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mmeSeminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mme
Vyacheslav Arbuzov
 
R code for data manipulation
R code for data manipulationR code for data manipulation
R code for data manipulation
Avjinder (Avi) Kaler
 
R code for data manipulation
R code for data manipulationR code for data manipulation
R code for data manipulation
Avjinder (Avi) Kaler
 
A Shiny Example-- R
A Shiny Example-- RA Shiny Example-- R
A Shiny Example-- R
Dr. Volkan OBAN
 
Vcs16
Vcs16Vcs16
Ns2programs
Ns2programsNs2programs
Ns2programs
Meenakshi Devi
 
Do snow.rwn
Do snow.rwnDo snow.rwn
Do snow.rwn
ARUN DN
 
R code
R codeR code
R code
Manav Goel
 
Rcommands-for those who interested in R.
Rcommands-for those who interested in R.Rcommands-for those who interested in R.
Rcommands-for those who interested in R.
Dr. Volkan OBAN
 
Pre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to Elixir
Paweł Dawczak
 
Php functions
Php functionsPhp functions
Php functions
JIGAR MAKHIJA
 
Prediction
PredictionPrediction
Prediction
Ban Bang
 
Time Series Analysis and Mining with R
Time Series Analysis and Mining with RTime Series Analysis and Mining with R
Time Series Analysis and Mining with R
Yanchang Zhao
 
Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.
Dr. Volkan OBAN
 

Similar to M12 random forest-part01 (20)

R (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support SystemR (Shiny Package) - Server Side Code for Decision Support System
R (Shiny Package) - Server Side Code for Decision Support System
 
Spark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj Talk
Spark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj TalkSpark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj Talk
Spark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj Talk
 
R is a very flexible and powerful programming language, as well as a.pdf
R is a very flexible and powerful programming language, as well as a.pdfR is a very flexible and powerful programming language, as well as a.pdf
R is a very flexible and powerful programming language, as well as a.pdf
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
 
Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)
 
Seminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mmeSeminar PSU 10.10.2014 mme
Seminar PSU 10.10.2014 mme
 
R code for data manipulation
R code for data manipulationR code for data manipulation
R code for data manipulation
 
R code for data manipulation
R code for data manipulationR code for data manipulation
R code for data manipulation
 
A Shiny Example-- R
A Shiny Example-- RA Shiny Example-- R
A Shiny Example-- R
 
Vcs16
Vcs16Vcs16
Vcs16
 
Ns2programs
Ns2programsNs2programs
Ns2programs
 
Do snow.rwn
Do snow.rwnDo snow.rwn
Do snow.rwn
 
R code
R codeR code
R code
 
Rcommands-for those who interested in R.
Rcommands-for those who interested in R.Rcommands-for those who interested in R.
Rcommands-for those who interested in R.
 
Pre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to ElixirPre-Bootcamp introduction to Elixir
Pre-Bootcamp introduction to Elixir
 
Php functions
Php functionsPhp functions
Php functions
 
Prediction
PredictionPrediction
Prediction
 
Time Series Analysis and Mining with R
Time Series Analysis and Mining with RTime Series Analysis and Mining with R
Time Series Analysis and Mining with R
 
Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.
 

More from Raman Kannan

Essays on-civic-responsibilty
Essays on-civic-responsibiltyEssays on-civic-responsibilty
Essays on-civic-responsibilty
Raman Kannan
 
M12 boosting-part02
M12 boosting-part02M12 boosting-part02
M12 boosting-part02
Raman Kannan
 
M10 gradient descent
M10 gradient descentM10 gradient descent
M10 gradient descent
Raman Kannan
 
M06 tree
M06 treeM06 tree
M06 tree
Raman Kannan
 
M07 svm
M07 svmM07 svm
M07 svm
Raman Kannan
 
M08 BiasVarianceTradeoff
M08 BiasVarianceTradeoffM08 BiasVarianceTradeoff
M08 BiasVarianceTradeoff
Raman Kannan
 
Chapter 05 k nn
Chapter 05 k nnChapter 05 k nn
Chapter 05 k nn
Raman Kannan
 
Chapter 04-discriminant analysis
Chapter 04-discriminant analysisChapter 04-discriminant analysis
Chapter 04-discriminant analysis
Raman Kannan
 
M03 nb-02
M03 nb-02M03 nb-02
M03 nb-02
Raman Kannan
 
Augmented 11022020-ieee
Augmented 11022020-ieeeAugmented 11022020-ieee
Augmented 11022020-ieee
Raman Kannan
 
Chapter 02-logistic regression
Chapter 02-logistic regressionChapter 02-logistic regression
Chapter 02-logistic regression
Raman Kannan
 
Chapter01 introductory handbook
Chapter01 introductory handbookChapter01 introductory handbook
Chapter01 introductory handbook
Raman Kannan
 
A voyage-inward-02
A voyage-inward-02A voyage-inward-02
A voyage-inward-02
Raman Kannan
 
Evaluating classifierperformance ml-cs6923
Evaluating classifierperformance ml-cs6923Evaluating classifierperformance ml-cs6923
Evaluating classifierperformance ml-cs6923
Raman Kannan
 
A data scientist's study plan
A data scientist's study planA data scientist's study plan
A data scientist's study plan
Raman Kannan
 
Cognitive Assistants
Cognitive AssistantsCognitive Assistants
Cognitive Assistants
Raman Kannan
 
Essay on-data-analysis
Essay on-data-analysisEssay on-data-analysis
Essay on-data-analysis
Raman Kannan
 
Joy of Unix
Joy of UnixJoy of Unix
Joy of Unix
Raman Kannan
 
How to-run-ols-diagnostics-02
How to-run-ols-diagnostics-02How to-run-ols-diagnostics-02
How to-run-ols-diagnostics-02
Raman Kannan
 
Sdr dodd frankbirdseyeview
Sdr dodd frankbirdseyeviewSdr dodd frankbirdseyeview
Sdr dodd frankbirdseyeview
Raman Kannan
 

More from Raman Kannan (20)

Essays on-civic-responsibilty
Essays on-civic-responsibiltyEssays on-civic-responsibilty
Essays on-civic-responsibilty
 
M12 boosting-part02
M12 boosting-part02M12 boosting-part02
M12 boosting-part02
 
M10 gradient descent
M10 gradient descentM10 gradient descent
M10 gradient descent
 
M06 tree
M06 treeM06 tree
M06 tree
 
M07 svm
M07 svmM07 svm
M07 svm
 
M08 BiasVarianceTradeoff
M08 BiasVarianceTradeoffM08 BiasVarianceTradeoff
M08 BiasVarianceTradeoff
 
Chapter 05 k nn
Chapter 05 k nnChapter 05 k nn
Chapter 05 k nn
 
Chapter 04-discriminant analysis
Chapter 04-discriminant analysisChapter 04-discriminant analysis
Chapter 04-discriminant analysis
 
M03 nb-02
M03 nb-02M03 nb-02
M03 nb-02
 
Augmented 11022020-ieee
Augmented 11022020-ieeeAugmented 11022020-ieee
Augmented 11022020-ieee
 
Chapter 02-logistic regression
Chapter 02-logistic regressionChapter 02-logistic regression
Chapter 02-logistic regression
 
Chapter01 introductory handbook
Chapter01 introductory handbookChapter01 introductory handbook
Chapter01 introductory handbook
 
A voyage-inward-02
A voyage-inward-02A voyage-inward-02
A voyage-inward-02
 
Evaluating classifierperformance ml-cs6923
Evaluating classifierperformance ml-cs6923Evaluating classifierperformance ml-cs6923
Evaluating classifierperformance ml-cs6923
 
A data scientist's study plan
A data scientist's study planA data scientist's study plan
A data scientist's study plan
 
Cognitive Assistants
Cognitive AssistantsCognitive Assistants
Cognitive Assistants
 
Essay on-data-analysis
Essay on-data-analysisEssay on-data-analysis
Essay on-data-analysis
 
Joy of Unix
Joy of UnixJoy of Unix
Joy of Unix
 
How to-run-ols-diagnostics-02
How to-run-ols-diagnostics-02How to-run-ols-diagnostics-02
How to-run-ols-diagnostics-02
 
Sdr dodd frankbirdseyeview
Sdr dodd frankbirdseyeviewSdr dodd frankbirdseyeview
Sdr dodd frankbirdseyeview
 

Recently uploaded

University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
soxrziqu
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
sameer shah
 
Experts live - Improving user adoption with AI
Experts live - Improving user adoption with AIExperts live - Improving user adoption with AI
Experts live - Improving user adoption with AI
jitskeb
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
Social Samosa
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
Sm321
 
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
74nqk8xf
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
74nqk8xf
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
javier ramirez
 
一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理
一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理
一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理
74nqk8xf
 
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
nyfuhyz
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
rwarrenll
 
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
g4dpvqap0
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
aqzctr7x
 
Intelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicineIntelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicine
AndrzejJarynowski
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
apvysm8
 
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
zsjl4mimo
 
DSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelinesDSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelines
Timothy Spann
 
Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
jerlynmaetalle
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
Walaa Eldin Moustafa
 

Recently uploaded (20)

University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
 
Experts live - Improving user adoption with AI
Experts live - Improving user adoption with AIExperts live - Improving user adoption with AI
Experts live - Improving user adoption with AI
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
 
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
 
一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理
一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理
一比一原版(牛布毕业证书)牛津布鲁克斯大学毕业证如何办理
 
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
 
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
 
Intelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicineIntelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicine
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
 
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
 
DSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelinesDSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelines
 
Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
 

M12 random forest-part01

  • 2. ## cname uvalfreq cname uvalfreq cname uvalfreq cn ame ## "age" "41" "sex" "2" "cp" "4" "trestb ps" ## uvalfreq cname uvalfreq cname uvalfreq cname uvalf req ## "49" "chol" "152" "fbs" "2" "restecg" "3" ## cname uvalfreq cname uvalfreq cname uvalfreq cn ame ## "thalach" "91" "exang" "2" "oldpeak" "40" "slo pe" ## uvalfreq cname uvalfreq cname uvalfreq cname uvalf req ## "3" "ca" "5" "thal" "4" "target" "2" nvpairsdf3<-do.call('rbind',lapply(names(heart),FUN=function(x,data=heart){c (cname=x,uvalfreq=length(unique(data[[x]])))})) categoricalFeatures<-function(dset,ncol=7) { df4<-as.data.frame(do.call('rbind',lapply(names(dset),FUN=function(x,data= dset){c(cname=x,uvalfreq=length(unique(data[[x]])))}))) df4$uvalfreq=as.numeric(df4$uvalfreq) dset[,df4$uvalfreq<=ncol] } X<-categoricalFeatures(heart) table(heart$target) ## ## 0 1 ## 138 165 dim(X) ## [1] 303 9 M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore... 2 of 14 11/23/2020, 5:44 PM
  • 3. class_col<-which(names(X)=='target') fvcnt<-ncol(X[,-c(class_col)]) #set.seed if you want to repeatability #RF implementations consider sqrt(p) features # to avoid too many common features # here we are seeking to establish that it matters # we are concerned about features being present in both exp_fset1<-sample(1:fvcnt,fvcnt-1,replace=F) exp_fset2<-sample(1:fvcnt,fvcnt-1,replace=F) table(sort(exp_fset1)==sort(exp_fset2)) ## ## TRUE ## 7 exp_fset1 ## [1] 1 2 5 4 3 6 7 exp_fset2 ## [1] 7 3 1 2 5 6 4 M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore... 3 of 14 11/23/2020, 5:44 PM
  • 4. ## ## rcpALL 0 1 ## 0 116 14 ## 1 22 151 ## [1] 0.8778656 ## [1] 0.0000000 0.1594203 1.0000000 ## [1] 0.0000000 0.9151515 1.0000000 X1<-X[,c(exp_fset1,9)] rpart.model1<-rpart(target~.,data=X1,minsplit=3) rpart.plot(rpart.model1) M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore... 4 of 14 11/23/2020, 5:44 PM
  • 5. rcp1<-predict(rpart.model1, X1[,-c(which(names(X1)=="target"))],type=" class") (rpart_mtab1<-table(rcp1,X$target)) ## ## rcp1 0 1 ## 0 107 15 ## 1 31 150 L1<-getMetrics(X1$target,as.numeric(rcp1)) L1$auc ## [1] 0.8422266 L1$fpr ## [1] 0.0000000 0.2246377 1.0000000 L1$tpr M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore... 5 of 14 11/23/2020, 5:44 PM
  • 6. ## [1] 0.0000000 0.9090909 1.0000000 X2<-X[,c(exp_fset2,9)] rpart.model2<-rpart(target~.,data=X2,minsplit=3) rpart.plot(rpart.model2) rcp2<-predict(rpart.model2, X2[,-c(which(names(X2)=="target"))],type=" class") (rpart_mtab2<-table(rcp2,X2$target)) ## ## rcp2 0 1 ## 0 107 15 ## 1 31 150 L2<-getMetrics(X2$target,as.numeric(rcp2)) L2$auc ## [1] 0.8422266 M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore... 6 of 14 11/23/2020, 5:44 PM
  • 7. L2$fpr ## [1] 0.0000000 0.2246377 1.0000000 L2$tpr ## [1] 0.0000000 0.9090909 1.0000000 exp_fset3<-sample(1:fvcnt,fvcnt-1,replace=F) X3<-X[,c(exp_fset3,9)] rpart.model3<-rpart(target~.,data=X3,minsplit=3) rpart.plot(rpart.model2) rcp3<-predict(rpart.model3, X3[,-c(which(names(X3)=="target"))],type=" class") (rpart_mtab3<-table(rcp3,X3$target)) M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore... 7 of 14 11/23/2020, 5:44 PM
  • 8. ## ## rcp3 0 1 ## 0 111 24 ## 1 27 141 L3<-getMetrics(X3$target,as.numeric(rcp3)) L3$auc ## [1] 0.8294466 L3$fpr ## [1] 0.0000000 0.1956522 1.0000000 L3$tpr ## [1] 0.0000000 0.8545455 1.0000000 dfpred<-data.frame(actual=X$target,rcpALL,rcp1,rcp2,rcp3) head(dfpred) ## actual rcpALL rcp1 rcp2 rcp3 ## 1 1 1 1 1 1 ## 2 1 1 1 1 1 ## 3 1 1 1 1 1 ## 4 1 1 1 1 1 ## 5 1 1 1 1 0 ## 6 1 1 1 1 1 table(X$target,rcpALL) ## rcpALL ## 0 1 ## 0 116 22 ## 1 14 151 table(X$target,rcp1) M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore... 8 of 14 11/23/2020, 5:44 PM
  • 9. ## rcp1 ## 0 1 ## 0 107 31 ## 1 15 150 table(X$target,rcp2) ## rcp2 ## 0 1 ## 0 107 31 ## 1 15 150 table(X$target,rcp3) ## rcp3 ## 0 1 ## 0 111 27 ## 1 24 141 … … if(!require(randomForest))require(randomForest) ## Loading required package: randomForest ## randomForest 4.6-14 ## Type rfNews() to see new features/changes/bug fixes. rf_model<-randomForest(target~.,data=X) rf_pred<-predict(rf_model,X[,-c(which(names(X)=="target"))]) rf_mtab<-table(X$target,rf_pred) rf_cmx<-caret::confusionMatrix(rf_mtab) rf_mtab ## rf_pred ## 0 1 ## 0 124 14 ## 1 10 155 (rf_accuracy<-sum(diag(rf_mtab))/sum(rf_mtab)) M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore... 9 of 14 11/23/2020, 5:44 PM
  • 10. ## [1] 0.9207921 rf_cmx$overall ## Accuracy Kappa AccuracyLower AccuracyUpper AccuracyNul l ## 9.207921e-01 8.399366e-01 8.844364e-01 9.485923e-01 5.577558e-0 1 ## AccuracyPValue McnemarPValue ## 1.441683e-44 5.402914e-01 rf_cmx$byClass ## Sensitivity Specificity Pos Pred Value ## 0.9253731 0.9171598 0.8985507 ## Neg Pred Value Precision Recall ## 0.9393939 0.8985507 0.9253731 ## F1 Prevalence Detection Rate ## 0.9117647 0.4422442 0.4092409 ## Detection Prevalence Balanced Accuracy ## 0.4554455 0.9212664 rf1k_model<-randomForest(target~.,data=X,ntree=1000) rf1k_pred<-predict(rf1k_model,X[,-c(which(names(X)=="target"))]) rf1k_mtab<-table(X$target,rf1k_pred) rf1k_cmx<-caret::confusionMatrix(rf1k_mtab) rf1k_mtab ## rf1k_pred ## 0 1 ## 0 121 17 ## 1 8 157 (rf1k_accuracy<-sum(diag(rf1k_mtab))/sum(rf1k_mtab)) ## [1] 0.9174917 rf1k_cmx$overall M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore... 10 of 14 11/23/2020, 5:44 PM
  • 11. ## Accuracy Kappa AccuracyLower AccuracyUpper AccuracyNul l ## 9.174917e-01 8.327704e-01 8.806106e-01 9.458942e-01 5.742574e-0 1 ## AccuracyPValue McnemarPValue ## 1.656736e-40 1.095986e-01 rf1k_cmx$byClass ## Sensitivity Specificity Pos Pred Value ## 0.9379845 0.9022989 0.8768116 ## Neg Pred Value Precision Recall ## 0.9515152 0.8768116 0.9379845 ## F1 Prevalence Detection Rate ## 0.9063670 0.4257426 0.3993399 ## Detection Prevalence Balanced Accuracy ## 0.4554455 0.9201417 rf100_model<-randomForest(target~.,data=X,ntree=100) rf100_pred<-predict(rf100_model,X[,-c(which(names(X)=="target"))]) rf100_mtab<-table(X$target,rf100_pred) rf100_cmx<-caret::confusionMatrix(rf100_mtab) rf100_mtab ## rf100_pred ## 0 1 ## 0 123 15 ## 1 11 154 (rf100_accuracy<-sum(diag(rf100_mtab))/sum(rf100_mtab)) ## [1] 0.9141914 rf100_cmx$overall ## Accuracy Kappa AccuracyLower AccuracyUpper AccuracyNul l ## 9.141914e-01 8.265980e-01 8.767989e-01 9.431813e-01 5.577558e-0 1 ## AccuracyPValue McnemarPValue ## 1.093523e-42 5.562985e-01 rf100_cmx$byClass M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore... 11 of 14 11/23/2020, 5:44 PM
  • 12. ## Sensitivity Specificity Pos Pred Value ## 0.9179104 0.9112426 0.8913043 ## Neg Pred Value Precision Recall ## 0.9333333 0.8913043 0.9179104 ## F1 Prevalence Detection Rate ## 0.9044118 0.4422442 0.4059406 ## Detection Prevalence Balanced Accuracy ## 0.4554455 0.9145765 rf50_model<-randomForest(target~.,data=X,ntree=50) rf50_pred<-predict(rf50_model,X[,-c(which(names(X)=="target"))]) rf50_mtab<-table(X$target,rf50_pred) rf50_cmx<-caret::confusionMatrix(rf50_mtab) rf50_mtab ## rf50_pred ## 0 1 ## 0 124 14 ## 1 11 154 (rf1k_accuracy<-sum(diag(rf50_mtab))/sum(rf50_mtab)) ## [1] 0.9174917 rf1k_cmx$overall ## Accuracy Kappa AccuracyLower AccuracyUpper AccuracyNul l ## 9.174917e-01 8.327704e-01 8.806106e-01 9.458942e-01 5.742574e-0 1 ## AccuracyPValue McnemarPValue ## 1.656736e-40 1.095986e-01 rf1k_cmx$byClass ## Sensitivity Specificity Pos Pred Value ## 0.9379845 0.9022989 0.8768116 ## Neg Pred Value Precision Recall ## 0.9515152 0.8768116 0.9379845 ## F1 Prevalence Detection Rate ## 0.9063670 0.4257426 0.3993399 ## Detection Prevalence Balanced Accuracy ## 0.4554455 0.9201417 M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore... 12 of 14 11/23/2020, 5:44 PM
  • 13. rfgrow<-grow(rf50_model,50) rfgrow_pred<-predict(rfgrow,X[,-c(which(names(X)=="target"))]) rfgrow_mtab<-table(X$target,rfgrow_pred) rfgrow_cmx<-caret::confusionMatrix(rfgrow_mtab) rfgrow_mtab ## rfgrow_pred ## 0 1 ## 0 123 15 ## 1 9 156 (rfgrow_accuracy<-sum(diag(rfgrow_mtab))/sum(rfgrow_mtab)) ## [1] 0.9207921 rfgrow_cmx$overall ## Accuracy Kappa AccuracyLower AccuracyUpper AccuracyNul l ## 9.207921e-01 8.397461e-01 8.844364e-01 9.485923e-01 5.643564e-0 1 ## AccuracyPValue McnemarPValue ## 2.685766e-43 3.074342e-01 rfgrow_cmx$byClass ## Sensitivity Specificity Pos Pred Value ## 0.9318182 0.9122807 0.8913043 ## Neg Pred Value Precision Recall ## 0.9454545 0.8913043 0.9318182 ## F1 Prevalence Detection Rate ## 0.9111111 0.4356436 0.4059406 ## Detection Prevalence Balanced Accuracy ## 0.4554455 0.9220494 M12-RandomForest file:///E:/users/rkannan/cuny/fall2020/fall2020/ML-Handbook/m12-rFore... 13 of 14 11/23/2020, 5:44 PM