"RandomForest" (机器学习方法)
详细信息与子选项
- 随机森林是通过构建大量决策树来进行分类和回归的综合学习方法。通过采用最常见的类或均值树预测来获得森林预测. 每个决策树在训练集的随机子集上训练,并且只使用特征的随机子集(自展输入引导式聚合算法).
- 可以给出下列选项:
-
"DistributionSmoothing" 0.5 正则化参数 "FeatureFraction" Automatic 用来训练每棵树的、随机选择的特征的一部分 "LeafSize" Automatic 每个叶子上的最大实例数量 "TreeNumber" Automatic 森林里树的数量 - "FeatureFraction"、"LeafSize" 和 "DistributionSmoothing" 可用来控制过拟合.
范例
打开所有单元 关闭所有单元基本范例 (3)
p = Predict[{1, 2, 3, 4} -> {.3, .4, .6, 9}, Method -> "RandomForest"]Information[p]p[1.3]trainingset = {1 -> "A", 2 -> "A", 3.5 -> "B", 4 -> "B", 5 -> "A", 5.5 -> "A"};c = Classify[trainingset, Method -> "RandomForest"]绘制一个实例作为特征的函数,类别是 "A" 或 "B" 的概率,并进行比较:
Grid[{{Plot[c[x, "Probability" -> "A"], {x, 0, 5}, Exclusions -> None], Plot[c[x, "Probability" -> "B"], {x, 0, 5}, Exclusions -> None]}}, Frame -> All]data = {-2.2 -> -0.5, 2.2 -> 0.7, -2.8 -> -0.7, 1. -> 0.60, -0.34 -> -0.4, 3.7 -> -0.6, -0.63 -> -0.8, -3.33 -> 0.1, 0.4 -> 0.4, 2.1 -> 0.8};p = Predict[data, Method -> "RandomForest"]Show[Plot[{p[x],
p[x] + StandardDeviation[p[x, "Distribution"]], p[x] - StandardDeviation[p[x, "Distribution"]]},
{x, -2, 6},
PlotStyle -> {Blue, Gray, Gray},
Filling -> {2 -> {3}},
Exclusions -> False,
PerformanceGoal -> "Speed", PlotLegends -> {"Prediction", "Confidence Interval"}], ListPlot[List@@@data, PlotStyle -> Red, PlotLegends -> {"Data"}]]选项 (6)
"DistributionSmoothing" (2)
用 "DistributionSmoothing" 子选项训练一个分类器:
Classify[{-2.2 -> 1, 2.2 -> 1, -2.8 -> 2, 1. -> 2, -0.34 -> 3, 3.7 -> 4, -0.63 -> 4}, Method -> {"RandomForest", "DistributionSmoothing" -> 6}]用 "Titanic" 训练集训练 "DistributionSmoothing" 为缺省值的分类器:
data = ExampleData[{"MachineLearning", "Titanic"}, "TrainingData"];classifier = Classify[data, Method -> "RandomForest"];增大 "DistributionSmoothing" 的值,训练第二个分类器:
smoothed = Classify[data, Method -> {"RandomForest", "DistributionSmoothing" -> 60}]testdata = ExampleData[{"MachineLearning", "Titanic"}, "TestData"];sample = RandomSample[testdata, 4];
Dataset@<|"AutomaticClassifier" ->
classifier[sample[[All, 1]], "Probabilities"],
"SmoothedClassifier" -> smoothed[sample[[All, 1]], "Probabilities"]|>"FeatureFraction" (2)
用 "FeatureFraction" 子选项在高维数据上训练一个预测器:
Predict[RandomReal[1, {200, 200}] -> RandomReal[1, 200], Method -> {"RandomForest", "FeatureFraction" -> .3}]在 "RandomForest" 方法中,平衡的 "FeatureFraction" 可以避免过拟合.
用 "Titanic" 训练集训练 "FeatureFraction" 值不同的两个分类器:
data = ExampleData[{"MachineLearning", "Titanic"}, "TrainingData"];c1 = Classify[data, Method -> {"RandomForest", "FeatureFraction" -> 1}];c2 = Classify[data, Method -> {"RandomForest", "FeatureFraction" -> .6}]testdata = ExampleData[{"MachineLearning", "Titanic"}, "TestData"];Dataset@<|"c1" -> AssociationThread[{"TrainingSet", "TestSet"}, ClassifierMeasurements[c1, #, "Accuracy"]& /@ {data, testdata}] ,
"c2" -> AssociationThread[{"TrainingSet", "TestSet"}, ClassifierMeasurements[c2, #, "Accuracy"]& /@ {data, testdata}]|>"LeafSize" (1)
用 "Titanic" 训练集训练 "LeafSize" 值不同的两个分类器:
data = ExampleData[{"MachineLearning", "Titanic"}, "TrainingData"];{c1, c2} = Classify[data, Method -> {"RandomForest", "LeafSize" -> #}]& /@ {1, 500};ByteCount[#[[1, "Model", "Trees"]]]& /@ {c1, c2}"TreeNumber" (1)
用 "Mushroom" 训练集训练两个 "TreeNumber" 值不同的分类器:
data = ExampleData[{"MachineLearning", "Mushroom"}, "TrainingData"];{c1, c2} = Classify[data, Method -> {"RandomForest", "TreeNumber" -> #}]& /@ {3, 30};Information[#, "TrainingTime"]& /@ {c1, c2}