交叉验证警告中的predict.lm:等级不足拟合的预测可能会误导

如何解决交叉验证警告中的predict.lm:等级不足拟合的预测可能会误导

我试图通过交叉验证使线性回归拟合,并总是得到错误:

In predict.lm(modelFit,newdata) :
  prediction from a rank-deficient fit may be misleading

首先:我的数据对35个变量进行了3970次观察。

我从拟合正常的线性模型开始,选择所有重要变量,然后预测模型。第一次出现错误。

我在这里找到了一些帖子,可以帮助我解决问题。 ({predict.lm() in a loop. warning: prediction from a rank-deficient fit may be misleading等)

两个变量,其中NA由于多重共线性。因此,我最终得到了一个具有7个独立变量的模型。

model <- lm(Y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7,data = LinearRegression)

其中x1和x5是具有71和5个因子的因子变量。 现在,我尝试测试模型通过交叉验证进行预测的能力

train.control <- trainControl(method = "cv",number = 10)
model_cv <- train(Y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7,data = LinearRegression,method = "lm",trControl = train.control)

然后我再次遇到错误,但是这次没有NA变量:

Call:
lm(Y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7,data = LinearRegression)

Residuals:
     Min       1Q   Median       3Q      Max 
-1.89215 -0.10896  0.02253  0.16437  1.62254 

Coefficients:
                       Estimate Std. Error t value Pr(>|t|)    
(Intercept)           6.8523833  0.4169588  16.434  < 2e-16 ***
x1_1             1.2046199  0.1341414   8.980  < 2e-16 ***
x1_2             0.8552971  0.1301020   6.574 5.58e-11 ***
x1_3             0.1951379  0.1586862   1.230 0.218884    
x1_4             1.0624589  0.1740145   6.106 1.13e-09 ***
x1_5             0.5189317  0.1590199   3.263 0.001111 ** 
x1_6             0.8474964  0.1486093   5.703 1.27e-08 ***
x1_7             -0.1415639  0.3224469  -0.439 0.660665    
x1_8             0.3960358  0.2340968   1.692 0.090776 .  
x1_9             0.7835493  0.1974889   3.968 7.40e-05 ***
x1_10            1.0919681  0.3238588   3.372 0.000755 ***
x1_11            1.1007771  0.1486148   7.407 1.59e-13 ***
x1_12            1.0938503  0.1023097  10.692  < 2e-16 ***
x1_13            1.1706621  0.1050607  11.143  < 2e-16 ***
x1_14            1.0061459  0.0942957  10.670  < 2e-16 ***
x1_15            0.7766680  0.1030926   7.534 6.16e-14 ***
x1_16            0.9417975  0.0865752  10.878  < 2e-16 ***
x1_17            1.2219212  0.1284831   9.510  < 2e-16 ***
x1_18            1.0498229  0.1213626   8.650  < 2e-16 ***
x1_19            1.1748814  0.1970319   5.963 2.71e-09 ***
x1_20            1.1845137  0.1960433   6.042 1.67e-09 ***
x1_21            0.3241002  0.1737104   1.866 0.062155 .  
x1_22            0.9336938  0.1957600   4.770 1.92e-06 ***
x1_23            1.2658970  0.1480022   8.553  < 2e-16 ***
x1_24            1.2567544  0.1065799  11.792  < 2e-16 ***
x1_25            0.8952060  0.0995382   8.994  < 2e-16 ***
x1_26            0.9703442  0.0968485  10.019  < 2e-16 ***
x1_27            0.8016274  0.1169069   6.857 8.20e-12 ***
x1_28            0.8449424  0.0861911   9.803  < 2e-16 ***
x1_29            0.9099589  0.0938174   9.699  < 2e-16 ***
x1_30            0.9530838  0.0916536  10.399  < 2e-16 ***
x1_31            0.8253420  0.1037119   7.958 2.30e-15 ***
x1_32            0.7729572  0.0863763   8.949  < 2e-16 ***
x1_33            0.8835926  0.0893175   9.893  < 2e-16 ***
x1_34            0.9115718  0.0865318  10.535  < 2e-16 ***
x1_35            0.9465358  0.0947191   9.993  < 2e-16 ***
x1_36            1.0026752  0.0917101  10.933  < 2e-16 ***
x1_37            1.0011434  0.0995831  10.053  < 2e-16 ***
x1_38            0.9982454  0.0960763  10.390  < 2e-16 ***
x1_39            1.0441242  0.0864358  12.080  < 2e-16 ***
x1_40            1.0176823  0.1132735   8.984  < 2e-16 ***
x1_41            1.0521302  0.0973221  10.811  < 2e-16 ***
x1_42            1.1895632  0.1597196   7.448 1.17e-13 ***
x1_43            1.1387535  0.1342213   8.484  < 2e-16 ***
x1_44            1.0821231  0.0878177  12.322  < 2e-16 ***
x1_45            1.1849959  0.0904991  13.094  < 2e-16 ***
x1_46            1.0049849  0.0991381  10.137  < 2e-16 ***
x1_47            1.1085438  0.1089135  10.178  < 2e-16 ***
x1_48            0.9449635  0.1001778   9.433  < 2e-16 ***
x1_49            1.1420746  0.1002712  11.390  < 2e-16 ***
x1_50            1.2042756  0.1004974  11.983  < 2e-16 ***
x1_51            0.9300386  0.1125598   8.263  < 2e-16 ***
x1_52            0.9324567  0.1143565   8.154 4.77e-16 ***
x1_53            1.1307837  0.1602068   7.058 2.00e-12 ***
x1_54            1.2180581  0.0871246  13.981  < 2e-16 ***
x1_55            0.9263829  0.0953577   9.715  < 2e-16 ***
x1_56            0.8827701  0.0824590  10.706  < 2e-16 ***
x1_57            0.6132403  0.1749772   3.505 0.000463 ***
x1_58            1.2387870  0.1171063  10.578  < 2e-16 ***
x1_59            0.9820014  0.1110539   8.843  < 2e-16 ***
x1_60            0.8840286  0.1015922   8.702  < 2e-16 ***
x1_61            1.0732949  0.1165657   9.208  < 2e-16 ***
x1_62            1.4754395  0.2349496   6.280 3.78e-10 ***
x1_63            0.8204402  0.0833158   9.847  < 2e-16 ***
x1_64            0.7751165  0.0812332   9.542  < 2e-16 ***
x1_65            0.8125287  0.0791297  10.268  < 2e-16 ***
x1_66            0.8607391  0.0816216  10.545  < 2e-16 ***
x1_67            0.9527723  0.0835425  11.405  < 2e-16 ***
x1_68            0.9082450  0.0943007   9.631  < 2e-16 ***
x1_69            1.1974770  0.0940538  12.732  < 2e-16 ***
x1_70            1.1811407  0.0973556  12.132  < 2e-16 ***
x1_71            1.0786986  0.0962506  11.207  < 2e-16 ***
x1_72            1.3146796  0.1251169  10.508  < 2e-16 ***
x2                    1.0105636  0.0166753  60.602  < 2e-16 ***
x3                    0.0004937  0.0002070   2.385 0.017147 *  
x3                    -0.0580034  0.0113374  -5.116 3.28e-07 ***
x4                    -0.0394516  0.0105203  -3.750 0.000179 ***
x5_1                  0.0524032  0.0176849   2.963 0.003064 ** 
x5_1                  0.1347279  0.0190404   7.076 1.77e-12 ***
x5_1                  0.1957828  0.0184072  10.636  < 2e-16 ***
x5_1                  0.2847831  0.0187699  15.172  < 2e-16 ***
x5_1                  0.3166791  0.0180418  17.553  < 2e-16 ***
x6                    -0.0296464  0.0173061  -1.713 0.086786 .  
x7                    -0.0374209  0.0109163  -3.428 0.000615 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.3132 on 3709 degrees of freedom
Multiple R-squared:  0.6094,Adjusted R-squared:  0.6006 
F-statistic: 69.72 on 83 and 3709 DF,p-value: < 2.2e-16

(模型的好坏并不重要,以后会使用更好的方法)

当我对整个数据集使用常规预测功能时,一切都很好

model_pred <- predict(model,LinearRegression)

因此,我查看了数据并试图找出问题的根源,并发现当我在交叉验证中使用变量'x1'时,即使仅使用它,它总是会发生:

train.control <- trainControl(method = "cv",number = 10)
model1cv <- train(Y ~ x1,trControl = train.control)

和错误

Warning messages:
1: In predict.lm(modelFit,newdata) :
  prediction from a rank-deficient fit may be misleading
2: In predict.lm(modelFit,newdata) :
  prediction from a rank-deficient fit may be misleading
``

does anyone know how to solve this problem? 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-