랜덤 포레스트 모델

R에서의 차원 축소

Matt Pickard

Owner, Pickard Predictives, LLC

랜덤 포레스트

  • 앙상블 모델
    • 군중의 지혜 접근법
  • 많은 랜덤 트리의 예측을 집계
  • 상관없는 트리로 오류 완화
  • 과적합 방지
  • 정확함
  • 특성 선택 수행

여러 결정 트리로 구성된 앙상블 모델과 각 투표가 최종 투표로 결합되는 과정을 보여주는 다이어그램.

R에서의 차원 축소

랜덤 포레스트

서로 다른 특성 하위 집합으로 다양한 서브트리를 생성하는 과정을 보여주는 다이어그램.

R에서의 차원 축소

랜덤 포레스트 학습

library(tidymodels)

rf <- rand_forest(mode = "classification", trees = 200) %>% set_engine("ranger", importance = "impurity")
rf_fit <- rf %>% fit(credit_score ~ ., data = train)
predict_df <- test %>% bind_cols(predict = predict(rf_fit, test))
R에서의 차원 축소

모델 평가

f_meas(predict_df, credit_score, .pred_class)
0.6895
R에서의 차원 축소

변수 중요도

library(vip)

rf_fit %>% vip()

변수 중요도 막대 차트.

R에서의 차원 축소

특성 마스크

top_features <- rf_fit %>% 
  vi(rank = TRUE) %>% 
  filter(Importance <= 10) %>% 
  pull(Variable)

top_features
 [1] "outstanding_debt"        "interest_rate"          
 [3] "delay_from_due_date"     "changed_credit_limit"   
 [5] "credit_history_months"   "num_credit_card"        
 [7] "monthly_balance"         "num_of_delayed_payment" 
 [9] "annual_income"           "amount_invested_monthly"
R에서의 차원 축소

데이터 축소

train_reduced <- train[top_features]
test_reduced <- test[top_features]
R에서의 차원 축소

성능

rf_fit <- rf %>% 
  fit(credit_score ~ ., data = train_reduced) 

predict_reduced_df <- test_reduced %>% bind_cols(predict = predict(rf_fit, test_reduced))
f_meas(predict_reduced_df, credit_score, .pred_class)
0.6738 

축소 전 모델의 F-점수:

0.6895 
R에서의 차원 축소

Ayo berlatih!

R에서의 차원 축소

Preparing Video For Download...