Python machine learning gradient lifting tree

Source: Internet
Author: User

# like random forests, tree-based decision trees are built in a continuous way, with a very small depth of max_depth<5. Important Parameters N_estimate and learning_rate, the Y effect of these two parameters is to adjust the model overfitting, Thus, the generalization ability of the model can be improved.

From sklearn.ensemble import Gradientboostingclassifier

From sklearn.datasets import Load_breast_cancer

From sklearn.model_selection import Train_test_split

Cancer=load_breast_cancer ()

X_train,x_test,y_train,y_test=train_test_split (cancer.data,cancer.target,random_state=0)

Gbrt=gradientboostingclassifier () #模型不做参数调整

Gbrt.fit (X_train,y_train)

Print (Gbrt.score (x_train,y_train))

Print (Gbrt.score (x_test,y_test))

#对模型做预剪枝

Gbrt=gradientboostingclassifier (n_estimate=100,learning_rate=0.01)

#n_estimate主要控制树的数量, Learning_rate control error correction parameter the smaller the model the more complex

Python machine learning gradient lifting tree

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: info-contact@alibabacloud.com 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.