it

R-bagging함수 (데이터프레임)

두두100 2021. 5. 15. 13:53

bagging함수는 ipred 패키지안에 있다.

 

?bagging을 하면 bagging의 description이 나오는데,

대부분 파일 형태가 data.frame일 것이므로 데이터프레임에 대해서만 다뤄보도록 하자.

데이터가 어떤 형태인지 알고 싶다면 str()을 해주면 간단하게 나온다.

 

사진의 맨 마지막 줄을 보면, S3 method for class 'data.frame' 의 경우엔

bagging(formula, data, subset, na.action=na.rpart,...) 의 명령어를 이용하라고 나온다.

 

(우리가 주로 다루는 데이터 form들은 주로 S3 class이다. S4는 내가 공부 더하고 추가해야지..😉)

 

이 때 formula란 무엇일까?

a formula of the form lhs~rhs where lhs is the response variable and rhs a set of predictors.

 

response variable=target varaible, predictors=설명변수 이므로

우리가 구하고자 하는 data의 타겟 변수를 y, 설명변수를 x라 할 때

formula는 data$y~data$x가 된다. 그런데 보통 x는 많이 있게 되므로 data$y~. 로 적어주는 게 간편하다.