matlab中feval和predict之间的差异

时间:2016-03-05 09:40:40

标签: matlab regression linear-regression

我正在尝试在Matlab中学习线性回归模型。所以我的变量是:train_fvtrain_fv_labelstest_fvtest_fv_labels。变量的大小如下:333x9333x1167x9167x1。我想训练模型,然后预测test_fv上的标签将它们与test_fv_labels中给出的实际标签进行比较。

我的matlab代码如下:我使用逐步线性回归进行建模以获得最佳拟合:

mdl = stepwiselm(train_fv,train_fv_labels,'PEnter',0.001,'verbose',1)

mdl1 = step(mdl,'upper','quadratic','verbose',1)

我得到的输出如下

1. Adding x5, FStat = 83.3108, pValue = 7.06324e-18
2. Adding x1, FStat = 35.6014, pValue = 6.24096e-09
3. Adding x7, FStat = 41.0932, pValue = 5.0338e-10
4. Adding x5:x7, FStat = 33.3157, pValue = 1.81571e-08
5. Adding x1:x5, FStat = 14.1821, pValue = 0.000196729

mdl = 


Linear regression model:
    y ~ 1 + x1*x5 + x5*x7

Estimated Coefficients:
                    Estimate         SE         tStat       pValue  
                   __________    __________    _______    __________

    (Intercept)     0.0014532    5.5229e-05     26.312    9.9458e-83
    x1             0.00071972    0.00011402     6.3121    8.9595e-10
    x5             -0.0021179    0.00018102      -11.7    1.1938e-26
    x7              0.0011401    0.00022498     5.0678    6.7473e-07
    x1:x5          -0.0015096    0.00040087    -3.7659    0.00019673
    x5:x7          -0.0049673    0.00077872    -6.3788    6.0915e-10


Number of observations: 333, Error degrees of freedom: 327
Root Mean Squared Error: 0.001
R-squared: 0.442,  Adjusted R-Squared 0.434
F-statistic vs. constant model: 51.9, p-value = 1.65e-39
6. Adding x5^2, FStat = 63.1344, pValue = 3.17359e-14

mdl1 = 


Linear regression model:
    y ~ 1 + x1*x5 + x5*x7 + x5^2

Estimated Coefficients:
                    Estimate         SE         tStat       pValue  
                   __________    __________    _______    __________

    (Intercept)     0.0011415    6.4043e-05     17.825    4.3107e-50
    x1             0.00071722    0.00010452     6.8618    3.4339e-11
    x5             -0.0018651    0.00016896    -11.039    2.7782e-24
    x7              0.0011951    0.00020635     5.7915    1.6426e-08
    x1:x5          -0.0019348    0.00037135    -5.2101     3.354e-07
    x5:x7          -0.0045341    0.00071592    -6.3332    7.9578e-10
    x5^2            0.0033789    0.00042525     7.9457    3.1736e-14


Number of observations: 333, Error degrees of freedom: 326
Root Mean Squared Error: 0.000921
R-squared: 0.533,  Adjusted R-Squared 0.524
F-statistic vs. constant model: 61.9, p-value = 5.33e-51

所以它基本上意味着对于使用mdl模型的回归我有这个函数: y~1 + x1 * x5 + x5 * x7 对于mdl1我有这个: y~1 + x1 * x5 + x5 * x7 + x5 ^ 2

但是当我尝试使用测试集预测值时,我收到错误。为什么会这样?

test_fv_labels = feval(mdl1,test_fv);    

预测变量数据矩阵必须有5列。

但是如果我使用预测函数而不是feval我没有收到错误。为什么会这样?

test_fv_labels = predict(mdl1,test_fv);

请告诉我出错的地方以及Matlab中predictfeval命令之间的区别。

0 个答案:

没有答案