You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R语言绘图:test_mse曲线无法显示且无报错问题咨询

Troubleshooting Test MSE Not Showing in Plot

Here are practical fixes for your issue where test_mse doesn’t appear on the plot despite no error messages:

  • Verify vector length consistency
    Ensure length(test_mse) equals p=10. If the vector is shorter or longer, the points won’t align with the x-axis range 1:p and may fail to render. Run this check:

    length(test_mse) == p
    
  • Adjust y-axis range to include test_mse values
    The initial plot() call sets the y-axis bounds based on train_mse values. If test_mse is significantly higher or lower, it’ll be plotted outside the visible area. Update your code to explicitly set a y-axis range that covers both datasets:

    # Calculate combined range of both MSE vectors
    mse_range <- range(c(train_mse, test_mse))
    
    plot(1:p, train_mse, type = "b", pch = 19, col = "blue", 
         xlab = "Number of Components (M)", ylab = "Mean Squared Error (MSE)",
         main = "PCR: Training and Test MSEs vs. Number of Components",
         ylim = mse_range)
    
    points(1:p, test_mse, type = "b", pch = 19, col = "red")
    legend("topright", legend = c("Training MSE", "Test MSE"), col = c("blue", "red"), pch = 19, cex = 0.8)
    
  • Check for missing values
    If test_mse contains NA values, those points won’t render. Confirm with:

    any(is.na(test_mse))
    

    If the result is TRUE, handle the missing values (e.g., remove or impute them) before plotting.

  • Isolate the issue with simplified code
    To rule out conflicts with the initial plot, try plotting test_mse alone first:

    plot(1:p, test_mse, type="b", col="red")
    

    If this works, the problem was almost certainly the y-axis range in your original plot.

内容的提问来源于stack exchange,提问作者khali-blinks

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 17:50:05