# 构建随机森林模型rf_sepc_reg<-rand_forest(mtry =5, trees =500)%>%set_engine("randomForest" , importance =TRUE)%>%set_mode("regression")# 创建配方rf_recipe<-recipe(ZD~., data =train_data)# 工作流程rf_workflow<-workflow()%>%add_recipe(rf_recipe)%>%add_model(rf_sepc_reg)# 训练模型reg_rf_fit<-rf_workflow%>%fit(data =train_data)reg_rf_fit%>%extract_fit_parsnip()#> parsnip model object#> #> #> Call:#> randomForest(x = maybe_data_frame(x), y = y, ntree = ~500, mtry = min_cols(~5, x), importance = ~TRUE) #> Type of random forest: regression#> Number of trees: 500#> No. of variables tried at each split: 5#> #> Mean of squared residuals: 48.45618#> % Var explained: 87.48
1.3.1 特征重要性:基于均方误差(MSE)的减少
这种方法主要用于回归任务。
Mean Decrease in Accuracy (MDA) 这种方法通过衡量某个特征对整体模型预测准确性的贡献来计算其重要性。具体步骤如下: