Sklearn discrete AdaBoost vs Real Adaboost__sklearn

Source: Internet
Author: User
In modular learning, there are generally parametric learning_rate: Learning rate Learning Rate
This is a value on [0, 1], and some of the articles say it's used to set the iteration range in the algorithm,
The General Assembly leads to the fitting, the fitting means that the fitting function oscillation instability, which is intuitively understandable.
For the AdaBoost combined model call Staged_predict, the predicted values for each iteration stage can be obtained.
The Sklearn.metrics.zero_one_loss directly measures the distance between the prediction and the original value.
Discrete AdaBoost and real AdaBoost are compared in the training set and test set below.
Import NumPy as NP import Matplotlib.pyplot as PLT from Sklearn Import datasets from Sklearn.tree import DECISIONTREEC 
Lassifier from sklearn.metrics import zero_one_loss from sklearn.ensemble import Adaboostclassifier = 400 Learning_rate = 1 X, y = datasets.make_hastie_10_2 (n_samples = 12000, random_state = 1) x_test, y_test = X[2000:], y[20 ] X_train, Y_train = x[:2000], y[:2000] dt_stump = decisiontreeclassifier (max_depth = 1, min_samples_leaf = 1) dt_stum (X_train, y_train) Dt_stump_err = 1.0-dt_stump.score (x_test, y_test) dt = decisiontreeclassifier (max_depth = 9, MI N_samples_leaf = 1 (x_train, y_train) Dt_err = 1.0-dt.score (x_test, y_test) ada_discrete = AdaBoostClassifier (ba Se_estimator = dt_stump,     learning_rate = Learning_rate,     n_estimators = n_estimators,     algorithm = "Samme") (X_train, y_train) Ada_real = Adaboostclassifier (Base_estimator = dt_stumP,     learning_rate = learning_rate,     n_estimators = n_estimators,      algorithm = "Samme."  R ") (X_train, y_train) FIG = plt.figure () Ax = Fig.add_subplot ($) Ax.plot ([1, N_estimators], [Dt_stump_err] 

* 2, "k", label = "Decision Stump error") Ax.plot ([1, N_estimators], [Dt_err] * 2, "k--", label = "Decision Tree error") Ada_discrete_err = Np.zeros ((n_estimators,)) for I, y_pred in enumerate (ada_discrete.staged_predict (X_test)):   Ada_discrete_err[i] = Zero_one_loss (y_pred, y_test) Ada_discrete_err_train = Np.zeros ((n_estimators,)) for I, y_pred in E

Numerate (Ada_discrete.staged_predict (X_train)):  ada_discrete_err_train[i] = Zero_one_loss (y_pred, Y_train) Ada_real_err = Np.zeros ((n_estimators,)) for I, y_pred in enumerate (ada_real.staged_predict (x_test)):  ada_real_ Err[i] = Zero_one_loss (y_pred, y_test) Ada_real_err_train = Np.zeros ((n_estimators,)) for I, y_pred in enumerate (ada_real . staged_pRedict (X_train)):  ada_real_err_train[i] = Zero_one_loss (y_pred, Y_train) Ax.plot (Np.arange (n_estimators) + 1, Ada_discrete_err, label = "Discrete AdaBoost Test Error", color = "Red") Ax.plot (Np.arange (n_estimators) + 1, Ada_discrete _err_train, label = "Discrete AdaBoost train Error", color = "Blue") Ax.plot (Np.arange (n_estimators) + 1, Ada_real_err, LA  Bel = "Real AdaBoost Test Error", color = "Orange") Ax.plot (Np.arange (n_estimators) + 1, ada_real_err_train, label = ' real

AdaBoost Train Error ", color =" green ") Ax.set_ylim ((0.0, 0.5)) Ax.set_xlabel (" N_estimators ") Ax.set_ylabel (" Err rate ")
 Leg = ax.legend (loc = "upper right", FancyBox = True) leg.get_frame (). Set_alpha (0.7) ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.