김두두의 블로그

R-adaboost 중 error: Error in `[.data.frame`(data, , as.character(formula[[2]])) 본문

it

R-adaboost 중 error: Error in `[.data.frame`(data, , as.character(formula[[2]]))

두두100 2021. 5. 15. 15:45

adaboost를 사용하기 위해선 C50 패키지와 adabag 패키지가 필요하다.

C50 package: C5.0 decision trees and rule-based models for pattern recognition that extend the work of Quinlan

(출처: https://cran.r-project.org/web/packages/C50/index.html)

실질적으로 adaboost를 하는 건 adabag패키지인 것 같다.

 

하여튼!

library('C50')

library('adabag')

iris.adaboost<-boosting(iris$Species~., data=iris)

 

를 통해서 iris.adaboost 변수에 저장하려고 했는데

 

> iris.adaboost=boosting(iris$Species~.,data=iris)

Error in `[.data.frame`(data, , as.character(formula[[2]])) :

undefined columns selected

이런 오류가 나왔다... bagging할 때는 이런 오류가 안나왔는데.

 

사실 data=iris로 이미 설정해뒀기 때문에 굳이 formula에 data$Species라 적어줄 필요는 없다. (여기서 오류가 발생한다.)

 

iris.adaboost<-boosting(Species~., data=iris)

 

 

따라서 그냥 Species라 적어주는 것 만으로도 문제가 해결된다.

 

 

참고)

boosting function's usage:

 boosting(formula, data, boos = TRUE, mfinal = 100, coeflearn = 'Breiman', 
	control,...)

example:

## rpart library should be loaded
data(iris)
iris.adaboost <- boosting(Species~., data=iris, boos=TRUE, mfinal=3)
iris.adaboost

 

출처: R documation Applies the Adaboost.M1 and SAMME algorighms to a data set

 

 

 

티스토리에 코드블럭이라는게 있다는 걸 지금알았다니..심지어 R도 지원이 된다. 앞으로 자주 애용해야지~~~

 

 

 

'it' 카테고리의 다른 글

[python] 백준 2562번- 배열과 최댓값  (0) 2022.03.03
R-What is boosting.cv?  (0) 2021.05.15
R-bagging함수 (데이터프레임)  (0) 2021.05.15
HTML-sublime text 설치하고 간단히 만들어보기  (0) 2021.05.15
파이썬-list안의 list  (0) 2021.05.12