adjusted r2
时间: 2023-09-28 22:04:40 浏览: 230
Adjusted R-squared is a modified version of the R-squared statistic that adjusts for the number of predictor variables in a regression model. It is a measure of how well a set of predictor variables explain the variability in the response variable, and takes into account the bias that can occur when using R-squared to evaluate the fit of a model with multiple predictors. The adjusted R-squared ranges from 0 to 1, with values closer to 1 indicating a better fit of the model to the data.
相关问题
tensorflow 计算R2/Adjust-R2
在 TensorFlow 中,可以使用以下代码计算 R2 和 Adjusted R2:
```python
import tensorflow as tf
def r_squared(y_true, y_pred):
residual = tf.reduce_sum(tf.square(tf.subtract(y_true, y_pred)))
total = tf.reduce_sum(tf.square(tf.subtract(y_true, tf.reduce_mean(y_true))))
r2_score = tf.subtract(1.0, tf.divide(residual, total))
return r2_score
def adj_r_squared(y_true, y_pred, n, k):
r2 = r_squared(y_true, y_pred)
adj_r2 = 1 - ((1 - r2) * tf.cast(n - 1, "float32")) / tf.cast(n - k - 1, "float32")
return adj_r2
```
其中,y_true 是真实值,y_pred 是预测值,n 是样本数,k 是特征数。使用这两个函数可以分别计算 R2 和 Adjusted R2。
R2、RMSE、MAE、MBE的范围解析
R2(决定系数)的范围是0到1,越接近1表示模型对数据的拟合效果越好。R2等于1表示模型完美拟合数据,R2等于0表示模型无法解释目标变量的变异性。
RMSE(均方根误差)的范围与目标变量的单位相同。它是MSE(均方误差)的平方根,用于衡量预测值与真实值之间的平均差异。RMSE越小表示模型的预测精度越高。
MAE(平均绝对误差)的范围与目标变量的单位相同。它是预测值与真实值之间绝对差的平均值,用于衡量预测值与真实值之间的平均差异。MAE越小表示模型的预测精度越高。
MBE(平均偏差误差)的范围与目标变量的单位相同。它是预测值与真实值之间的平均差异,用于衡量预测值与真实值之间的平均偏差。MBE等于0表示预测值与真实值的平均偏差为0,正值表示预测值偏高,负值表示预测值偏低。
综上所述,R2的范围是0到1,RMSE、MAE和MBE的范围与目标变量的单位相同。
#### 引用[.reference_title]
- *1* [回归评价指标:MSE、RMSE、MAE、R2、Adjusted R2](https://blog.csdn.net/zhao2chen3/article/details/115345787)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [回归评价指标:MSE、RMSE、MAE、MAPE、R2公式理解及代码实现](https://blog.csdn.net/weixin_40651515/article/details/105930868)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文