<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/extremely-boost-your-machine-learning-exercises-part-1/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.r-exercises.com/2017/09/24/extremely-boost-your-machine-learning-exercises-part-1/"> R-exercises</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a rel="nofollow" href="https://i1.wp.com/www.r-exercises.com/wp-content/uploads/2017/09/rocket-launch-67643_1920.jpg" target="_blank"><img sizes="(max-width: 300px) 100vw, 300px" src="https://i2.wp.com/www.r-exercises.com/wp-content/uploads/2017/09/rocket-launch-67643_1920-300x201.jpg?resize=300%2C201" alt="" class="wp-image-8023" data-recalc-dims="1"></a><br>
eXtreme Gradient Boosting is a machine learning model which became really popular few years ago after winning several Kaggle competitions. It is very powerful algorithm that use an ensemble of weak learners to obtain a strong learner. Its R implementation is available in <code>xgboost</code> package and it is really worth including into anyone’s machine learning portfolio.</p>
<p>This is the first part of eXtremely Boost your machine learning series. For other parts follow the tag <a rel="nofollow" href="http://r-exercises.com/tag/xgboost" target="_blank">xgboost</a>.</p>
<p>Answers to the exercises are available <a rel="nofollow" href="http://r-exercises.com/2017/09/24/extremely-boost-your-machine-learning-solutions-part-1/" target="_blank">here</a>.</p>
<p>If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.</p>
<p><strong>Exercise 1</strong><br>
Load <code>xgboost</code> library and download <a rel="nofollow" href="http://freakonometrics.free.fr/german_credit.csv" target="_blank">German Credit dataset</a>. Your goal in this tutorial will be to predict <code>Creditability</code> (the first column in the dataset).</p>
<p><strong>Exercise 2</strong><br>
Convert columns <code>c(2,4,5,7,8,9,10,11,12,13,15,16,17,18,19,20)</code> to factors and then encode them as dummy variables. HINT: use <code>model.matrix()</code></p>
<p><strong>Exercise 3</strong><br>
Split data into training and test set 700:300. Create <code>xgb.DMatrix</code> for both sets with <code>Creditability</code> as label.</p>
<p><strong>Exercise 4</strong><br>
Train <code>xgboost</code> with logistic objective and 30 rounds of training and maximal depth 2.</p>
<p><strong>Exercise 5</strong><br>
To check model performance calculate test set classification error.</p>
<p><strong>Exercise 6</strong><br>
Plot predictors importance.</p>
<div>
<aside><img src="http://www.r-exercises.com/2017/09/24/extremely-boost-your-machine-learning-exercises-part-1/"></aside>
<div><strong>Learn more</strong> about machine learning in the online course <a rel="nofollow" href="http://www.r-exercises.com/product/beginner-to-advanced-guide-on-machine-learning-with-r-tool/" target="_blank">Beginner to Advanced Guide on Machine Learning with R Tool</a>. In this course you will learn how to:
<ul>
<li>Create a machine learning algorithm from a beginner point of view</li>
<li>Quickly dive into more advanced methods in an accessible pace and with more explanations</li>
<li>And much more</li>
</ul>
<p>This course shows a complete workflow start to finish. It is a great introduction and fallback when you have some experience.
</div>
</div>
<p><strong>Exercise 7</strong><br>
Use <code>xgb.train()</code> instead of <code>xgboost()</code> to add both train and test sets as a watchlist. Train model with same parameters, but 100 rounds to see how it performs during training.</p>
<p><strong>Exercise 8</strong><br>
Train model again adding AUC and Log Loss as evaluation metrices.</p>
<p><strong>Exercise 9</strong><br>
Plot how AUC and Log Loss for train and test sets was changing during training process. Use plotting function/library of your choice.</p>
<p><strong>Exercise 10</strong><br>
Check how setting parameter <code>eta</code> to 0.01 influences the AUC and Log Loss curves.</p>
<div>
<h3>Related exercise sets:</h3>
<ol>
<li><a rel="nofollow" href="http://www.r-exercises.com/2016/12/22/model-evaluation-2/" title="Model Evaluation 2" target="_blank">Model Evaluation 2 </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/2017/08/25/machine-learning-tutorial/" title="How to prepare and apply machine learning to your dataset" target="_blank">How to prepare and apply machine learning to your dataset </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/2017/08/01/hacking-statistics-exercises-part-5/" title="Hacking statistics or: How I Learned to Stop Worrying About Calculus and Love Stats Exercises (Part-5)" target="_blank">Hacking statistics or: How I Learned to Stop Worrying About Calculus and Love Stats Exercises (Part-5) </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/start-here-to-learn-r/" target="_blank">Explore all our (>1000) R exercises</a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/r-courses/" target="_blank">Find an R course using our R Course Finder</a> directory</li>
</ol>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.r-exercises.com/2017/09/24/extremely-boost-your-machine-learning-exercises-part-1/"> R-exercises</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/eeTtOajDrGA" height="1"></a></div>