我们已经尝试在我们的一个项目中使用 MillerUpdatingRegression 类并遇到了问题。在创建类的实例、提供期望的变量数量并从整个样本集中添加观察值后,我们调用“regress(int[])”方法,通知回归过程我们希望包含哪些变量(整个预测器集的子集)。
当我们这样做时,我们会在该过程中收到一个 ArrayIndexOutOfBounds 异常,因为预期的变量数(nvars,在 MillerUpdatingRegression 类被实例化时提供)小于传递给“regress(int[])”方法的变量数. 我们的理解是,这个整数数组可以是所有观察结果的预测指标的子集。
有谁知道我们在这里缺少什么?
==== 已更新代码 ====
double predictorData[][] = new double[n][125];
double predictions[] = new double[n];
//predictorData is a [n x 125] two-dimensional array of
//features/predictors with n samples and 125 predictors
//predictionsArray is a n-length array of predictions
//for the sample set
int numberOfPredictorVariables = 125;
boolean includeConstantWhenBuildingModel = true;
MillerUpdatingRegression regression = new MillerUpdatingRegression(numberOfPredictorVariables,includeConstantWhenBuildingModel);
regression.addObservations(predictorData,predictionsArray)
int predictorsToIncludeInRegression[] = {0,3,9,11};
regression.regress(predictorsToIncludeInRegression);
//this is where the ArrayIndexOutOfBounds exception is generated