python - 如何计算 RandomForestRegression 中的 MSE 标准?

标签 python random-forest mse

我现在使用 sklearn.ensemble 中的 RandomForestRegressor 来分析数据集,并选择“mse”作为衡量分割质量的函数。但我不太清楚mse是如何计算的。有人可以在这里向我解释一下(用方程更好)或者为我提供一些引用吗?预先感谢您。

最佳答案

简短回答:

Mean Squared Error (MSE) is calculated by squaring all of the errors (to make them positive) and then taking the mean value of those squares. It is a single value; "for each tree, we get a difference between two MSE values. Averaging over trees gives the mean difference between the two MSE values". ref

... However, the Random Forest calculates the MSE using the predictions obtained from evaluating the same data. Train in every tree but only considering the data is not taken from bootstrapping to construct the tree, wether the data that it is in the OOB (OUT-OF-BAG). Then it averages the predictions for all the OOB predictions for each sample of data. ... ref

MSE,度量是成本函数方法之一。考虑您的模型绿线如下图所示,那些蓝点是数据(观察值)。顾名思义,MSE 是所有数据点相对于一条线的平方面积的平均总和,总而言之代表您的模型误差

img

MSE 可以通过以下方式计算:

img

It shows how good or bad the model is. The smaller MSE, the better model!

更多信息:

Understanding Regression Error Metrics in Python

Introduction to Loss Functions

更新 30.05.2019 要验证内容,您可以根据其文档 RandomForestRegressor() 深入研究文档,有时也可以深入研究代码。 ,MSE 只不过是作为特征选择标准的方差减少,即使您检查源代码,它也用于测量分割质量。另一方面,如果您对 RandomForestRegressor() 中的 MSE 方法有疑问,您可以通过自定义 criterion 来独立使用它,如下所示:

from sklearn.metrics import mean_squared_error
from sklearn.ensemble import RandomForestRegressor
#Feature Selection
criterion = mean_squared_error(y, predictions)
RandomForestRegressor( ...,criterion= criterion,...)

或使用 :

import numpy as np
criterion = np.mean((y_test - est.predict(X_test))**2)

更多 info

关于python - 如何计算 RandomForestRegression 中的 MSE 标准?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56369519/

相关文章:

python - 使用 R-Squared 评估随机森林性能

r - R 中的 cv.glmnet 是否为二进制数据返回双 MSE?

Python 日志记录 : use milliseconds in time format

python - 将单个字符与它们之间的单个空格组合在一起

r - 在 randomForest 包中绘制 500 棵树中的一棵

r - 如何在 R 中对 SpatialPointsDataFrame 进行子采样

Python计算每一行的MSE

Pytorch,无法获得 <class 'torch.Tensor' > 的 repr

python - 如何跳出只有一个嵌套循环

python - 打印组合问题