线性回归

x = rand(10, 5);
y = rand(10, 1);

model = fitlm(x, y); %得到一个linear model object

model.Coefficients.Estimate %返回系数估计
model.Coefficients %返回一个table 如下
                   Estimate      SE        tStat       pValue 
                   ________    _______    ________    ________

    (Intercept)     0.42245    0.44641     0.94634     0.39756
    x1             -0.20952    0.25985    -0.80632     0.46526
    x2              0.21429    0.32745     0.65442     0.54856
    x3              0.12381    0.37666     0.32871     0.75887
    x4              0.39472    0.40384     0.97743      0.3837
    x5             -0.52458    0.22535     -2.3278    0.080442

% 下面两种方法均可用于预测结果
model.predict([1,2,3,4,5]);    
predict(model, [1,2,3,4,5]);

% 方差分析
model.anova %返回一个展示anova结果的table
               SumSq      DF     MeanSq         F        pValue 
             _________    __    _________    ________    _______

    x1       0.0036003    1     0.0036003    0.032771    0.86515
    x2        0.050071    1      0.050071     0.45575    0.53663
    x3       0.0041511    1     0.0041511    0.037784    0.85535
    x4         0.22678    1       0.22678      2.0642    0.22415
    x5        0.074927    1      0.074927       0.682    0.45531
    Error      0.43946    4       0.10986        

% 绘制散点图和回归线
model.plot()

% 绘制变量影响图
model.plotEffects()

% model的各种常用属性
model.Varables % 返回代表x的table
model.SSE model.SST model.SSR model.Rsquared %返回相应的属性的值

回归树

tree = fitrtree(x, y); %返回regression tree model


tree.view % 返回一个直观显示变量切割的信息
Decision tree for regression
1  if x1<5.5 then node 2 elseif x1>=5.5 then node 3 else 0.5
2  fit = 0
3  fit = 1

%以树状图的形式显示模型切割信息
tree.view('Mode','graph')

% 预测新样本
predict(tree, x)

results matching ""

    No results matching ""