Adaboost算法实现一

来源:互联网 发布:炸奥利奥 知乎 编辑:程序博客网 时间:2024/06/06 11:47

对前四次迭代分析

训练数据

实验样本:30

   43.8744   84.0717         1

   38.1558   25.4282         2

   76.5517   81.4285         1

   79.5200   24.3525         2

   18.6873   92.9264         1

   48.9764   34.9984         2

   44.5586   19.6595         2

   64.6313   25.1084         2

   70.9365   61.6045         2

   75.4687   47.3289         2

   27.6025   35.1660         1

   67.9703   83.0829         1

   65.5098   58.5264         2

   16.2612   54.9724         1

   11.8998   91.7194         1

   49.8364   28.5839         2

   95.9744   75.7200         2

   34.0386   75.3729         1

   58.5268   38.0446         2

   22.3812   56.7822         1

   75.1267    7.5854         2

   25.5095    5.3950         2

   50.5957   53.0798         1

   69.9077   77.9167         1

   89.0903   93.4011         1

   95.9291   12.9906         2

   54.7216   56.8824         1

   13.8624   46.9391         1

   14.9294    1.1902         2

   25.7508   33.7123         1

 

第一次循环

adaboost_model.parameters{1}

ans =

 

   min_error: 0.2000

    min_error_thr: 31.1481

          pos_neg: 'neg'

              dim: 2

                            mm:10

 

 [L,hits,error_rate] = threshold_te(adaboost_model.parameters{turn},...

        tr_set,samples_weight,tr_labels)

L =

     1     0

     0     1

     1     0

     0     1

     1     0

     1     0

     0     1

     0     1

     1     0

     1     0

     1     0

     1     0

     1     0

     1     0

     1     0

     0     1

     1     0

     1     0

     1     0

     1     0

     0     1

     0     1

     1     0

     1     0

     1     0

     0     1

     1     0

     1     0

     0     1

     1     0

 

 

hits =

    24

error_rate =

    0.2000

第一次分类以后权重的分配

samples_weight(t_labeled) = samples_weight(t_labeled)*...%提取正确分类的权重

        ((error_rate)/(1-error_rate))

将错误的分类突出出来,标记的权重更大

samples_weight =

    0.0083

    0.0083

    0.0083

    0.0083

    0.0083

    0.0333

    0.0083

    0.0083

    0.0333

    0.0333

    0.0083

    0.0083

    0.0333

    0.0083

    0.0083

    0.0083

    0.0333

    0.0083

    0.0333

    0.0083

    0.0083

    0.0083

    0.0083

    0.0083

    0.0083

    0.0083

    0.0083

    0.0083

    0.0083

0.0083

第二次循环

adaboost_model.parameters{2}

ans =

   min_error: 0.1667

    min_error_thr: 76.8184

          pos_neg: 'neg'

              dim: 2

                            mm:24

[L,hits,error_rate] = threshold_te(adaboost_model.parameters{turn},...

        tr_set,samples_weight,tr_labels)

L =

     1     0

     0     1

     1     0

     0     1

     1     0

     0     1

     0     1

     0     1

     0     1

     0     1

     0     1

     1     0

     0     1

     0     1

     1     0

     0     1

     0     1

     0     1

     0     1

     0     1

     0     1

     0     1

     0     1

     1     0

     1     0

     0     1

     0     1

     0     1

     0     1

     0     1

hits =

    22

error_rate =

0.1667

权重

weights: [0.6021 0.6990]

 

第二次更新样本权重,没归一化之前的

samples_weight(t_labeled) = samples_weight(t_labeled)*...%提取正确分类的权重

        ((error_rate)/(1-error_rate))

samples_weight =

    0.0042

    0.0042

    0.0042

    0.0042

    0.0042

    0.0167

    0.0042

    0.0042

    0.0167

    0.0167

    0.0208

    0.0042

    0.0167

    0.0208

    0.0042

    0.0042

    0.0167

    0.0208

    0.0167

    0.0208

    0.0042

    0.0042

    0.0208

    0.0042

    0.0042

    0.0042

    0.0208

    0.0208

    0.0042

0.0208

第三次迭代

adaboost_model.parameters{3}

ans =

  min_error: 0.1625

    min_error_thr: 56.6242

          pos_neg: 'pos'

              dim: 1

                            mm:24

[L,hits,error_rate] = threshold_te(adaboost_model.parameters{turn},...

        tr_set,samples_weight,tr_labels)

L =

     1     0

     1     0

     0     1

     0     1

     1     0

     1     0

     1     0

     0     1

     0     1

     0     1

     1     0

     0     1

     0     1

     1     0

     1     0

     1     0

     0     1

     1     0

     0     1

     1     0

     0     1

     1     0

     1     0

     0     1

     0     1

     0     1

     1     0

     1     0

     1     0

     1     0

hits =

   20

error_rate =

0.1625

weights: [0.6021 0.6990 0.7121]

samples_weight =

    0.0024

    0.0125

    0.0125

    0.0024

    0.0024

    0.0500

    0.0125

    0.0024

    0.0097

    0.0097

    0.0121

    0.0125

    0.0097

    0.0121

    0.0024

    0.0125

    0.0097

    0.0121

    0.0097

    0.0121

    0.0024

    0.0125

    0.0121

    0.0125

    0.0125

    0.0024

    0.0121

    0.0121

    0.0125

0.0121

第四次迭代

adaboost_model.parameters{4}

ans =

   min_error: 0.1866

    min_error_thr: 35.0822

          pos_neg: 'neg'

              dim: 2

                            mm:12

[L,hits,error_rate] = threshold_te(adaboost_model.parameters{turn},...

        tr_set,samples_weight,tr_labels)

L =

     1     0

     0     1

     1     0

     0     1

     1     0

     0     1

     0     1

     0     1

     1     0

     1     0

     1     0

     1     0

     1     0

     1     0

     1     0

     0     1

     1     0

     1     0

     1     0

     1     0

     0     1

     0     1

     1     0

     1     0

     1     0

     0     1

     1     0

     1     0

     0     1

     0     1

hits =

    24

error_rate =

    0.1866

weights: [0.6021 0.6990 0.7121 0.6395]

    samples_weight(t_labeled) = samples_weight(t_labeled)*...%提取正确分类的权重

        ((error_rate)/(1-error_rate))

samples_weight =

    0.0017

    0.0088

    0.0088

    0.0017

    0.0017

    0.0353

    0.0088

    0.0017

    0.0299

    0.0299

    0.0086

    0.0088

    0.0299

    0.0086

    0.0017

    0.0088

    0.0299

    0.0086

    0.0299

    0.0086

    0.0017

    0.0088

    0.0086

    0.0088

    0.0088

    0.0017

    0.0086

    0.0086

    0.0088

    0.0373

原创粉丝点击