Machine learning Path: Python practice lifting Tree xgboost classifier

Source: Internet
Author: User
Tags rfc xgboost

Git:https://github.com/linyi0604/machinelearning

I downloaded the dataset locally, and I can go to my git to get the dataset.

Xgboost
Lift classifier
belong to the integrated learning model
Combine hundreds of tree models with lower classification accuracy rates
Continually iterate, generating a new tree each iteration


Below is a prediction of the death of the Titanic.
Using the Xgboost model and other classifier performance comparisons

1 ImportPandas as PD2  fromSklearn.cross_validationImportTrain_test_split3  fromSklearn.feature_extractionImportDictvectorizer4  fromSklearn.ensembleImportRandomforestclassifier5  fromXgboostImportXgbclassifier6 7 " "8 Xgboost9 Lift ClassifierTen belong to the integrated learning model One combine hundreds of tree models with lower classification accuracy rates A continually iterate, generating a new tree each iteration -      -      the under the face of Titanic 's death forecast - using the Xgboost model and other classifier performance comparisons -  - " " +  -Titanic = Pd.read_csv (".. /data/titanic/titanic.txt") + #extract Pclass age and sex as a training sample Ax = titanic[["Pclass"," Age","Sex"]] aty = titanic["survived"] - #The average complement of the acquired age space -x[" Age"].fillna (x[" Age"].mean (), inplace=True) -  - #split training data and test data -X_train, X_test, y_train, y_test =train_test_split (x, in y, -test_size=0.25, toRandom_state=33) + #extracting dictionary features for vectorization -VEC =Dictvectorizer () theX_train = Vec.fit_transform (X_train.to_dict (orient="Record")) *X_test = Vec.transform (X_test.to_dict (orient="Record")) $ Panax Notoginseng #predict with a random forest with default configuration -RFC =Randomforestclassifier () the Rfc.fit (X_train, Y_train) + Print("Stochastic forest prediction accuracy rate:", Rfc.score (X_test, Y_test))#0.7811550151975684 A  the #using Xgboost model to predict +XGBC =Xgbclassifier () - Xgbc.fit (X_train, Y_train) $ Print("xgboost Forecast accuracy rate:", Xgbc.score (X_test, Y_test))#0.7872340425531915

Machine learning Path: Python practice lifting Tree xgboost classifier

Related Article

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.