簡體   English   中英

為什么我不斷得到無效的R平方

[英]Why I keep getting invalid R-squared

我嘗試使用計算R平方的公式,但是它們都給了我無效的R平方,無論是負數還是大於1。

我正在嘗試使用R平方來評估我的模型擬合度。 從而根據預測值和實際值進行計算。

這是我的實際數據:

lasso_pred <- c(13.61946, 13.91595, 13.55052, 13.68006, 13.85825, 13.61735, 13.51712, 13.49727, 13.53181, 13.02560, 13.68658, 13.75073, 13.81856, 13.37798, 13.82558, 13.86672, 13.30965, 13.85373, 13.89834, 13.61562, 13.86353, 13.99774, 13.64185, 13.85063, 13.89282, 13.95036)

actual <- c(13.88986, 14.01917, 14.08782, 13.79533, 14.21647 ,14.18666, 13.84793, 14.02716 ,13.72207, 13.31198 ,13.99843,13.68277 ,13.81584, 13.81574, 14.24260 ,13.75368 ,13.71866 ,13.69617, 14.10187, 13.48185, 14.19855, 13.32519,13.61845, 13.81680, 13.94318, 14.09442)

   SSE <- sum((lasso_pred - actual)^2) #sum of squares residual
   SST <- sum((actual - mean(actual))^2)  #total sum of squares

   r2 <- 1-SSE/SST
   SSR <- sum((lasso_pred- mean(actual))^2)  #sum of squares regression
   SST <- sum((actual - mean(actual))^2)  #total sum of squares

   r2 <- SSR/SST

計算得出的R平方不在0到1的范圍內。

通常,R ^ 2不是負數,但是可能仍然是預測值比簡單均值差的時期。 閱讀更多

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM