{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
" \n",
"## [mlcourse.ai](https://mlcourse.ai) – Open Machine Learning Course \n",
"Author: [Yury Kashnitsky](https://yorko.github.io) (@yorko). Edited by Roman Volykhin (@GerrBert). This material is subject to the terms and conditions of the [Creative Commons CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/) license. Free use is permitted for any non-commercial purpose"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"# Fall 2019. Quiz 1. Decision trees and Random Forests\n",
" \n",
"Prior to working on the assignment, you'd better check out the corresponding course material:\n",
"\n",
" 1. [Classification, Decision Trees and k Nearest Neighbors](https://mlcourse.ai/articles/topic3-dt-knn/), the same as an interactive web-based [Kaggle Kernel](https://www.kaggle.com/kashnitsky/topic-3-decision-trees-and-knn) \n",
" 1. Ensembles:\n",
" - [Bagging](https://mlcourse.ai/articles/topic5-part1-bagging/), the same as a [Kaggle Kernel](https://www.kaggle.com/kashnitsky/topic-5-ensembles-part-1-bagging)\n",
" - [Random Forest](https://mlcourse.ai/articles/topic5-part2-rf/), the same as a [Kaggle Kernel](https://www.kaggle.com/kashnitsky/topic-5-ensembles-part-2-random-forest)\n",
" - [Feature Importance](https://mlcourse.ai/articles/topic5-part3-feature-importance/), the same as a [Kaggle Kernel](https://www.kaggle.com/kashnitsky/topic-5-ensembles-part-3-feature-importance)\n",
" 1. There are 5 video lectures on trees, forests and their applications: [mlcourse.ai/lectures](https://mlcourse.ai/lectures) \n",
" \n",
"We suggest that you first read the articles (quiz questions are based on them), if something is not clear - watch thr corresponding lecture. \n",
" \n",
"### Your task is to:\n",
" 1. study the materials \n",
" 1. write code where needed\n",
" 1. choose answers in the [webform](https://docs.google.com/forms/d/1eT1niiuyFvmpYjL5rY6wRplocoqUHdeCTd6jAa_vsrk). \n",
"\n",
" \n",
"### Deadline for Quiz: 2019 September 27, 20:59 CET (London time)\n",
" \n",
"Solutions will be discussed during a live YouTube session on September 28. You can get up to 10 credits (those points in a web-form, 15 max, will be scaled to a max of 10 credits). "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Part 1. Decision trees\n",
"\n",
"*For discussions, please stick to [ODS Slack](https://opendatascience.slack.com/), channel __#mlcourse_ai_news__, pinned thread __#quiz1\\_fall2019__*\n",
"\n",
"**Question 1**. Which of these problems does not fall into 3 main types of ML tasks: classification, regression, and clustering?\n",
" 1. Identifying a topic of a live-chat with a customer\n",
" 1. Grouping news into topics\n",
" 1. Predicting LTV (Life-Time Value) - the amount of money spent by a customer in a certain large period of time\n",
" 1. Listing top products that a user is prone to buy (based on his/her click history)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Question 2**. Maximal possible entropy is achieved when all states are equally probable (prove it yourself for a system with 2 states with probabilities $p$ and $1-p$). What's the maximal possible entropy of a system with N states? (here all logs are with base 2)\n",
" 1. $N \\log N$\n",
" 1. $-\\log N$\n",
" 1. $\\log N$\n",
" 1. $-N \\log N$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Question 3**. In Topic 3 article, toy example with 20 balls, what's the information gain of splitting 20 balls in 2 groups based on the condition X <= 8?\n",
"\n",
" 1. ~ 0.1\n",
" 1. ~ 0.01\n",
" 1. ~ 0.001\n",
" 1. ~ 0.0001"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Question 4.** In a toy binary classification task, there are $d$ features $x_1 \\ldots x_d$, but target $y$ depends only on $x_1$ and $x_2$: $y = [\\frac{x_1^2}{4} + \\frac{x_2^2}{9} \\leq 16]$, where $[\\cdot]$ is an indicator function. All of features $x_3 \\ldots x_d$ are noisy, i.e. do not influence the target feature at all. Obviously, machine learning algorithms shall perform almost perfectly in this task, where target is a simple function of input features. If we train sklearn's `DecisionTreeClassifier` for this task, which parameters have crucial effect on accuracy (crucial - meaning that if these parameters are set incorrectly, then accuracy can drop significantly)? Select all that apply (to get credits, you need to select all that apply, no partially correct answers).\n",
" 1. `max_features`\n",
" 1. `criterion`\n",
" 1. `min_samples_leaf`\n",
" 1. `max_depth`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Question 5.** Load iris data with `sklearn.datasets.load_iris`. Train a decision tree with this data, specifying params `max_depth`=4 and `random_state`=17 (all other arguments shall be left unchanged). Use all available 150 instances to train a tree (do not perform train/validation split). Visualize the fitted decision tree, see topic 3 for examples. Let's call a leaf in a tree _pure_ if it contains instances of only one class. How many pure leaves are there in this tree?\n",
"\n",
" 1. 6\n",
" 1. 7\n",
" 1. 8\n",
" 1. 9\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Part 2. Ensembles and Random Forest\n",
"\n",
"*For discussions, please stick to [ODS Slack](https://opendatascience.slack.com/), channel __#mlcourse_ai_news__, pinned thread __#quiz1\\_fall2019__*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Question 6.** There are 7 jurors in the courtroom. Each of them individually can correctly determine whether the defendant is guilty or not with 80% probability. How likely is the jury will make a correct verdict jointly if the decision is made by majority voting?\n",
"\n",
"\n",
"\n",
" 1. 20.97%\n",
" 1. 80.00%\n",
" 1. 83.70%\n",
" 1. 96.66%"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Question 7.** In [Topic 5, part 2](https://mlcourse.ai/articles/topic5-part2-rf/), section 2. \"Comparison with Decision Trees and Bagging\" we show how bagging and Random Forest improve classification accuracy as compared to a single decision tree. Which of the following is a better explanation of the visual difference between decision boundaries built by a single desicion tree and those built by ensemble models?\n",
"\n",
" 1. Ensembles ignore some of the features. Thus picking only important ones, they build a smoother decision boundary \n",
" 1. Some of the classification rules built by a decision tree can be applied only to a small number of training instances\n",
" 1. When fitting a decision tree, if two potential splits are equally good in terms of information criterion, then a random split is chosen. This leads to some randomness in building a decision tree. Therefore its decision boundary is so jagged"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Question 8.** Random Forest learns a coefficient for each input feature, which shows how much this feature influences the target feature. True/False?\n",
" 1. True\n",
" 1. False\n",
"\n",
"**Question 9.** Suppose we fit `RandomForestRegressor` to predict age of a customer (a real task actually, good for targeting ads), and the maximal age seen in the dataset is 98 years. Is it possible that for some customer in future the model predicts his/her age to be 105 years?\n",
" 1. Yes\n",
" 1. No\n",
" \n",
"**Question 10.** Select all statements supporting advantages of Random Forest over decision trees (some statements might be true but not about Random Forest's pros, don't select those).\n",
"\n",
" 1. Random Forest is easier to train in terms of computational resources\n",
" 1. Random Forest typically requires more RAM than a single decision tree \n",
" 1. Random Forest typically achieves better metrics in classification/regression tasks\n",
" 1. Single decision tree's prediction can be much easier interpreted"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}