# randomForest 와 ranger 속도 차이 비교 # randomForest 의 가장 큰 약점 중 하나 인 모델 생성 속도 문제 에 대한 대책 으로 ranger 테스트 # ranger : : a fast implementation of Random Forest ( Breiman 2001 ) or recursive partitioning , particularly suited for high dimensional databnk 05 <- read . csv ( ' https : / / t 1 . daumcdn . net / cfile / blog / 99 E 6173359 C 44 CE 507 ? download ') bnk 06 <- rbind ( bnk 05 , bnk 05 ) bnk 06 <- rbind ( bnk 06 , bnk 06 ) # replicate databnk 06 <- rbind ( bnk 06 , bnk 06 ) bnk 06 <- rbind ( bnk 06 , bnk 06 ) nrow ( bnk 06 ) require ( ranger ) require ( randomForest ) start . time <- Sys . time ( ) rng 1 <- ranger ( y ~ . , data = bnk 06 , num . trees = 1000 , importance =" impurity ") end . time <- Sys . time ( ) ranger . learningtime <- end . time - start . time # sort ( rng 1 $ variable . importance , decreasing = T ) start . time <- Sys . time ( ) rf 1 <- randomForest ( y ~ . , data = bnk 06 , ntree = 1000 , importance = T ) end . time <- Sys . time ( ) rf . learningtime <- end . time - start . timebarplot ( c ( as . numeric ( ranger . learningtime ) , as . numeric ( rf . learningtime ) * 60 ) , names . arg = c ( " ranger ", " rf "), main =" learning time " ) c ( ( ranger . learningtime ) , ( rf . learningtime ) ) start . time <- Sys . time ( ) for ( i in 1 : 50 ) { pr <- predict ( rng 1 , newdata = bnk 06 ) print ( i ) } end . time <- Sys . time ( ) ranger . predtime <- end . time - start . timestart . time <- Sys . time ( ) for ( i in 1 : 50 ) { pr <- predict ( rf 1 , newdata = bnk 06 ) print ( i ) } end . time <- Sys . time ( ) rf . predtime <- end . time - start . timebarplot ( c ( as . numeric ( ranger . predtime ) , as . numeric ( rf . predtime ) ) , names . arg = c ( " ranger ", " rf "), main =" prediction time " ) c ( ( ranger . predtime ) , ( rf . predtime ) ) ranger . learningtime <- round ( as . numeric ( ranger . learningtime , units =" secs "), 2 ) rf . learningtime <- round ( as . numeric ( rf . learningtime , units =" secs "), 2 ) ranger . predtime <- round ( as . numeric ( ranger . predtime , units =" secs "), 2 ) rf . predtime <- round ( as . numeric ( rf . predtime , units =" secs "), 2 ) par ( mfrow = c ( 1 , 2 ) ) barplot ( c ( as . numeric ( ranger . learningtime ) , as . numeric ( rf . learningtime ) ) , names . arg = c ( " ranger ", " rf "), main =" learning time ( 8 . 69 K rows X 23 vars ) " ) barplot ( c ( as . numeric ( ranger . predtime ) , as . numeric ( rf . predtime ) ) , names . arg = c ( " ranger ", " rf "), main =" prediction time ( 4 . 34 M rows X 23 vars ) " ) par ( mfrow = c ( 1 , 1 ) ) # comparison of times ( unit : seconds ) paste ( " ranger . learningtime : " , ranger . learningtime ) paste ( " rf . learningtime : " , rf . learningtime ) paste ( " ranger . predtime : " , ranger . predtime ) paste ( " rf . predtime : " , rf . predtime ) # " ranger . learningtime : 24 . 3938548564911 "# " rf . learningtime : 304 . 569322109222 "# " ranger . predtime : 0 . 177471876144409 "# " rf . predtime : 177 . 684410095215 "# rf . predtime / ranger . predtime == 1001 . 198 # 모델 빌딩 에서 10 배 이상 , prediction 에서 도 1000 배 가량 ranger 가 빠름 #