首页 >
> 详细

代写实现Adaboost分类器。

In this assignment, your task is to train an AdaBoost classifier on synthetic data. For reference, you are provided with the posterior `P(y = 1 | x)`

, with x regularly sampled over the domain `X = [0, 1] × [0, 1]`

, so that you can see, in the end, how the output of the AdaBoost classifier better approximates the posterior at each round.

Please read the assignment entirely before you start coding, in order to get a sense of how it is organized. In particular, note that the AdaBoost algorithm is only run at the very last cell of the “Train the classifier” section. Before that, a number of functions are defined, one of which you need to complete.

Fill in the missing parts to implement the Adaboost algorithm described in class (slide 64 of the course). This involves iterating over the following steps:

- a. Find the best weak learner h at each round.
- b. Using the weak learner’s weighted error e, compute t.
- c. Update the weight distribution D of the training samples.

Modify your loop to compute the loss at each round. Then, plot E and make sure that it is monotonically decreasing with time. Verify that E provides an upper bound for the number of errors.

First show the approximate posterior of your strong learner side-by-side with the original posterior. Then, show the approximate posteriors for each step at which the learner’s response has been saved. Make sure that they look increasingly similar to the original posterior.

- The response of a weak learner h for the sample x is
`h(x) ∈ {−1, 1}`

. - At each round we find the best weak learner. The overall response of the strong learner at round t for the sample x. In order to be coherent with the weak learner’s expression, we can also define
`H(x) = sign(f(x)) ∈ {1, 1}`

, which can also be called the overall response. However, in this assignment, we are only interested in f .

1 |
import matplotlib.pyplot as plt |

1 |
features, labels, posterior = construct_data(500, 'train', 'nonlinear', plusminus=True) |

The weak learner we use for this classification problem is a decision stump (see slide 63 of the course), whose response is defined as `h(x) = s(2[xd ≥ θ] − 1)`

, where

- d is the the dimension along which the decision is taken,
- [·] is 1 if is true and 0 otherwise,
- θ is the threshold applied along dimension d and
`s ∈ {−1, 1}`

is the polarity of the decision stump (this is a multiplicative factor, not a func- tion!).

For example, if s = 1, the decision stump will consider that all samples whose d-th feature is greater than θ are in the positive class `(h(x) = +1)`

, and all samples with a feature strictly lower than are in the negative class `(h(x) = -1)`

.

1 |
def evaluate_stump(features, coordinate_wl, polarity_wl, theta_wl): |

At each round of AdaBoost, the samples are reweighted, thus producing a new classification prob- lem, where the samples with a larger weigth count more in the classification error. The first step of a new round is to find the weak learner with the best performance for this new problem, that is, with the smallest classification error:

Notes on the implementation:

- The error is normalized in the course’s slides, but in practice you don’t need to, since the weights themselves are already normalized in the main loop of the algorithm.
- When searching for the best weak learner, you don’t need to consider all possible combi- nations of θ, d, s. For a given dimension d, the relevant values to try are the x (where i indexes the training samples).

1 |
def find_best_weak_learner(weights, features, labels): |

1 |
npoints = features.shape[0] |

1 |
## TODO (Question 2) |

It can be shown (cf. slide 69 of the course*) that the AdaBoost strong classifier’s response con- verges to half the posterior log-ratio:

Therefore, we can check how good the response gets in terms of approximating the posterior.

*NB: There is a typo in this slide, the 2 1 is missing.

1 |
approx_posterior_10 = 1 / (1 + np.exp(-2 * f_10)) |

联系我们

- QQ：99515681
- 邮箱：99515681@qq.com
- 工作时间：8:00-23:00
- 微信：codinghelp2

- Ecse 427作业代写、代做systems课程作业、C++程序语言作业调试 2020-09-25
- 代做program课程作业、代写matlab实验作业、Matlab编程语言作 2020-09-25
- 代写program留学生作业、Sql程序设计作业调试、代写data课程作业、 2020-09-25
- Comp3506作业代写、代做java实验作业、Java编程语言作业调试、代 2020-09-25
- Game Menu Shell作业代做、System课程作业代写、C#编程语 2020-09-25
- Cp1 1902作业代做、代做c/C++程序语言作业、代写java，Pyth 2020-09-25
- 代写sit215留学生作业、Artificial作业代写、Python程序语 2020-09-24
- Sit202课程作业代做、代写computer Networks作业、Web 2020-09-24
- 代写kit308/408作业、代做programming作业、C/C++程序 2020-09-24
- Comp3506作业代做、代写java编程语言作业、代做programmin 2020-09-24
- 代写data留学生作业、代写program作业、Python程序语言作业调试 2020-09-23
- Data Programming作业代写、Python编程语言作业调试、代写 2020-09-23
- Comp1600作业代做、代写java编程作业、代做c/C++，Python 2020-09-23
- Ict365课程作业代做、代写c++程序设计作业、代做c/C++实验作业调试 2020-09-23
- 代写program留学生作业、Python，Java，C++程序语言作业调试 2020-09-23
- Cs 2510课程作业代做、代写systems留学生作业、Python编程设 2020-09-22
- B-Tree作业代做、代做java课程设计作业、Java程序语言作业调试、代 2020-09-22
- 代做cop3503作业、代写c++程序语言作业、代做c++课程设计作业、代做 2020-09-22
- 代写159.336留学生作业、代做python编程设计作业、代写java，C 2020-09-22
- Software课程作业代写、C++程序语言作业调试代做、代做data留学生 2020-09-22