This document provides an overview of XGBoost, an open-source gradient boosting framework. It begins with introductions to machine learning algorithms and XGBoost specifically. The document then walks through using XGBoost with R, including loading data, running models, cross-validation, and prediction. It discusses XGBoost's use in winning the Higgs Boson machine learning competition and provides code to replicate its solution. Finally, it briefly covers XGBoost's model specification and training objectives.
Open Source Tools & Data Science Competitions odsc
This talk shares the presenter’s experience with open source tools in data science competitions. In the past several years Kaggle and other competitions have created a large online community of data scientists. In addition to competing with each other for fame and glory, members of this community also generously share knowledge, insights using forum and open source code. The open competition and sharing have resulted in rapid progress in the sophistication of the entire community. This presentation will briefly cover this journey from a competitor’s perspective, and share hands on tips on some open source tools proven popular and useful in recent competitions.
Winning data science competitions, presented by Owen ZhangVivian S. Zhang
<featured> Meetup event hosted by NYC Open Data Meetup, NYC Data Science Academy. Speaker: Owen Zhang, Event Info: http://www.meetup.com/NYC-Open-Data/events/219370251/
Tong is a data scientist in Supstat Inc and also a master students of Data Mining. He has been an active R programmer and developer for 5 years. He is the author of the R package of XGBoost, one of the most popular and contest-winning tools on kaggle.com nowadays.
Agenda:
Introduction of Xgboost
Real World Application
Model Specification
Parameter Introduction
Advanced Features
Kaggle Winning Solution
Overview of tree algorithms from decision tree to xgboostTakami Sato
For my understanding, I surveyed popular tree algorithms on Machine Learning and their evolution. This is the first time I wrote a presentation in English. So, I am happy if you give me a feedback.
Our fall 12-Week Data Science bootcamp starts on Sept 21st,2015. Apply now to get a spot!
If you are hiring Data Scientists, call us at (1)888-752-7585 or reach info@nycdatascience.com to share your openings and set up interviews with our excellent students.
---------------------------------------------------------------
Come join our meet-up and learn how easily you can use R for advanced Machine learning. In this meet-up, we will demonstrate how to understand and use Xgboost for Kaggle competition. Tong is in Canada and will do remote session with us through google hangout.
---------------------------------------------------------------
Speaker Bio:
Tong is a data scientist in Supstat Inc and also a master students of Data Mining. He has been an active R programmer and developer for 5 years. He is the author of the R package of XGBoost, one of the most popular and contest-winning tools on kaggle.com nowadays.
Pre-requisite(if any): R /Calculus
Preparation: A laptop with R installed. Windows users might need to have RTools installed as well.
Agenda:
Introduction of Xgboost
Real World Application
Model Specification
Parameter Introduction
Advanced Features
Kaggle Winning Solution
Event arrangement:
6:45pm Doors open. Come early to network, grab a beer and settle in.
7:00-9:00pm XgBoost Demo
Reference:
https://github.com/dmlc/xgboost
In this talk, Dmitry shares his approach to feature engineering which he used successfully in various Kaggle competitions. He covers common techniques used to convert your features into numeric representation used by ML algorithms.
Open Source Tools & Data Science Competitions odsc
This talk shares the presenter’s experience with open source tools in data science competitions. In the past several years Kaggle and other competitions have created a large online community of data scientists. In addition to competing with each other for fame and glory, members of this community also generously share knowledge, insights using forum and open source code. The open competition and sharing have resulted in rapid progress in the sophistication of the entire community. This presentation will briefly cover this journey from a competitor’s perspective, and share hands on tips on some open source tools proven popular and useful in recent competitions.
Winning data science competitions, presented by Owen ZhangVivian S. Zhang
<featured> Meetup event hosted by NYC Open Data Meetup, NYC Data Science Academy. Speaker: Owen Zhang, Event Info: http://www.meetup.com/NYC-Open-Data/events/219370251/
Tong is a data scientist in Supstat Inc and also a master students of Data Mining. He has been an active R programmer and developer for 5 years. He is the author of the R package of XGBoost, one of the most popular and contest-winning tools on kaggle.com nowadays.
Agenda:
Introduction of Xgboost
Real World Application
Model Specification
Parameter Introduction
Advanced Features
Kaggle Winning Solution
Overview of tree algorithms from decision tree to xgboostTakami Sato
For my understanding, I surveyed popular tree algorithms on Machine Learning and their evolution. This is the first time I wrote a presentation in English. So, I am happy if you give me a feedback.
Our fall 12-Week Data Science bootcamp starts on Sept 21st,2015. Apply now to get a spot!
If you are hiring Data Scientists, call us at (1)888-752-7585 or reach info@nycdatascience.com to share your openings and set up interviews with our excellent students.
---------------------------------------------------------------
Come join our meet-up and learn how easily you can use R for advanced Machine learning. In this meet-up, we will demonstrate how to understand and use Xgboost for Kaggle competition. Tong is in Canada and will do remote session with us through google hangout.
---------------------------------------------------------------
Speaker Bio:
Tong is a data scientist in Supstat Inc and also a master students of Data Mining. He has been an active R programmer and developer for 5 years. He is the author of the R package of XGBoost, one of the most popular and contest-winning tools on kaggle.com nowadays.
Pre-requisite(if any): R /Calculus
Preparation: A laptop with R installed. Windows users might need to have RTools installed as well.
Agenda:
Introduction of Xgboost
Real World Application
Model Specification
Parameter Introduction
Advanced Features
Kaggle Winning Solution
Event arrangement:
6:45pm Doors open. Come early to network, grab a beer and settle in.
7:00-9:00pm XgBoost Demo
Reference:
https://github.com/dmlc/xgboost
In this talk, Dmitry shares his approach to feature engineering which he used successfully in various Kaggle competitions. He covers common techniques used to convert your features into numeric representation used by ML algorithms.
Feature Engineering - Getting most out of data for predictive modelsGabriel Moreira
How should data be preprocessed for use in machine learning algorithms? How to identify the most predictive attributes of a dataset? What features can generate to improve the accuracy of a model?
Feature Engineering is the process of extracting and selecting, from raw data, features that can be used effectively in predictive models. As the quality of the features greatly influences the quality of the results, knowing the main techniques and pitfalls will help you to succeed in the use of machine learning in your projects.
In this talk, we will present methods and techniques that allow us to extract the maximum potential of the features of a dataset, increasing flexibility, simplicity and accuracy of the models. The analysis of the distribution of features and their correlations, the transformation of numeric attributes (such as scaling, normalization, log-based transformation, binning), categorical attributes (such as one-hot encoding, feature hashing, Temporal (date / time), and free-text attributes (text vectorization, topic modeling).
Python, Python, Scikit-learn, and Spark SQL examples will be presented and how to use domain knowledge and intuition to select and generate features relevant to predictive models.
文献紹介:Simple Copy-Paste Is a Strong Data Augmentation Method for Instance Segm...Toru Tamaki
Golnaz Ghiasi, Yin Cui, Aravind Srinivas, Rui Qian, Tsung-Yi Lin, Ekin D. Cubuk, Quoc V. Le, Barret Zoph; Simple Copy-Paste Is a Strong Data Augmentation Method for Instance Segmentation, Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 2021, pp. 2918-2928
https://openaccess.thecvf.com/content/CVPR2021/html/Ghiasi_Simple_Copy-Paste_Is_a_Strong_Data_Augmentation_Method_for_Instance_CVPR_2021_paper.html
出典:Nicolas Carion, Francisco Massa, Gabriel Synnaeve, Nicolas Usunier, Alexander Kirillov, Sergey Zagoruyko
Facebook AI
公開URL : https://arxiv.org/abs/2005.12872
概要:Detection Transformer(DETRという)という新しいフレームワークによって,non-maximum-supressionやアンカー生成のような人手で設計する必要なく、End-to-Endで画像からぶった検出を行う手法を提案しています。物体検出を直接集合予測問題として解くためのtransformerアーキテクチャとハンガリアン法を用いて二部マッチングを行い正解と予測の組み合わせを探索しています。Attentionを物体検出に応用しただけでなく、競合手法であるFaster R-CNNと同等の精度を達成しています。
BERT を中心に解説した資料です.BERT に比べると,XLNet と RoBERTa の内容は詳細に追ってないです.
あと,自作の図は上から下ですが,引っ張ってきた図は下から上になっているので注意してください.
もし間違い等あったら修正するので,言ってください.
(特に,RoBERTa の英語を読み間違えがちょっと怖いです.言い訳すいません.)
BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
XLNet: Generalized Autoregressive Pretraining for Language Understanding
RoBERTa: A Robustly Optimized BERT Pretraining Approach
Feature Engineering - Getting most out of data for predictive modelsGabriel Moreira
How should data be preprocessed for use in machine learning algorithms? How to identify the most predictive attributes of a dataset? What features can generate to improve the accuracy of a model?
Feature Engineering is the process of extracting and selecting, from raw data, features that can be used effectively in predictive models. As the quality of the features greatly influences the quality of the results, knowing the main techniques and pitfalls will help you to succeed in the use of machine learning in your projects.
In this talk, we will present methods and techniques that allow us to extract the maximum potential of the features of a dataset, increasing flexibility, simplicity and accuracy of the models. The analysis of the distribution of features and their correlations, the transformation of numeric attributes (such as scaling, normalization, log-based transformation, binning), categorical attributes (such as one-hot encoding, feature hashing, Temporal (date / time), and free-text attributes (text vectorization, topic modeling).
Python, Python, Scikit-learn, and Spark SQL examples will be presented and how to use domain knowledge and intuition to select and generate features relevant to predictive models.
文献紹介:Simple Copy-Paste Is a Strong Data Augmentation Method for Instance Segm...Toru Tamaki
Golnaz Ghiasi, Yin Cui, Aravind Srinivas, Rui Qian, Tsung-Yi Lin, Ekin D. Cubuk, Quoc V. Le, Barret Zoph; Simple Copy-Paste Is a Strong Data Augmentation Method for Instance Segmentation, Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 2021, pp. 2918-2928
https://openaccess.thecvf.com/content/CVPR2021/html/Ghiasi_Simple_Copy-Paste_Is_a_Strong_Data_Augmentation_Method_for_Instance_CVPR_2021_paper.html
出典:Nicolas Carion, Francisco Massa, Gabriel Synnaeve, Nicolas Usunier, Alexander Kirillov, Sergey Zagoruyko
Facebook AI
公開URL : https://arxiv.org/abs/2005.12872
概要:Detection Transformer(DETRという)という新しいフレームワークによって,non-maximum-supressionやアンカー生成のような人手で設計する必要なく、End-to-Endで画像からぶった検出を行う手法を提案しています。物体検出を直接集合予測問題として解くためのtransformerアーキテクチャとハンガリアン法を用いて二部マッチングを行い正解と予測の組み合わせを探索しています。Attentionを物体検出に応用しただけでなく、競合手法であるFaster R-CNNと同等の精度を達成しています。
BERT を中心に解説した資料です.BERT に比べると,XLNet と RoBERTa の内容は詳細に追ってないです.
あと,自作の図は上から下ですが,引っ張ってきた図は下から上になっているので注意してください.
もし間違い等あったら修正するので,言ってください.
(特に,RoBERTa の英語を読み間違えがちょっと怖いです.言い訳すいません.)
BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
XLNet: Generalized Autoregressive Pretraining for Language Understanding
RoBERTa: A Robustly Optimized BERT Pretraining Approach
What is boosting
Boosting algorithm
Building models using GBM
Algorithm main Parameters
Finetuning models
Hyper parameters in GBM
Validating GBM models
A Hybrid Recommender with Yelp Challenge Data Vivian S. Zhang
Developed by Chao Shi, Sam O'Mullane, Sean Kickham, Reza Rad and Andrew Rubino
Watch the project presentation: https://youtu.be/gkKGnnBenyk
This project was completed by students from NYC Data Science Academy's 12-Week Bootcamp. Learn more about the bootcamp: http://nycdatascience.com/data-science-bootcamp/
People make decisions on where to eat based on friends’ recommendations. Since they know you, their suggestions matter more than those of strangers.
For the capstone project, we built a hybrid Yelp recommendation system that can provide individualized recommendations based on your friend’s reviews on the social network. We built the machine learning models using Spark, and set up a Flask-Kafka-RDS-Databricks pipeline that allows a continuous stream of user requests.
During the presentation, we will talk about the development framework and technical implementation of the pipeline.
Read on their project posts and code:
https://blog.nycdatascience.com/student-works/capstone/yelp-recommender-part-1/
https://blog.nycdatascience.com/student-works/yelp-recommender-part-2/
Using Machine Learning to aid Journalism at the New York TimesVivian S. Zhang
This talk was presented to NYC Open Data Meetup Group on Nov 11, 2014.
Speaker:
Daeil Kim is currently a data scientist at the Times and is finishing up his Ph.D at Brown University on work related to developing scalable inference algorithms for Bayesian Nonparametric models. His work at the Times spans a variety of problems related to the company's business interests, audience development, as well as developing tools to aid journalism.
Topic:
This talk will focus mostly on how machine learning can help problems that prop up in journalism. We'll begin first by talking about using popular supervised learning algorithms such as regularized Logistic Regression to help assist a journalist's work in uncovering insights into a story regarding the recall of Takata airbags in cars. Afterwards, we'll think about using topic modeling to deal with large document dumps generated from FOIA (Freedom of Information Act) requests and Refinery, a simple web based tool to ease the implementation of such tasks. Finally, if there is time, we will go over how topic models have been extended to assist in the problem of designing an efficient recommendation engine for text-based content.
This project was completed by Scott Dobbins and Rachel Kogan, who enrolled in the NYC Data Science Academy's 12-Week Data Science Bootcamp. Learn more about the program: http://nycdatascience.com/data-science-bootcamp/
Given that both Wikipedia and comments sections of most websites are freely open to anyone to edit at any time, how has Wikipedia managed to remain such a useful resource while most comments sections are ridden with vandalism, ads, and other counterproductive user behavior?
We believe the answer is two-fold: 1) Wikipedia has an army of bots that quickly identify and revert vandalism so that the worst edits are usually never seen by people and the site generally maintains itself in a well-kempt state, and 2) Wikipedia has a strong community of administrators and other contributors who routinely clean the site’s flagged contents.
Vandalism is relatively easy to flag, though a few clever edits manage to stay on the site for a long time. What about site content problems that are more subjective, like bias? Wikipedia users do routinely manually flag pages with point-of-view (POV) issues, though with millions of pages and no machine-based approaches, the site can only manage to confidently maintain neutrality on the more well-trafficked pages.
Here we propose a solution to solve some of the more intractable content issues for Wikipedia and other sites using Natural Language Processing (NLP) and machine learning approaches. The sheer quantity of data managed by Wikipedia and similar sites requires distributed computing approaches, so we show here how Apache Spark can upgrade common algorithms to run on massive data sets.
Hack session for NYTimes Dialect Map Visualization( developed by R Shiny)Vivian S. Zhang
Data Science Academy, Hack session, NY Times, Dialect Map, Data science by R, Vivian S. Zhang, see www.nycdatascience.com for more details. Joint work by Data Scientist team of SupStat Inc. a New York based data analytic and visualization consulting firm.
Data Science is concerned with the analysis of large amounts of data. When the volume of data is really large, it requires the use of cooperating, distributed machines. The most popular method of doing this is Hadoop, a collection of programs to perform computations on connected machines in a cluster. Hadoop began life as an open-source implementation of MapReduce, an idea first developed and implemented by Google for its own clusters. Though Hadoop's MapReduce is Java-based, and quite complex, this talk focuses on the "streaming" facility, which allows Python programmers to use MapReduce in a clean and simple way. We will present the core ideas of MapReduce and show you how to implement a MapReduce computation using Python streaming. The presentation will also include an overview of the various components of the Hadoop "ecosystem."
NYC Data Science Academy is excited to welcome Sam Kamin who will be presenting an Introduction to Hadoop for Python Programmers a well as a discussion of MapReduce with Streaming Python.
Sam Kamin was a professor in the University of Illinois Computer Science Department. His research was in programming languages, high-performance computing, and educational technology. He taught a wide variety of courses, and served as the Director of Undergraduate Programs. He retired as Emeritus Associate Professor, and worked at Google until taking his current position as VP of Data Engineering in NYC Data Science Academy.
--------------------------------------
Our fall 12-Week Data Science bootcamp starts on Sept 21st,2015. Apply now to get a spot!
If you are hiring Data Scientists, call us at (1)888-752-7585 or reach info@nycdatascience.com to share your openings and set up interviews with our excellent students.
Kaggle Top1% Solution: Predicting Housing Prices in Moscow Vivian S. Zhang
This project was completed by students graduated from NYC Data Science Academy 12-week Data Science Bootcamp. Learn more about the bootcamp: http://nycdatascience.com/data-science-bootcamp/
Watch the project presentation: https://youtu.be/W530d2ZdbJE
Ranked #15 out of 3,274 teams on Kaggle Team Members - Brandy Freitas, Chase Edge and Grant Webb
Given 4 years of housing price data in a foreign market, predicting the following year’s prices should be pretty straightforward, right? But what if in that last year of data, the country’s stock market, the value of its currency and the price of its number 1 export, all dropped by nearly 50%. And on top of all that, the country was slapped with economic sanctions by the EU and the US. This was Moscow in 2014 and as you can see, it was anything but straightforward.
We were able to overcome these challenges and in the two weeks of working together, were able to achieve a top 1% ranking on Kaggle. Our success is a product of our in depth data cleaning, feature engineering and our approach to modeling. With a focus on interpretability and simplicity, we begin modeling using linear regression and decision trees which gave us a better understanding of the data. We then utilized more complicated models such as random forests and XGBoost which ultimately resulted in our top submission.
In this article you will learn hot to use tensorflow Softmax Classifier estimator to classify MNIST dataset in one script.
This paper introduces also the basic idea of a artificial neural network.
"Optimization of a .NET application- is it simple ! / ?", Yevhen TatarynovFwdays
Optimization of .NET application seems complex and tied full task, but don’t hurry up with conclusions. Let’s look on several cases from real projects.
For this we:
look under the hood of an application from a real project;
define the metric for optimization;
choose the necessary tools;
find bottlenecks /memory leaks and best practice to resolve them.
We'll improve the application step by step and we’ll what with simple analysis and simple best practice we can significantly reduce total resources usage.
Mobility insights at Swisscom - Understanding collective mobility in SwitzerlandFrançois Garillot
Swisscom is the leading mobile-service provider in Switzerland, with a market share high enough to enable us to model and understand the collective mobility in every area of the country. To accomplish that, we built an urban planning tool that helps cities better manage their infrastructure based on data-based insights, produced with Apache Spark, YARN, Kafka and a good dose of machine learning. In this talk, we will explain how building such a tool involves mining a massive amount of raw data (1.5E9 records/day) to extract fine-grained mobility features from raw network traces. These features are obtained using different machine learning algorithms. For example, we built an algorithm that segments a trajectory into mobile and static periods and trained classifiers that enable us to distinguish between different means of transport. As we sketch the different algorithmic components, we will present our approach to continuously run and test them, which involves complex pipelines managed with Oozie and fuelled with ground truth data. Finally, we will delve into the streaming part of our analytics and see how network events allow Swisscom to understand the characteristics of the flow of people on roads and paths of interest. This requires making a link between network coverage information and geographical positioning in the space of milliseconds and using Spark streaming with libraries that were originally designed for batch processing. We will conclude on the advantages and pitfalls of Spark involved in running this kind of pipeline on a multi-tenant cluster. Audiences should come back from this talk with an overall picture of the use of Apache Spark and related components of its ecosystem in the field of trajectory mining.
This tutor introduces the basic idea of machine learning with a very simple example. Machine learning teaches machines (and me too) to learn to carry out tasks and concepts by themselves. It is that simple, so here is an overview:
http://www.softwareschule.ch/examples/machinelearning.jpg
Feature Engineering - Getting most out of data for predictive models - TDC 2017Gabriel Moreira
How should data be preprocessed for use in machine learning algorithms? How to identify the most predictive attributes of a dataset? What features can generate to improve the accuracy of a model?
Feature Engineering is the process of extracting and selecting, from raw data, features that can be used effectively in predictive models. As the quality of the features greatly influences the quality of the results, knowing the main techniques and pitfalls will help you to succeed in the use of machine learning in your projects.
In this talk, we will present methods and techniques that allow us to extract the maximum potential of the features of a dataset, increasing flexibility, simplicity and accuracy of the models. The analysis of the distribution of features and their correlations, the transformation of numeric attributes (such as scaling, normalization, log-based transformation, binning), categorical attributes (such as one-hot encoding, feature hashing, Temporal (date / time), and free-text attributes (text vectorization, topic modeling).
Python, Python, Scikit-learn, and Spark SQL examples will be presented and how to use domain knowledge and intuition to select and generate features relevant to predictive models.
Metric learning is an area of machine learning which aims to learn a distance (or similarity) measure between samples for a given task. In this presentation, I will start by briefly introducing the main ideas of metric learning and some of its applications, and show a concrete example of using metric-learn, the metric learning library in Python. I will then highlight the importance of making a machine learning package compatible with scikit-learn and discuss the challenges in the specific case of metric-learn, in particular regarding API constraints. Finally, we will dig into metric-learn's code to illustrate the main design choices, and emphasize some general issues (such as test design) that require special care when developing a machine learning toolbox.
https://github.com/metric-learn/metric-learn
The basic concept for the data structure.
It covers these topics
System Life Cycle
Algorithm Specification
Data Abstraction
Performance Analysis
Space Complexity
Time Complexity
Asymptotic Notation
Text Book: Fundamentals of Data Structures in C++
E. Horowitz, et al.
No more struggles with Apache Spark workloads in productionChetan Khatri
Paris Scala Group Event May 2019, No more struggles with Apache Spark workloads in production.
Apache Spark
Primary data structures (RDD, DataSet, Dataframe)
Pragmatic explanation - executors, cores, containers, stage, job, a task in Spark.
Parallel read from JDBC: Challenges and best practices.
Bulk Load API vs JDBC write
An optimization strategy for Joins: SortMergeJoin vs BroadcastHashJoin
Avoid unnecessary shuffle
Alternative to spark default sort
Why dropDuplicates() doesn’t result consistency, What is alternative
Optimize Spark stage generation plan
Predicate pushdown with partitioning and bucketing
Why not to use Scala Concurrent ‘Future’ explicitly!
Lab 2: Classification and Regression Prediction Models, training and testing ...Yao Yao
https://github.com/yaowser/data_mining_group_project
https://www.kaggle.com/c/zillow-prize-1/data
From the Zillow real estate data set of properties in the southern California area, conduct the following data cleaning, data analysis, predictive analysis, and machine learning algorithms:
Lab 2: Classification and Regression Prediction Models, training and testing splits, optimization of K Nearest Neighbors (KD tree), optimization of Random Forest, optimization of Naive Bayes (Gaussian), advantages and model comparisons, feature importance, Feature ranking with recursive feature elimination, Two dimensional Linear Discriminant Analysis
This tutor shows the train and test set split with binary classifying, clustering and 3D plots and discuss a probability density function in scikit-learn on synthetic datasets. The dataset is very simple as a reference of understanding.
Similar to Kaggle Winning Solution Xgboost algorithm -- Let us learn from its author (20)
This document list the reasons why our past alumni chose NYC Data Science Academy over other programs.
Machine Learning Bootcamp is our flagship program and well received by our community.
Nyc open-data-2015-andvanced-sklearn-expandedVivian S. Zhang
Scikit-learn is a machine learning library in Python, that has become a valuable tool for many data science practitioners.
This talk will cover some of the more advanced aspects of scikit-learn, such as building complex machine learning pipelines, model evaluation, parameter search, and out-of-core learning.
Apart from metrics for model evaluation, we will cover how to evaluate model complexity, and how to tune parameters with grid search, randomized parameter search, and what their trade-offs are. We will also cover out of core text feature processing via feature hashing.
---------------------------------------------------------
Andreas is an Assistant Research Scientist at the NYU Center for Data Science, building a group to work on open source software for data science. Previously he worked as a Machine Learning Scientist at Amazon, working on computer vision and forecasting problems. He is one of the core developers of the scikit-learn machine learning library, and maintained it for several years.
Material will be posted here:
https://github.com/amueller/pydata-nyc-advanced-sklearn
Blog:
peekaboo-vision.blogspot.com
Twitter:
https://twitter.com/t3kcit
Twitter: @NycDataSci
Learn with our NYC Data Science Program (weekend courses for working professionals and 12 week full time for whom are advancing their career into Data Science)
Our next 12-Week Data Science Bootcamp starts in Jun. (Deadline to apply is May 1st, all decisions will be made by May 15th.)
====================================
Max Kuhn, Director is Nonclinical Statistics of Pfizer and also the author of Applied Predictive Modeling.
He will join us and share his experience with Data Mining with R.
Max is a nonclinical statistician who has been applying predictive models in the diagnostic and pharmaceutical industries for over 15 years. He is the author and maintainer for a number of predictive modeling packages, including: caret, C50, Cubist and AppliedPredictiveModeling. He blogs about the practice of modeling on his website at ttp://appliedpredictivemodeling.com/blog
---------------------------------------------------------
His Feb 18th course can be RSVP at NYC Data Science Academy.
Syllabus
Predictive Modeling using R
Description
This class will get attendees up to speed in predictive modeling using the R programming language. The goal of the course is to understand the general predictive modeling process and how it can be implemented in R. A selection of important models (e.g. tree-based models, support vector machines) will be described in an intuitive manner to illustrate the process of training and evaluating models.
Prerequisites:
Attendees should have a working knowledge of basic R data structures (e.g. data frames, factors etc) and language fundamentals such as functions and subsetting data. Understanding of the content contained in Appendix B sections B1 though B8 of Applied Predictive Modeling (free PDF from publisher [1]) should suffice.
Outline:
- An introduction to predictive modeling
- R and predictive modeling: the good and bad
- Illustrative example
- Measuring performance
- Data splitting and resampling
- Data pre-processing
- Classification trees
- Boosted trees
- Support vector machines
If time allows, the following topics will also be covered
- Parallel processing
- Comparing models
- Feature selection
- Common pitfalls
Materials:
Attendees will be provided with a copy of Applied Predictive Modeling[2] as well as course notes, code and raw data. Participants will be able to reproduce the examples described in the workshop.
Attendees should have a computer with a relatively recent version of R installed.
About the Instructor:
More about Max's work:
[1] http://rd.springer.com/content/pdf/bbm%3A978-1-4614-6849-3%2F1.pdf
[2] http://appliedpredictivemodeling.com
R003 laila restaurant sanitation report(NYC Data Science Academy, Data Scienc...Vivian S. Zhang
NYC Data Science Academy, Data Science by R Intensive Beginner level, R003 student, Laila, presented on restaurant sanitation report using NYC Open Data Set, see her blog post at http://nycdatascience.com/2014/05/pizza-everyone-loves-pizza/
R003 jiten south park episode popularity analysis(NYC Data Science Academy, D...Vivian S. Zhang
NYC Data Science Academy, Data Science by R Intensive Beginner level, R003 student, Jiten presented how he scrapped dataset and did south park episode popularity analysis.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Honest Reviews of Tim Han LMA Course Program.pptxtimhan337
Personal development courses are widely available today, with each one promising life-changing outcomes. Tim Han’s Life Mastery Achievers (LMA) Course has drawn a lot of interest. In addition to offering my frank assessment of Success Insider’s LMA Course, this piece examines the course’s effects via a variety of Tim Han LMA course reviews and Success Insider comments.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
4. 8/30/15, 10:09 PMXGBoost
Page 4 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Introduction
Nowadays we have plenty of machine learning models. Those most well-knowns are
Linear/Logistic Regression
k-Nearest Neighbours
Support Vector Machines
Tree-based Model
Neural Networks
·
·
·
·
Decision Tree
Random Forest
Gradient Boosting Machine
-
-
-
·
4/128
5. 8/30/15, 10:09 PMXGBoost
Page 5 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Introduction
XGBoost is short for eXtreme Gradient Boosting. It is
An open-sourced tool
A variant of the gradient boosting machine
The winning model for several kaggle competitions
·
Computation in C++
R/python/Julia interface provided
-
-
·
Tree-based model-
·
5/128
6. 8/30/15, 10:09 PMXGBoost
Page 6 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Introduction
XGBoost is currently host on github.
The primary author of the model and the c++ implementation is Tianqi Chen.
The author for the R-package is Tong He.
·
·
6/128
7. 8/30/15, 10:09 PMXGBoost
Page 7 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Introduction
XGBoost is widely used for kaggle competitions. The reason to choose XGBoost includes
Easy to use
Efficiency
Accuracy
Feasibility
·
Easy to install.
Highly developed R/python interface for users.
-
-
·
Automatic parallel computation on a single machine.
Can be run on a cluster.
-
-
·
Good result for most data sets.-
·
Customized objective and evaluation
Tunable parameters
-
-
7/128
8. 8/30/15, 10:09 PMXGBoost
Page 8 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Basic Walkthrough
We introduce the R package for XGBoost. To install, please run
This command downloads the package from github and compile it automatically on your
machine. Therefore we need RTools installed on Windows.
devtools::install_github('dmlc/xgboost',subdir='R-package')
8/128
9. 8/30/15, 10:09 PMXGBoost
Page 9 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Basic Walkthrough
XGBoost provides a data set to demonstrate its usages.
This data set includes the information for some kinds of mushrooms. The features are binary,
indicate whether the mushroom has this characteristic. The target variable is whether they are
poisonous.
require(xgboost)
## Loading required package: xgboost
data(agaricus.train, package='xgboost')
data(agaricus.test, package='xgboost')
train = agaricus.train
test = agaricus.test
9/128
10. 8/30/15, 10:09 PMXGBoost
Page 10 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Basic Walkthrough
Let's investigate the data first.
We can see that the data is a dgCMatrix class object. This is a sparse matrix class from the
package Matrix. Sparse matrix is more memory efficient for some specific data.
str(train$data)
## Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
## ..@ i : int [1:143286] 2 6 8 11 18 20 21 24 28 32 ...
## ..@ p : int [1:127] 0 369 372 3306 5845 6489 6513 8380 8384 10991 ...
## ..@ Dim : int [1:2] 6513 126
## ..@ Dimnames:List of 2
## .. ..$ : NULL
## .. ..$ : chr [1:126] "cap-shape=bell" "cap-shape=conical" "cap-shape=convex" "cap-shape=fla
## ..@ x : num [1:143286] 1 1 1 1 1 1 1 1 1 1 ...
## ..@ factors : list()
10/128
11. 8/30/15, 10:09 PMXGBoost
Page 11 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Basic Walkthrough
To use XGBoost to classify poisonous mushrooms, the minimum information we need to
provide is:
1. Input features
2. Target variable
3. Objective
4. Number of iteration
XGBoost allows dense and sparse matrix as the input.·
A numeric vector. Use integers starting from 0 for classification, or real values for
regression
·
For regression use 'reg:linear'
For binary classification use 'binary:logistic'
·
·
The number of trees added to the model·
11/128
12. 8/30/15, 10:09 PMXGBoost
Page 12 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Basic Walkthrough
To run XGBoost, we can use the following command:
The output is the classification error on the training data set.
bst = xgboost(data = train$data, label = train$label,
nround = 2, objective = "binary:logistic")
## [0] train-error:0.000614
## [1] train-error:0.001228
12/128
13. 8/30/15, 10:09 PMXGBoost
Page 13 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Basic Walkthrough
Sometimes we might want to measure the classification by 'Area Under the Curve':
bst = xgboost(data = train$data, label = train$label, nround = 2,
objective = "binary:logistic", eval_metric = "auc")
## [0] train-auc:0.999238
## [1] train-auc:0.999238
13/128
14. 8/30/15, 10:09 PMXGBoost
Page 14 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Basic Walkthrough
To predict, you can simply write
pred = predict(bst, test$data)
head(pred)
## [1] 0.2582498 0.7433221 0.2582498 0.2582498 0.2576509 0.2750908
14/128
15. 8/30/15, 10:09 PMXGBoost
Page 15 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Basic Walkthrough
Cross validation is an important method to measure the model's predictive power, as well as
the degree of overfitting. XGBoost provides a convenient function to do cross validation in a line
of code.
Notice the difference of the arguments between xgb.cv and xgboost is the additional nfold
parameter. To perform cross validation on a certain set of parameters, we just need to copy
them to the xgb.cv function and add the number of folds.
cv.res = xgb.cv(data = train$data, nfold = 5, label = train$label, nround = 2,
objective = "binary:logistic", eval_metric = "auc")
## [0] train-auc:0.998668+0.000354 test-auc:0.998497+0.001380
## [1] train-auc:0.999187+0.000785 test-auc:0.998700+0.001536
15/128
16. 8/30/15, 10:09 PMXGBoost
Page 16 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Basic Walkthrough
xgb.cv returns a data.table object containing the cross validation results. This is helpful for
choosing the correct number of iterations.
cv.res
## train.auc.mean train.auc.std test.auc.mean test.auc.std
## 1: 0.998668 0.000354 0.998497 0.001380
## 2: 0.999187 0.000785 0.998700 0.001536
16/128
18. 8/30/15, 10:09 PMXGBoost
Page 18 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Higgs Boson Competition
The debut of XGBoost was in the higgs boson competition.
Tianqi introduced the tool along with a benchmark code which achieved the top 10% at the
beginning of the competition.
To the end of the competition, it was already the mostly used tool in that competition.
18/128
19. 8/30/15, 10:09 PMXGBoost
Page 19 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Higgs Boson Competition
XGBoost offers the script on github.
To run the script, prepare a data directory and download the competition data into this
directory.
19/128
20. 8/30/15, 10:09 PMXGBoost
Page 20 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Higgs Boson Competition
Firstly we prepare the environment
require(xgboost)
require(methods)
testsize = 550000
20/128
21. 8/30/15, 10:09 PMXGBoost
Page 21 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Higgs Boson Competition
Then we can read in the data
dtrain = read.csv("data/training.csv", header=TRUE)
dtrain[33] = dtrain[33] == "s"
label = as.numeric(dtrain[[33]])
data = as.matrix(dtrain[2:31])
weight = as.numeric(dtrain[[32]]) * testsize / length(label)
sumwpos <- sum(weight * (label==1.0))
sumwneg <- sum(weight * (label==0.0))
21/128
22. 8/30/15, 10:09 PMXGBoost
Page 22 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Higgs Boson Competition
The data contains missing values and they are marked as -999. We can construct an
xgb.DMatrix object containing the information of weight and missing.
xgmat = xgb.DMatrix(data, label = label, weight = weight, missing = -999.0)
22/128
23. 8/30/15, 10:09 PMXGBoost
Page 23 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Higgs Boson Competition
Next step is to set the basic parameters
param = list("objective" = "binary:logitraw",
"scale_pos_weight" = sumwneg / sumwpos,
"bst:eta" = 0.1,
"bst:max_depth" = 6,
"eval_metric" = "auc",
"eval_metric" = "ams@0.15",
"silent" = 1,
"nthread" = 16)
23/128
24. 8/30/15, 10:09 PMXGBoost
Page 24 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Higgs Boson Competition
We then start the training step
bst = xgboost(params = param, data = xgmat, nround = 120)
24/128
25. 8/30/15, 10:09 PMXGBoost
Page 25 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Higgs Boson Competition
Then we read in the test data
dtest = read.csv("data/test.csv", header=TRUE)
data = as.matrix(dtest[2:31])
xgmat = xgb.DMatrix(data, missing = -999.0)
25/128
26. 8/30/15, 10:09 PMXGBoost
Page 26 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Higgs Boson Competition
We now can make prediction on the test data set.
ypred = predict(bst, xgmat)
26/128
27. 8/30/15, 10:09 PMXGBoost
Page 27 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Higgs Boson Competition
Finally we output the prediction according to the required format.
Please submit the result to see your performance :)
rorder = rank(ypred, ties.method="first")
threshold = 0.15
ntop = length(rorder) - as.integer(threshold*length(rorder))
plabel = ifelse(rorder > ntop, "s", "b")
outdata = list("EventId" = idx,
"RankOrder" = rorder,
"Class" = plabel)
write.csv(outdata, file = "submission.csv", quote=FALSE, row.names=FALSE)
27/128
28. 8/30/15, 10:09 PMXGBoost
Page 28 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Higgs Boson Competition
Besides the good performace, the efficiency is also a highlight of XGBoost.
The following plot shows the running time result on the Higgs boson data set.
28/128
29. 8/30/15, 10:09 PMXGBoost
Page 29 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Higgs Boson Competition
After some feature engineering and parameter tuning, one can achieve around 25th with a
single model on the leaderboard. This is an article written by a former-physist introducing his
solution with a single XGboost model:
https://no2147483647.wordpress.com/2014/09/17/winning-solution-of-kaggle-higgs-
competition-what-a-single-model-can-do/
On our post-competition attempts, we achieved 11th on the leaderboard with a single XGBoost
model.
29/128
31. 8/30/15, 10:09 PMXGBoost
Page 31 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Training Objective
To understand other parameters, one need to have a basic understanding of the model behind.
Suppose we have trees, the model is
where each is the prediction from a decision tree. The model is a collection of decision trees.
K
∑
k=1
K
fk
fk
31/128
32. 8/30/15, 10:09 PMXGBoost
Page 32 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Training Objective
Having all the decision trees, we make prediction by
where is the feature vector for the -th data point.
Similarly, the prediction at the -th step can be defined as
= ( )yiˆ
∑
k=1
K
fk xi
xi i
t
= ( )yiˆ (t)
∑
k=1
t
fk xi
32/128
33. 8/30/15, 10:09 PMXGBoost
Page 33 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Training Objective
To train the model, we need to optimize a loss function.
Typically, we use
Rooted Mean Squared Error for regression
LogLoss for binary classification
mlogloss for multi-classification
·
- L = ( −1
N
∑N
i=1 yi yiˆ )2
·
- L = − ( log( ) + (1 − ) log(1 − ))1
N
∑N
i=1 yi pi yi pi
·
- L = − log( )1
N
∑N
i=1 ∑M
j=1 yi,j pi,j
33/128
34. 8/30/15, 10:09 PMXGBoost
Page 34 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Training Objective
Regularization is another important part of the model. A good regularization term controls the
complexity of the model which prevents overfitting.
Define
where is the number of leaves, and is the score on the -th leaf.
Ω = γT + λ
1
2 ∑
j=1
T
w2
j
T w2
j j
34/128
35. 8/30/15, 10:09 PMXGBoost
Page 35 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Training Objective
Put loss function and regularization together, we have the objective of the model:
where loss function controls the predictive power, and regularization controls the simplicity.
Obj = L + Ω
35/128
36. 8/30/15, 10:09 PMXGBoost
Page 36 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Training Objective
In XGBoost, we use gradient descent to optimize the objective.
Given an objective to optimize, gradient descent is an iterative technique which
calculate
at each iteration. Then we improve along the direction of the gradient to minimize the
objective.
Obj(y, )yˆ
Obj(y, )∂yˆ yˆ
yˆ
36/128
37. 8/30/15, 10:09 PMXGBoost
Page 37 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Training Objective
Recall the definition of objective . For a iterative algorithm we can re-define the
objective function as
To optimize it by gradient descent, we need to calculate the gradient. The performance can also
be improved by considering both the first and the second order gradient.
Obj = L + Ω
Ob = L( , ) + Ω( ) = L( , + ( )) + Ω( )j(t)
∑
i=1
N
yi yˆ(t)
i ∑
i=1
t
fi ∑
i=1
N
yi yiˆ (t−1)
ft xi
∑
i=1
t
fi
Ob∂yiˆ (t) j(t)
Ob∂2
yiˆ (t) j(t)
37/128
38. 8/30/15, 10:09 PMXGBoost
Page 38 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Training Objective
Since we don't have derivative for every objective function, we calculate the second order taylor
approximation of it
where
Ob ≃ [L( , ) + ( ) + ( )] + Ω( )j(t)
∑
i=1
N
yi yˆ(t−1)
gift xi
1
2
hif 2
t xi
∑
i=1
t
fi
· = l( , )gi ∂yˆ(t−1) yi yˆ(t−1)
· = l( , )hi ∂2
yˆ(t−1) yi yˆ(t−1)
38/128
39. 8/30/15, 10:09 PMXGBoost
Page 39 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Training Objective
Remove the constant terms, we get
This is the objective at the -th step. Our goal is to find a to optimize it.
Ob = [ ( ) + ( )] + Ω( )j(t)
∑
i=1
n
gift xi
1
2
hif 2
t xi ft
t ft
39/128
40. 8/30/15, 10:09 PMXGBoost
Page 40 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Tree Building Algorithm
The tree structures in XGBoost leads to the core problem:
how can we find a tree that improves the prediction along the gradient?
40/128
41. 8/30/15, 10:09 PMXGBoost
Page 41 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Tree Building Algorithm
Every decision tree looks like this
Each data point flows to one of the leaves following the direction on each node.
41/128
42. 8/30/15, 10:09 PMXGBoost
Page 42 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Tree Building Algorithm
The core concepts are:
Internal Nodes
Leaves
·
Each internal node split the flow of data points by one of the features.
The condition on the edge specifies what data can flow through.
-
-
·
Data points reach to a leaf will be assigned a weight.
The weight is the prediction.
-
-
42/128
43. 8/30/15, 10:09 PMXGBoost
Page 43 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Tree Building Algorithm
Two key questions for building a decision tree are
1. How to find a good structure?
2. How to assign prediction score?
We want to solve these two problems with the idea of gradient descent.
43/128
44. 8/30/15, 10:09 PMXGBoost
Page 44 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Tree Building Algorithm
Let us assume that we already have the solution to question 1.
We can mathematically define a tree as
where is a "directing" function which assign every data point to the -th leaf.
This definition describes the prediction process on a tree as
(x) =ft wq(x)
q(x) q(x)
Assign the data point to a leaf by
Assign the corresponding score on the -th leaf to the data point.
· x q
· wq(x) q(x)
44/128
45. 8/30/15, 10:09 PMXGBoost
Page 45 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Tree Building Algorithm
Define the index set
This set contains the indices of data points that are assigned to the -th leaf.
= {i|q( ) = j}Ij xi
j
45/128
46. 8/30/15, 10:09 PMXGBoost
Page 46 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Tree Building Algorithm
Then we rewrite the objective as
Since all the data points on the same leaf share the same prediction, this form sums the
prediction by leaves.
Ob = [ ( ) + ( )] + γT + λj(t)
∑
i=1
n
gift xi
1
2
hif 2
t xi
1
2 ∑
j=1
T
w2
j
= [( ) + ( + λ) ] + γT
∑
j=1
T
∑
i∈Ij
gi wj
1
2 ∑
i∈Ij
hi w2
j
46/128
47. 8/30/15, 10:09 PMXGBoost
Page 47 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Tree Building Algorithm
It is a quadratic problem of , so it is easy to find the best to optimize .
The corresponding value of is
wj wj Obj
= −w∗
j
∑i∈Ij
gi
+ λ∑i∈Ij
hi
Obj
Ob = − + γTj(t) 1
2 ∑
j=1
T (∑i∈Ij
gi)2
+ λ∑i∈Ij
hi
47/128
48. 8/30/15, 10:09 PMXGBoost
Page 48 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Tree Building Algorithm
The leaf score
relates to
= −wj
∑i∈Ij
gi
+ λ∑i∈Ij
hi
The first and second order of the loss function and
The regularization parameter
· g h
· λ
48/128
49. 8/30/15, 10:09 PMXGBoost
Page 49 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Tree Building Algorithm
Now we come back to the first question: How to find a good structure?
We can further split it into two sub-questions:
1. How to choose the feature to split?
2. When to stop the split?
49/128
50. 8/30/15, 10:09 PMXGBoost
Page 50 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Tree Building Algorithm
In each split, we want to greedily find the best splitting point that can optimize the objective.
For each feature
1. Sort the numbers
2. Scan the best splitting point.
3. Choose the best feature.
50/128
51. 8/30/15, 10:09 PMXGBoost
Page 51 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Tree Building Algorithm
Now we give a definition to "the best split" by the objective.
Everytime we do a split, we are changing a leaf into a internal node.
51/128
52. 8/30/15, 10:09 PMXGBoost
Page 52 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Tree Building Algorithm
Let
Recall the best value of objective on the -th leaf is
be the set of indices of data points assigned to this node
and be the sets of indices of data points assigned to two new leaves.
· I
· IL IR
j
Ob = − + γj(t) 1
2
(∑i∈Ij
gi)2
+ λ∑i∈Ij
hi
52/128
53. 8/30/15, 10:09 PMXGBoost
Page 53 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Tree Building Algorithm
The gain of the split is
gain =
[
+ −
]
− γ
1
2
(∑i∈IL
gi)2
+ λ∑i∈IL
hi
(∑i∈IR
gi)2
+ λ∑i∈IR
hi
(∑i∈I gi)2
+ λ∑i∈I hi
53/128
54. 8/30/15, 10:09 PMXGBoost
Page 54 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Tree Building Algorithm
To build a tree, we find the best splitting point recursively until we reach to the maximum
depth.
Then we prune out the nodes with a negative gain in a bottom-up order.
54/128
55. 8/30/15, 10:09 PMXGBoost
Page 55 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Tree Building Algorithm
XGBoost can handle missing values in the data.
For each node, we guide all the data points with a missing value
Finally every node has a "default direction" for missing values.
to the left subnode, and calculate the maximum gain
to the right subnode, and calculate the maximum gain
Choose the direction with a larger gain
·
·
·
55/128
56. 8/30/15, 10:09 PMXGBoost
Page 56 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Tree Building Algorithm
To sum up, the outline of the algorithm is
Iterate for nround times·
Grow the tree to the maximun depth
Prune the tree to delete nodes with negative gain
-
Find the best splitting point
Assign weight to the two new leaves
-
-
-
56/128
58. 8/30/15, 10:09 PMXGBoost
Page 58 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Parameter Introduction
XGBoost has plenty of parameters. We can group them into
1. General parameters
2. Booster parameters
3. Task parameters
Number of threads·
Stepsize
Regularization
·
·
Objective
Evaluation metric
·
·
58/128
59. 8/30/15, 10:09 PMXGBoost
Page 59 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Parameter Introduction
After the introduction of the model, we can understand the parameters provided in XGBoost.
To check the parameter list, one can look into
The documentation of xgb.train.
The documentation in the repository.
·
·
59/128
60. 8/30/15, 10:09 PMXGBoost
Page 60 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Parameter Introduction
General parameters:
nthread
booster
·
Number of parallel threads.-
·
gbtree: tree-based model.
gblinear: linear function.
-
-
60/128
61. 8/30/15, 10:09 PMXGBoost
Page 61 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Parameter Introduction
Parameter for Tree Booster
eta
gamma
·
Step size shrinkage used in update to prevents overfitting.
Range in [0,1], default 0.3
-
-
·
Minimum loss reduction required to make a split.
Range [0, ], default 0
-
- ∞
61/128
62. 8/30/15, 10:09 PMXGBoost
Page 62 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Parameter Introduction
Parameter for Tree Booster
max_depth
min_child_weight
max_delta_step
·
Maximum depth of a tree.
Range [1, ], default 6
-
- ∞
·
Minimum sum of instance weight needed in a child.
Range [0, ], default 1
-
- ∞
·
Maximum delta step we allow each tree's weight estimation to be.
Range [0, ], default 0
-
- ∞
62/128
63. 8/30/15, 10:09 PMXGBoost
Page 63 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Parameter Introduction
Parameter for Tree Booster
subsample
colsample_bytree
·
Subsample ratio of the training instance.
Range (0, 1], default 1
-
-
·
Subsample ratio of columns when constructing each tree.
Range (0, 1], default 1
-
-
63/128
64. 8/30/15, 10:09 PMXGBoost
Page 64 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Parameter Introduction
Parameter for Linear Booster
lambda
alpha
lambda_bias
·
L2 regularization term on weights
default 0
-
-
·
L1 regularization term on weights
default 0
-
-
·
L2 regularization term on bias
default 0
-
-
64/128
65. 8/30/15, 10:09 PMXGBoost
Page 65 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Parameter Introduction
Objectives·
"reg:linear": linear regression, default option.
"binary:logistic": logistic regression for binary classification, output probability
"multi:softmax": multiclass classification using the softmax objective, need to specify
num_class
User specified objective
-
-
-
-
65/128
67. 8/30/15, 10:09 PMXGBoost
Page 67 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Guide on Parameter Tuning
It is nearly impossible to give a set of universal optimal parameters, or a global algorithm
achieving it.
The key points of parameter tuning are
Control Overfitting
Deal with Imbalanced data
Trust the cross validation
·
·
·
67/128
68. 8/30/15, 10:09 PMXGBoost
Page 68 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Guide on Parameter Tuning
The "Bias-Variance Tradeoff", or the "Accuracy-Simplicity Tradeoff" is the main idea for
controlling overfitting.
For the booster specific parameters, we can group them as
Controlling the model complexity
Robust to noise
·
max_depth, min_child_weight and gamma-
·
subsample, colsample_bytree-
68/128
69. 8/30/15, 10:09 PMXGBoost
Page 69 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Guide on Parameter Tuning
Sometimes the data is imbalanced among classes.
Only care about the ranking order
Care about predicting the right probability
·
Balance the positive and negative weights, by scale_pos_weight
Use "auc" as the evaluation metric
-
-
·
Cannot re-balance the dataset
Set parameter max_delta_step to a finite number (say 1) will help convergence
-
-
69/128
70. 8/30/15, 10:09 PMXGBoost
Page 70 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Guide on Parameter Tuning
To select ideal parameters, use the result from xgb.cv.
Trust the score for the test
Use early.stop.round to detect continuously being worse on test set.
If overfitting observed, reduce stepsize eta and increase nround at the same time.
·
·
·
70/128
72. 8/30/15, 10:09 PMXGBoost
Page 72 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Advanced Features
There are plenty of highlights in XGBoost:
Customized objective and evaluation metric
Prediction from cross validation
Continue training on existing model
Calculate and plot the variable importance
·
·
·
·
72/128
73. 8/30/15, 10:09 PMXGBoost
Page 73 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Customization
According to the algorithm, we can define our own loss function, as long as we can calculate the
first and second order gradient of the loss function.
Define and . We can optimize the loss function if we can calculate
these two values.
grad = l∂yt−1 hess = l∂2
yt−1
73/128
74. 8/30/15, 10:09 PMXGBoost
Page 74 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Customization
We can rewrite logloss for the -th data point as
The is calculated by applying logistic transformation on our prediction .
Then the logloss is
i
L = log( ) + (1 − ) log(1 − )yi pi yi pi
pi yˆi
L = log + (1 − ) logyi
1
1 + e−yˆi
yi
e−yˆi
1 + e−yˆi
74/128
75. 8/30/15, 10:09 PMXGBoost
Page 75 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Customization
We can see that
Next we translate them into the code.
· grad = − = −1
1+e−yˆi
yi pi yi
· hess = = (1 − )1+e−yˆi
(1+e−yˆi )2
pi pi
75/128
77. 8/30/15, 10:09 PMXGBoost
Page 77 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Customization
The complete code:
logregobj = function(preds, dtrain) {
# Extract the true label from the second argument
labels = getinfo(dtrain, "label")
preds = 1/(1 + exp(-preds))
grad = preds - labels
hess = preds * (1 - preds)
return(list(grad = grad, hess = hess))
}
77/128
78. 8/30/15, 10:09 PMXGBoost
Page 78 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Customization
The complete code:
logregobj = function(preds, dtrain) {
# Extract the true label from the second argument
labels = getinfo(dtrain, "label")
# apply logistic transformation to the output
preds = 1/(1 + exp(-preds))
grad = preds - labels
hess = preds * (1 - preds)
return(list(grad = grad, hess = hess))
}
78/128
79. 8/30/15, 10:09 PMXGBoost
Page 79 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Customization
The complete code:
logregobj = function(preds, dtrain) {
# Extract the true label from the second argument
labels = getinfo(dtrain, "label")
# apply logistic transformation to the output
preds = 1/(1 + exp(-preds))
# Calculate the 1st gradient
grad = preds - labels
hess = preds * (1 - preds)
return(list(grad = grad, hess = hess))
}
79/128
80. 8/30/15, 10:09 PMXGBoost
Page 80 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Customization
The complete code:
logregobj = function(preds, dtrain) {
# Extract the true label from the second argument
labels = getinfo(dtrain, "label")
# apply logistic transformation to the output
preds = 1/(1 + exp(-preds))
# Calculate the 1st gradient
grad = preds - labels
# Calculate the 2nd gradient
hess = preds * (1 - preds)
return(list(grad = grad, hess = hess))
}
80/128
81. 8/30/15, 10:09 PMXGBoost
Page 81 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Customization
The complete code:
logregobj = function(preds, dtrain) {
# Extract the true label from the second argument
labels = getinfo(dtrain, "label")
# apply logistic transformation to the output
preds = 1/(1 + exp(-preds))
# Calculate the 1st gradient
grad = preds - labels
# Calculate the 2nd gradient
hess = preds * (1 - preds)
# Return the result
return(list(grad = grad, hess = hess))
}
81/128
82. 8/30/15, 10:09 PMXGBoost
Page 82 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Customization
We can also customize the evaluation metric.
evalerror = function(preds, dtrain) {
labels = getinfo(dtrain, "label")
err = as.numeric(sum(labels != (preds > 0)))/length(labels)
return(list(metric = "error", value = err))
}
82/128
83. 8/30/15, 10:09 PMXGBoost
Page 83 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Customization
We can also customize the evaluation metric.
evalerror = function(preds, dtrain) {
# Extract the true label from the second argument
labels = getinfo(dtrain, "label")
err = as.numeric(sum(labels != (preds > 0)))/length(labels)
return(list(metric = "error", value = err))
}
83/128
84. 8/30/15, 10:09 PMXGBoost
Page 84 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Customization
We can also customize the evaluation metric.
evalerror = function(preds, dtrain) {
# Extract the true label from the second argument
labels = getinfo(dtrain, "label")
# Calculate the error
err = as.numeric(sum(labels != (preds > 0)))/length(labels)
return(list(metric = "error", value = err))
}
84/128
85. 8/30/15, 10:09 PMXGBoost
Page 85 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Customization
We can also customize the evaluation metric.
evalerror = function(preds, dtrain) {
# Extract the true label from the second argument
labels = getinfo(dtrain, "label")
# Calculate the error
err = as.numeric(sum(labels != (preds > 0)))/length(labels)
# Return the name of this metric and the value
return(list(metric = "error", value = err))
}
85/128
86. 8/30/15, 10:09 PMXGBoost
Page 86 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Customization
To utilize the customized objective and evaluation, we simply pass them to the arguments:
param = list(max.depth=2,eta=1,nthread = 2, silent=1,
objective=logregobj, eval_metric=evalerror)
bst = xgboost(params = param, data = train$data, label = train$label, nround = 2)
## [0] train-error:0.0465223399355136
## [1] train-error:0.0222631659757408
86/128
87. 8/30/15, 10:09 PMXGBoost
Page 87 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Prediction in Cross Validation
"Stacking" is an ensemble learning technique which takes the prediction from several models. It
is widely used in many scenarios.
One of the main concern is avoid overfitting. The common way is use the prediction value from
cross validation.
XGBoost provides a convenient argument to calculate the prediction during the cross validation.
87/128
88. 8/30/15, 10:09 PMXGBoost
Page 88 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Prediction in Cross Validation
res = xgb.cv(params = param, data = train$data, label = train$label, nround = 2,
nfold=5, prediction = TRUE)
## [0] train-error:0.046522+0.001347 test-error:0.046522+0.005387
## [1] train-error:0.022263+0.000637 test-error:0.022263+0.002545
str(res)
## List of 2
## $ dt :Classes 'data.table' and 'data.frame': 2 obs. of 4 variables:
## ..$ train.error.mean: num [1:2] 0.0465 0.0223
## ..$ train.error.std : num [1:2] 0.001347 0.000637
## ..$ test.error.mean : num [1:2] 0.0465 0.0223
## ..$ test.error.std : num [1:2] 0.00539 0.00254
## ..- attr(*, ".internal.selfref")=<externalptr>
## $ pred: num [1:6513] 2.58 -1.07 -1.03 2.59 -3.03 ...
88/128
89. 8/30/15, 10:09 PMXGBoost
Page 89 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
xgb.DMatrix
XGBoost has its own class of input data xgb.DMatrix. One can convert the usual data set into
it by
It is the data structure used by XGBoost algorithm. XGBoost preprocess the input data and
label into an xgb.DMatrix object before feed it to the training algorithm.
If one need to repeat training process on the same big data set, it is good to use the
xgb.DMatrix object to save preprocessing time.
dtrain = xgb.DMatrix(data = train$data, label = train$label)
89/128
90. 8/30/15, 10:09 PMXGBoost
Page 90 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
xgb.DMatrix
An xgb.DMatrix object contains
1. Preprocessed training data
2. Several features
Missing values
data weight
·
·
90/128
91. 8/30/15, 10:09 PMXGBoost
Page 91 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Continue Training
Train the model for 5000 rounds is sometimes useful, but we are also taking the risk of
overfitting.
A better strategy is to train the model with fewer rounds and repeat that for many times. This
enable us to observe the outcome after each step.
91/128
93. 8/30/15, 10:09 PMXGBoost
Page 93 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Continue Training
# Train with only one round
bst = xgboost(params = param, data = dtrain, nround = 1)
## [0] train-error:0.0222631659757408
ptrain = predict(bst, dtrain, outputmargin = TRUE)
setinfo(dtrain, "base_margin", ptrain)
## [1] TRUE
bst = xgboost(params = param, data = dtrain, nround = 1)
## [0] train-error:0.00706279748195916
93/128
94. 8/30/15, 10:09 PMXGBoost
Page 94 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Continue Training
# Train with only one round
bst = xgboost(params = param, data = dtrain, nround = 1)
## [0] train-error:0.00706279748195916
# margin means the baseline of the prediction
ptrain = predict(bst, dtrain, outputmargin = TRUE)
setinfo(dtrain, "base_margin", ptrain)
## [1] TRUE
bst = xgboost(params = param, data = dtrain, nround = 1)
## [0] train-error:0.0152003684937817
94/128
95. 8/30/15, 10:09 PMXGBoost
Page 95 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Continue Training
# Train with only one round
bst = xgboost(params = param, data = dtrain, nround = 1)
## [0] train-error:0.0152003684937817
# margin means the baseline of the prediction
ptrain = predict(bst, dtrain, outputmargin = TRUE)
# Set the margin information to the xgb.DMatrix object
setinfo(dtrain, "base_margin", ptrain)
## [1] TRUE
bst = xgboost(params = param, data = dtrain, nround = 1)
## [0] train-error:0.00706279748195916
95/128
96. 8/30/15, 10:09 PMXGBoost
Page 96 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Continue Training
# Train with only one round
bst = xgboost(params = param, data = dtrain, nround = 1)
## [0] train-error:0.00706279748195916
# margin means the baseline of the prediction
ptrain = predict(bst, dtrain, outputmargin = TRUE)
# Set the margin information to the xgb.DMatrix object
setinfo(dtrain, "base_margin", ptrain)
## [1] TRUE
# Train based on the previous result
bst = xgboost(params = param, data = dtrain, nround = 1)
## [0] train-error:0.00122831260555811
96/128
97. 8/30/15, 10:09 PMXGBoost
Page 97 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Importance and Tree plotting
The result of XGBoost contains many trees. We can count the number of appearance of each
variable in all the trees, and use this number as the importance score.
bst = xgboost(data = train$data, label = train$label, max.depth = 2, verbose = FALSE,
eta = 1, nthread = 2, nround = 2,objective = "binary:logistic")
xgb.importance(train$dataDimnames[[2]], model = bst)
## Feature Gain Cover Frequence
## 1: 28 0.67615484 0.4978746 0.4
## 2: 55 0.17135352 0.1920543 0.2
## 3: 59 0.12317241 0.1638750 0.2
## 4: 108 0.02931922 0.1461960 0.2
97/128
98. 8/30/15, 10:09 PMXGBoost
Page 98 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Importance and Tree plotting
We can also plot the trees in the model by xgb.plot.tree.
xgb.plot.tree(agaricus.train$data@Dimnames[[2]], model = bst)
98/128
100. 8/30/15, 10:09 PMXGBoost
Page 100 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Early Stopping
When doing cross validation, it is usual to encounter overfitting at a early stage of iteration.
Sometimes the prediction gets worse consistantly from round 300 while the total number of
iteration is 1000. To stop the cross validation process, one can use the early.stop.round
argument in xgb.cv.
bst = xgb.cv(params = param, data = train$data, label = train$label,
nround = 20, nfold = 5,
maximize = FALSE, early.stop.round = 3)
100/128
103. 8/30/15, 10:09 PMXGBoost
Page 103 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Kaggle Winning Solution
To get a higher rank, one need to push the limit of
1. Feature Engineering
2. Parameter Tuning
3. Model Ensemble
The winning solution in the recent Otto Competition is an excellent example.
103/128
104. 8/30/15, 10:09 PMXGBoost
Page 104 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Kaggle Winning Solution
They used a 3-layer ensemble learning model, including
33 models on top of the original data
XGBoost, neural network and adaboost on 33 predictions from the models and 8 engineered
features
Weighted average of the 3 prediction from the second step
·
·
·
104/128
105. 8/30/15, 10:09 PMXGBoost
Page 105 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Kaggle Winning Solution
The data for this competition is special: the meanings of the featuers are hidden.
For feature engineering, they generated 8 new features:
Distances to nearest neighbours of each classes
Sum of distances of 2 nearest neighbours of each classes
Sum of distances of 4 nearest neighbours of each classes
Distances to nearest neighbours of each classes in TFIDF space
Distances to nearest neighbours of each classed in T-SNE space (3 dimensions)
Clustering features of original dataset
Number of non-zeros elements in each row
X (That feature was used only in NN 2nd level training)
·
·
·
·
·
·
·
·
105/128
106. 8/30/15, 10:09 PMXGBoost
Page 106 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Kaggle Winning Solution
This means a lot of work. However this also implies they need to try a lot of other models,
although some of them turned out to be not helpful in this competition. Their attempts include:
A lot of training algorithms in first level as
Some preprocessing like PCA, ICA and FFT
Feature Selection
Semi-supervised learning
·
Vowpal Wabbit(many configurations)
R glm, glmnet, scikit SVC, SVR, Ridge, SGD, etc...
-
-
·
·
·
106/128
107. 8/30/15, 10:09 PMXGBoost
Page 107 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Influencers in Social Networks
Let's learn to use a single XGBoost model to achieve a high rank in an old competition!
The competition we choose is the Influencers in Social Networks competition.
It was a hackathon in 2013, therefore the size of data is small enough so that we can train the
model in seconds.
107/128
108. 8/30/15, 10:09 PMXGBoost
Page 108 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Influencers in Social Networks
First let's download the data, and load them into R
train = read.csv('train.csv',header = TRUE)
test = read.csv('test.csv',header = TRUE)
y = train[,1]
train = as.matrix(train[,-1])
test = as.matrix(test)
108/128
111. 8/30/15, 10:09 PMXGBoost
Page 111 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Influencers in Social Networks
The data contains information from two users in a social network service. Our mission is to
determine who is more influencial than the other one.
This type of data gives us some room for feature engineering.
111/128
112. 8/30/15, 10:09 PMXGBoost
Page 112 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Influencers in Social Networks
The first trick is to increase the information in the data.
Every data point can be expressed as <y, A, B>. Actually it indicates <1-y, B, A> as well.
We can simply use extract this part of information from the training set.
new.train = cbind(train[,12:22],train[,1:11])
train = rbind(train,new.train)
y = c(y,1-y)
112/128
113. 8/30/15, 10:09 PMXGBoost
Page 113 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Influencers in Social Networks
The following feature engineering steps are done on both training and test set. Therefore we
combine them together.
x = rbind(train,test)
113/128
114. 8/30/15, 10:09 PMXGBoost
Page 114 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Influencers in Social Networks
The next step could be calculating the ratio between features of A and B seperately:
followers/following
mentions received/sent
retweets received/sent
followers/posts
retweets received/posts
mentions received/posts
·
·
·
·
·
·
114/128
115. 8/30/15, 10:09 PMXGBoost
Page 115 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Influencers in Social Networks
Considering there might be zeroes, we need to smooth the ratio by a constant.
Next we can calculate the ratio with this helper function.
calcRatio = function(dat,i,j,lambda = 1) (dat[,i]+lambda)/(dat[,j]+lambda)
115/128
117. 8/30/15, 10:09 PMXGBoost
Page 117 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Influencers in Social Networks
Combine the features into the data set.
x = cbind(x[,1:11],
A.follow.ratio,A.mention.ratio,A.retweet.ratio,
A.follow.post,A.mention.post,A.retweet.post,
x[,12:22],
B.follow.ratio,B.mention.ratio,B.retweet.ratio,
B.follow.post,B.mention.post,B.retweet.post)
117/128
118. 8/30/15, 10:09 PMXGBoost
Page 118 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Influencers in Social Networks
Then we can compare the difference between A and B. Because XGBoost is scale invariant,
therefore minus and division are the essentially same.
AB.diff = x[,1:17]-x[,18:34]
x = cbind(x,AB.diff)
train = x[1:nrow(train),]
test = x[-(1:nrow(train)),]
118/128
119. 8/30/15, 10:09 PMXGBoost
Page 119 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Influencers in Social Networks
Now comes to the modeling part. We investigate how far can we can go with a single model.
The parameter tuning step is very important in this step. We can see the performance from
cross validation.
119/128
120. 8/30/15, 10:09 PMXGBoost
Page 120 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Influencers in Social Networks
Here's the xgb.cv with default parameters.
set.seed(1024)
cv.res = xgb.cv(data = train, nfold = 3, label = y, nrounds = 100, verbose = FALSE,
objective='binary:logistic', eval_metric = 'auc')
120/128
121. 8/30/15, 10:09 PMXGBoost
Page 121 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Influencers in Social Networks
We can see the trend of AUC on training and test sets.
121/128
122. 8/30/15, 10:09 PMXGBoost
Page 122 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Influencers in Social Networks
It is obvious our model severly overfits. The direct reason is simple: the default value of eta is
0.3, which is too large for this mission.
Recall the parameter tuning guide, we need to decrease eta and inccrease nrounds based on
the result of cross validation.
122/128
123. 8/30/15, 10:09 PMXGBoost
Page 123 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Influencers in Social Networks
After some trials, we get the following set of parameters:
set.seed(1024)
cv.res = xgb.cv(data = train, nfold = 3, label = y, nrounds = 3000,
objective='binary:logistic', eval_metric = 'auc',
eta = 0.005, gamma = 1,lambda = 3, nthread = 8,
max_depth = 4, min_child_weight = 1, verbose = F,
subsample = 0.8,colsample_bytree = 0.8)
123/128
124. 8/30/15, 10:09 PMXGBoost
Page 124 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Influencers in Social Networks
We can see the trend of AUC on training and test sets.
124/128
125. 8/30/15, 10:09 PMXGBoost
Page 125 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Influencers in Social Networks
Next we extract the best number of iterations.
We calculate the AUC minus the standard deviation, and choose the iteration with the largest
value.
bestRound = which.max(as.matrix(cv.res)[,3]-as.matrix(cv.res)[,4])
bestRound
## [1] 2442
cv.res[bestRound,]
## train.auc.mean train.auc.std test.auc.mean test.auc.std
## 1: 0.934967 0.00125 0.876629 0.002073
125/128
126. 8/30/15, 10:09 PMXGBoost
Page 126 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Influencers in Social Networks
Then we train the model with the same set of parameters:
set.seed(1024)
bst = xgboost(data = train, label = y, nrounds = 3000,
objective='binary:logistic', eval_metric = 'auc',
eta = 0.005, gamma = 1,lambda = 3, nthread = 8,
max_depth = 4, min_child_weight = 1,
subsample = 0.8,colsample_bytree = 0.8)
preds = predict(bst,test,ntreelimit = bestRound)
126/128
127. 8/30/15, 10:09 PMXGBoost
Page 127 of 128file:///Users/vivi/Desktop/xgboost/index.html#1
Influencers in Social Networks
Finally we submit our solution
This wins us top 10 on the leaderboard!
result = data.frame(Id = 1:nrow(test),
Choice = preds)
write.csv(result,'submission.csv',quote=FALSE,row.names=FALSE)
127/128