This article is not updated regularly. Original articles, reproduced please indicate the source, thank you.
AdaBoost is an iterative algorithm whose core idea is to train different classifiers (weak classifiers) for the same training set, and then set up these weak classifiers to form a stronger final classifier (strong classifier). The adaboost algorithm itself is implemented by changing the data distribution, which determines the weights of each sample based on the correctness of the classification of each sample in each training set and the accuracy of the last population classification. The new data set that modifies the weights is sent to the lower classifier for training, and finally the classifier is finally fused as the final decision classifier.
Algorithm overview
1, first through the study of n training samples to get the first weak classifier;
2, the wrong sample and other new data together constitute a new n training sample, through the study of this sample to obtain a second weak classifier;
3, the sample of 1 and 2 are divided into two different samples and other new samples constitute another new n training samples, through the study of this sample to obtain a third weak classifier
4, finally through the promotion of the strong classifier. That is, a data is divided into which category is determined by the weights of each classifier.
Comparison with boosting algorithm
1. The use of weighted post-selection training data instead of randomly selected training samples, so that the focus of training on the more difficult sample of training data;
2. Unite the weak classifiers and use a weighted voting mechanism instead of the average voting mechanism. The weak classifier with good classification effect has bigger weight, and the classification with poor classification effect has smaller weight.
Unlike the boosting algorithm, the adaboost algorithm does not need to know in advance that the weak-learning algorithm learns the lower limit of the correct rate, i.e., the error of the weak classifier, and the classification precision of the final strong classifier depends on the classification precision of all weak classifiers, so that the ability of the weak classifier algorithm can be deeply explored.
Algorithm steps
1. Given the training sample set S, where x and y correspond to a positive sample and a negative sample, T is the maximum number of cycles to be trained;
2. Initialize the sample weight to 1/n, which is the initial probability distribution of the training sample;
3. The first iteration: (1) The probability distribution of training samples is equal, training weak classifier, (2) calculating the error rate of weak classifier, (3) Selecting appropriate threshold value, making the error minimum; (4) updating the sample weights;
After the T-cycle, a weak classifier is obtained, which is superimposed by the updated weights and finally gets the strong classifier.
The steps are as follows:
A. Sample
Given:m examples (x1, y1), ..., (XM, YM)
Where xix, Yiy={-1, +1}
Xi represents the first element of X,
Yi represents the attribute value of the corresponding element with Xi, and +1 indicates that Xi belongs to a classification,
-1 indicates that Xi does not belong to a category
Two. Weight of the initial Training sample XI (i): I=1,......, M;
(1). If the number of positive and negative samples is the same, D1 (i) = 1/m
(2). If the number of positive and negative samples is m+, M is the sample D1 (i) = 1/m+,
Negative sample D1 (i) = 1/m-
Detailed examples
The "+" and "-" in the figure represent two categories. We classify a horizontal or vertical line as a classifier.
Before the algorithm began to evenly distribute d, a total of 10 samples, so each sample weight value is 0.1.
First-time classification:
The First Division has 3 point partitioning errors, based on the error expression
Calculation can be e1= (0.1+0.1+0.1)/1.0=0.3
Classifier Weights:
Then, according to the algorithm, the weights of the wrong points become larger. For the correct classification of the 7 points, the weights are unchanged, still 0.1, for the wrong points of 3 points, the weights are:
d1=d0* (1-e1)/e1=0.1* (1-0.3)/0.3=0.2333
Secondary classification:
, there are 3 "-" classification errors. The sum of the weights after the upper whorl classification is: 0.1*7+0.2333*3=1.3990
Classification Error: e2=0.1*3/1.3990=0.2144
Classifier Weight a2=0.6493
The 3 point weights of the wrong points are: D2=0.1* (1-0.2144)/0.2144=0.3664
Third Category:
The above steps can be obtained: e3=0.1365; a3=0.9223;d3=0.6326
The final strong classifier is the overlay of three weak classifiers, as shown in:
Each region is a property of which it is determined by the weight of the classifier in which the region is located. For example, the lower left corner of the area, the weight of the blue category is H1 0.42 and H2 in the 0.65, which is 1.07; the weight of the light red category is 0.92 in H3, and the weight of the light red classification area is less than the weights belonging to the blue category, so the lower left corner belongs to the blue classification area. So you can get the results of the integration as shown in the result graph, even simple classifiers can be combined to achieve a good classification effect.
Reason for weight adjustment of classifier
As can be seen from the formula, weights are expressions about errors. Each iteration increases the weighted value of the wrong point, and the next time the classifier is wrongly divided, it increases the overall error rate, which leads to a smaller classifier weight, which in turn causes the classifier to be less weighted in the final mixed classifier, which means The adaboost algorithm makes the classifier with high accuracy higher than the overall weight, so that the right value of the classifier with low correct rate is lower, thus improving the accuracy of the final classifier.
Advantages and disadvantages of algorithms
Advantages
1) AdaBoost is a classifier with high accuracy
2) A sub-classifier can be constructed using various methods, and the AdaBoost algorithm provides a framework
3) When using a simple classifier, the calculated results are understandable. And the weak classifier is extremely simple to construct.
4) Simple, no feature screening
5) Don't worry about overfitting (over fitting)
Disadvantages
1) susceptible to noise interference, which is also the disadvantage of most algorithms
2) Training time is too long
3) The execution effect depends on the selection of the weak classifier
SQL implementation
#开始迭代while (@i<=3) do set @evalue =0, @temp =0;set @flag1 =0, @flag2 =0, @flag3 =0, @flag4 =0;set @las =concat (' d ', @i-1); set @cur =concat (' d ', @i); Set @a=concat (' Select Hx,hy into @hx, @hy from hea where id = ', @i); Prepare STMT1 from @a;execute stmt1;set @aa =concat (' Update adaset set ', @cur, ' = ', @las); Prepare stmt111 from @aa; execute stmt111; #1. The classifier is a vertical x-axis straight line if (@hy =0) then #处理分类1set @b=concat (' Select count (Class) into @l_1 F Rom Adaset where Class=1 and X < ', @hx);p repare stmt2 from @b;execute stmt2;set @c=concat (' Select count (Class) into @l_ 2 from Adaset where Class=-1 and X < ', @hx);p repare stmt3 from @c;execute stmt3;if (@l_1 =0 and @l_2!=0) Thenset @clas =co NCAT (' Update hea set l=-1 where id = ', @i);p repare stmt28 from @clas; execute stmt28;end if;if (@l_1!=0 and @l_2 =0) thenset @clas =concat (' Update hea set l=1 where id = ', @i);p repare stmt29 from @clas; execute stmt29;end if;set @weight =concat (' d ', @i-1), if (@l_1!=0 and @l_2!=0 and @l_1 > @l_2) THEN # @l_2 is the wrong point set @d=concat (' Select sum (', @weIght, ') into @temp from Adaset where class=-1 and X < ', @hx);p repare stmt4 from @d;execute stmt4;set @[email prote Cted][email protected];set @flag1 =1;set @clas =concat (' Update hea set l=1 where id = ', @i);p repare stmt20 from @clas; E Xecute stmt20;end if;if (@l_1!=0 and @l_2!=0 and @l_1 < @l_2) Then # @l_1 is the wrong point set @d=concat (' Select sum (', @weight, ') into @temp from Adaset where Class=1 and X < ', @hx);p repare stmt5 from @d;execute stmt5;set @[email protected][email&n Bsp;protected];set @flag2 =1;set @clas =concat (' Update hea set l=-1 where id = ', @i);p repare stmt21 from @clas; Execute stmt2 1;end if; #总权值 & Error Set @h=concat (' Select sum (', @weight, ') into @temp from Adaset ');p repare stmt10 from @h;execute stmt10 Set @evalue = Round (@evalue/@temp, 4), Set @avalue = Round ((0.5*ln ([[email protected])/@evalue), 4), Set @eee = Round ([email protected])/@evalue, 4); #更新误差e & Assume the weight aset @j=concat (' update hea set e = ', @evalue, ', a = ', @avalue, ' WHERE id = ', @i);p repare stmt11 froM @j;execute stmt11; #更新错分样本的权重if (@hy =0) thenif (@flag1 =1) thenset @k=concat (' Update adaset set ', @cur, ' = ', @las, ' * ', @eee , ' where class=-1 and X < ', @hx);p repare stmt12 from @k;execute stmt12;end if;if (@flag2 =1) thenset @m=concat (' Update a Daset set ', @cur, ' = ', @las, ' * ', @eee, ' where Class=1 and X < ', @hx);p repare stmt13 from @m;execute stmt13;end if;if (@f lag3=1) Thenset @n=concat (' Update adaset set ', @cur, ' = ', @las, ' * ', @eee, ' where class=-1 and x > ', @hx);p Repare stmt14 From @n;execute stmt14;end if;if (@flag4 =1) thenset @o=concat (' Update adaset set ', @cur, ' = ', @las, ' * ', @eee, ' where class= 1 and x > ', @hx);p repare stmt15 from @o;execute stmt15;end if;end if;set @[email protected]+1;end while;
These are some of the adaboost algorithms that bloggers have recently implemented with SQL. The database tables are then collated and pasted. Ubuntu unstable ah, the crash twice. The editor's blog is gone. Tired sleep does not love.
Personal questions
The disadvantage mentioned above is that the effect of the AdaBoost algorithm relies on the selection of weak classifiers, so how to choose the weak classification in the face of huge data to be classified? There are no principles. Bloggers are still exploring and finding answers will be updated here.
Recommended information: Written by AdaBoost algorithm founder Freund and schapire about the adaboost algorithm, I have uploaded the document.
Original articles, reproduced please indicate the source, thank you.
Data Mining Algorithm Learning (eight) Adaboost