0

我们已经尝试在我们的一个项目中使用 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

4

1 回答 1

0

I can just guess here without a complete code example, but the number of observations must must be larger than the number of variables (which is 125 in your example).

To be more precisely, the n in your code must be larger than 125 for for the regression to work. The number of predictors passed into the regress method can be less than that.

于 2014-06-27T21:29:08.713 回答