一、定义
校正决定系数(Adjusted R-squared)是经过修正的决定系数(R-squared),它是用于解释因变量(dependent variable)的变异量的模型拟合程度的统计量。
在统计模型中,校正决定系数表示的是因变量中可被解释部分所占总方差的百分比,即拟合优度。数值越接近1,说明模型越拟合数据。
二、计算方法
假设变量个数为p,样本数量为n,y表示因变量,y_hat表示回归值,y_bar表示y的平均值。
校正决定系数的计算方法如下:
SS_res = sum((y - y_hat)^2) # sum of squared residuals SS_tot = sum((y - y_bar)^2) # total sum of squares n = number of samples p = number of predictors R_squared = 1 - (SS_res / SS_tot) Adjusted_R_squared = 1 - (1 - R_squared) * (n - 1) / (n - p - 1)
三、优点
校正决定系数比简单的决定系数更加准确地评估模型的拟合度,因为它考虑了模型所使用的变量数量和样本数量的影响。
校正决定系数还可以用来比较不同模型的预测能力。在比较时,应该选择具有更高校正决定系数的模型。
四、局限性
校正决定系数存在一些局限性,如:
1. 可能会过度拟合,因为校正决定系数值只会增加或不变,即使加入的变量对模型没有贡献。
2. 只适用于线性回归模型。
五、应用实例
下面是一个使用python中的scikit-learn库进行线性回归分析的实例:
from sklearn.linear_model import LinearRegression from sklearn.metrics import r2_score # Load dataset X = [[1, 2], [2, 4], [3, 6], [4, 8]] y = [2, 4, 6, 8] # Fit the model model = LinearRegression().fit(X, y) # Make predictions y_pred = model.predict(X) # Compute R-squared and adjusted R-squared r2 = r2_score(y, y_pred) adj_r2 = 1 - (1 - r2) * (len(y) - 1) / (len(y) - len(X[0]) - 1) print("R-squared:", r2) print("Adjusted R-squared:", adj_r2)
原创文章,作者:EGGMG,如若转载,请注明出处:https://www.506064.com/n/372928.html