更多特征变量却未能带来随机森林分类效果的提升
評估RFE變量篩選過程中構建的最終模型的效果
最終擬合的模型可通過rfe$fit獲取,用于后續預測分析。
library(randomForest) rfe$fit## ## Call: ## randomForest(x = x, y = y, importance = TRUE) ## Type of random forest: classification ## Number of trees: 500 ## No. of variables tried at each split: 14 ## ## OOB estimate of error rate: 5.08% ## Confusion matrix: ## DLBCL FL class.error ## DLBCL 43 1 0.02272727 ## FL 2 13 0.13333333但此模型沒有進行調參。雖然用的變量多了,但預測效果沒有比Boruta篩選的特征變量結果好。P-Value [Acc > NIR] : 0.2022不顯著。
# 獲得模型結果評估矩陣(`confusion matrix`)predictions <- predict(rfe$fit, newdata=test_data) confusionMatrix(predictions, test_data_group)## Confusion Matrix and Statistics ## ## Reference ## Prediction DLBCL FL ## DLBCL 14 2 ## FL 0 2 ## ## Accuracy : 0.8889 ## 95% CI : (0.6529, 0.9862) ## No Information Rate : 0.7778 ## P-Value [Acc > NIR] : 0.2022 ## ## Kappa : 0.6087 ## ## Mcnemar's Test P-Value : 0.4795 ## ## Sensitivity : 1.0000 ## Specificity : 0.5000 ## Pos Pred Value : 0.8750 ## Neg Pred Value : 1.0000 ## Prevalence : 0.7778 ## Detection Rate : 0.7778 ## Detection Prevalence : 0.8889 ## Balanced Accuracy : 0.7500 ## ## 'Positive' Class : DLBCL ##基于RFE選擇的特征變量再次調參構建模型
# 提取訓練集的特征變量子集 rfe_train_data <- train_data[, caretRfe_variables$Item] rfe_mtry <- generateTestVariableSet(length(caretRfe_variables$Item))使用 Caret 進行調參和建模
library(caret) # Create model with default parameters trControl <- trainControl(method="repeatedcv", number=10, repeats=5)# train model if(file.exists('rda/rfeVariable_rf_default.rda')){rfeVariable_rf_default <- readRDS("rda/rfeVariable_rf_default.rda") } else {# 設置隨機數種子,使得結果可重復seed <- 1set.seed(seed)# 根據經驗或感覺設置一些待查詢的參數和參數值tuneGrid <- expand.grid(mtry=rfe_mtry)rfeVariable_rf_default <- train(x=rfe_train_data, y=train_data_group, method="rf", tuneGrid = tuneGrid, # metric="Accuracy", #metric='Kappa'trControl=trControl)saveRDS(rfeVariable_rf_default, "rda/rfeVariable_rf_default.rda") } print(rfeVariable_rf_default)## Random Forest ## ## 59 samples ## 216 predictors ## 2 classes: 'DLBCL', 'FL' ## ## No pre-processing ## Resampling: Cross-Validated (10 fold, repeated 5 times) ## Summary of sample sizes: 53, 53, 54, 53, 53, 54, ... ## Resampling results across tuning parameters: ## ## mtry Accuracy Kappa ## 1 0.9802857 0.9459213 ## 2 0.9707619 0.9091146 ## 3 0.9600952 0.8725321 ## 4 0.9554286 0.8405432 ## 5 0.9599048 0.8612016 ## 6 0.9525714 0.8326301 ## 7 0.9572381 0.8642968 ## 8 0.9492381 0.8242968 ## 9 0.9492381 0.8242968 ## 10 0.9492381 0.8242968 ## 16 0.9492381 0.8242968 ## 25 0.9492381 0.8242968 ## 27 0.9463810 0.8160615 ## 36 0.9492381 0.8242968 ## 49 0.9492381 0.8242968 ## 64 0.9425714 0.8042968 ## 81 0.9363810 0.7874901 ## 100 0.9397143 0.7960615 ## 125 0.9311429 0.7713556 ## ## Accuracy was used to select the optimal model using the largest value. ## The final value used for the model was mtry = 1.結果還是不顯著P-Value [Acc > NIR]>0.05。效果弱于Boruta篩選出的特征變量構建的模型。
# 獲得模型結果評估矩陣(`confusion matrix`)predictions <- predict(rfeVariable_rf_default, newdata=test_data) confusionMatrix(predictions, test_data_group)## Confusion Matrix and Statistics ## ## Reference ## Prediction DLBCL FL ## DLBCL 14 2 ## FL 0 2 ## ## Accuracy : 0.8889 ## 95% CI : (0.6529, 0.9862) ## No Information Rate : 0.7778 ## P-Value [Acc > NIR] : 0.2022 ## ## Kappa : 0.6087 ## ## Mcnemar's Test P-Value : 0.4795 ## ## Sensitivity : 1.0000 ## Specificity : 0.5000 ## Pos Pred Value : 0.8750 ## Neg Pred Value : 1.0000 ## Prevalence : 0.7778 ## Detection Rate : 0.7778 ## Detection Prevalence : 0.8889 ## Balanced Accuracy : 0.7500 ## ## 'Positive' Class : DLBCL ##機器學習系列教程
從隨機森林開始,一步步理解決策樹、隨機森林、ROC/AUC、數據集、交叉驗證的概念和實踐。
文字能說清的用文字、圖片能展示的用、描述不清的用公式、公式還不清楚的寫個簡單代碼,一步步理清各個環節和概念。
再到成熟代碼應用、模型調參、模型比較、模型評估,學習整個機器學習需要用到的知識和技能。
機器學習算法 - 隨機森林之決策樹初探(1)
機器學習算法-隨機森林之決策樹R 代碼從頭暴力實現(2)
機器學習算法-隨機森林之決策樹R 代碼從頭暴力實現(3)
機器學習算法-隨機森林之理論概述
隨機森林拖了這么久,終于到實戰了。先分享很多套用于機器學習的多種癌癥表達數據集 https://file.biolab.si/biolab/supp/bi-cancer/projections/。
機器學習算法-隨機森林初探(1)
機器學習 模型評估指標 - ROC曲線和AUC值
機器學習 - 訓練集、驗證集、測試集
機器學習 - 隨機森林手動10 折交叉驗證
一個函數統一238個機器學習R包,這也太贊了吧
基于Caret和RandomForest包進行隨機森林分析的一般步驟 (1)
Caret模型訓練和調參更多參數解讀(2)
機器學習相關書籍分享
基于Caret進行隨機森林隨機調參的4種方式
送你一個在線機器學習網站,真香!
UCI機器學習數據集
機器學習第17篇 - 特征變量篩選(1)
機器學習第18篇 - 基于隨機森林的Boruta特征變量篩選(2)
機器學習系列補充:數據集準備和更正YSX包
機器學習第20篇 - 基于Boruta選擇的特征變量構建隨機森林
?機器學習第21篇 - 特征遞歸消除RFE算法 理論
RFE篩選出的特征變量竟然是Boruta的4倍之多
總結
以上是生活随笔為你收集整理的更多特征变量却未能带来随机森林分类效果的提升的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2020 年诺贝尔生理奖授予丙肝病毒的3
- 下一篇: 单细胞分析Seurat使用相关的10个问