gpt4 book ai didi

spss - 如何在SPSS中进行留一法交叉验证

转载 作者:行者123 更新时间:2023-12-01 06:07:24 29 4
gpt4 key购买 nike

我无法理解如何在 SPSS 中执行 LOOCV。我需要评估一个简单的线性回归$Y=aX+b$。谢谢。

最佳答案

对于线性回归,它是 pretty easy ,SPSS 允许您在 REGRESSION 命令中保存统计数据。参见 here for another example

REGRESSION
/NOORIGIN
/DEPENDENT Y
/METHOD=ENTER X
/SAVE PRED (PredAll) DFIT (CVFit).

然后留一法预测可以计算为 COMPUTE LeaveOneOut = PredAll - CVFit。但是对于非线性模型,SPSS 没有提供方便的 SAVE 值可以构建包含缺失值的重复数据集,然后使用SPLIT FILE,然后根据您想要的任何统计过程获取留一统计。如果您的 id 变量只是数据集的行号,您只需要两个最大案例数的循环,然后将所需的信息匹配到新文件中。

这是此过程的示例。

*Making some fake data to work with.
INPUT PROGRAM.
LOOP Id = 1 TO 10.
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
DATASET NAME Sim.
COMPUTE X = RV.NORMAL(10,5).
COMPUTE Y = 3 + 0.2*(X) + RV.NORMAL(0,0.2).
FORMATS Id (F2.0) X Y (F4.2).
EXECUTE.

*Original regression model with the leave one.
*out fits.
REGRESSION
/NOORIGIN
/DEPENDENT Y
/METHOD=ENTER X
/SAVE PRED (PredAll) DFIT (CVFit).

*Manual way to create stacked dataset
*can use with other non-linear models.
INPUT PROGRAM.
COMPUTE #Cases = 10.
LOOP #Id = 1 TO #Cases.
LOOP #Iter = 1 TO #Cases.
COMPUTE L1O = #Iter.
COMPUTE Id = #Id.
END CASE.
END LOOP.
END LOOP.
END FILE.
END INPUT PROGRAM.
DATASET NAME LeaveOneOut.

*Merging in original data.
MATCH FILES FILE = *
/TABLE = 'Sim'
/BY Id.

*Set missing to
IF L1O = Id Y = $SYSMIS.
SORT CASES BY L1O.
SPLIT FILE BY L1O.
*You can replace regression with whatever procedure you are.
*interested in.
REGRESSION
/NOORIGIN
/DEPENDENT Y
/METHOD=ENTER X
/SAVE PRED (CVFit2).
SPLIT FILE OFF.

*This shows the original leave one out stats.
*And new stats are the same besides some floating.
*point differences.
COMPUTE Test = (CVFit2 - (PredAll-CVFit)).
TEMPORARY.
SELECT IF (L1O = Id).
FREQ VAR Test.
EXECUTE.

关于spss - 如何在SPSS中进行留一法交叉验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24216574/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com