R中预测的预处理比例 - 预测

时间:2016-11-02 18:26:16

标签: r machine-learning neural-network r-caret

我正在使用插入符号包中的train函数训练R中的神经网络。我正在使用一些示例代码:Time-series - data spliting and model evaluation

网络训练的输出告诉我它已被重新缩放到[0,1]但是当我使用预测函数时,我的预测没有缩放到[0,1]。首先,我如何知道数据是否已正确标准化?第二,如何获得标准化预测?

这是我的代码:

timeSlices <- createTimeSlices(1:nrow(mytsframe3), initialWindow = 36,
                           horizon = 12, fixedWindow = TRUE)

nn <- train(diffREALBRENTSPOT ~ diffF1REALlag + diffF2REALlag, data = mytsframe3[trainSlices[[1]],], method = "mlp"
        , size = 1, preProc = c("range"))

> nn
Multi-Layer Perceptron 

36 samples
 2 predictor

Pre-processing: re-scaling to [0, 1] (2) 
Resampling: Bootstrapped (25 reps) 
Summary of sample sizes: 36, 36, 36, 36, 36, 36, ... 
Resampling results across tuning parameters:

  size  RMSE       Rsquared 
  1     0.7879697  0.2098693
  3     0.7485212  0.2249331
  5     0.7571630  0.2246444

RMSE was used to select the optimal model using  the smallest value.
The final value used for the model was size = 3. 

pred <- predict(nn, mytsframe3[testSlices[[1]],])

str(pred)
 Named num [1:12] 0.0734 -0.0214 0.3264 0.0362 -0.1569 ...
 - attr(*, "names")= chr [1:12] "37" "38" "39" "40" ...

以下是我测试数据的dput

structure(list(diffREALBRENTSPOT = c(-0.523999999999999, -0.693, 
0.386999999999999, 0.453000000000001, -0.842000000000001, 0.369999999999999
), diffF1REALlag = c(0.48597655, -1.61485375, 0.60622805, -0.469351210000001, 
0.292303670000001, -0.44088176), diffF2REALlag = c(1.00948236, 
0.48597655, -1.61485375, 0.60622805, -0.469351210000001, 0.292303670000001
)), .Names = c("diffREALBRENTSPOT", "diffF1REALlag", "diffF2REALlag"
), row.names = c(NA, 6L), class = "data.frame")

1 个答案:

答案 0 :(得分:2)

  

网络训练的输出告诉我它已被重新缩放到[0,1]但是当我使用预测函数时,我的预测没有缩放到[0,1]。

结果是数字,您拟合回归模型(不是分类)。 preProc选项会将预测变量重新调整为[0,1],并且不会将结果或预测重新调整为此范围。