You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2008 lines
197 KiB

2 years ago
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"___\n",
"\n",
"<a href='https://www.udemy.com/user/joseportilla/'><img src='../Pierian_Data_Logo.png'/></a>\n",
"___\n",
"<center><em>Copyright by Pierian Data Inc.</em></center>\n",
"<center><em>For more information, visit us at <a href='http://www.pieriandata.com'>www.pieriandata.com</a></em></center>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Gradient Boosting and GridSearch\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The Data\n",
"\n",
"\n",
"<img src=\"mushroom.jpg\" width=\"400\" height=\"400\">\n",
"\n",
"### Mushroom Hunting: Edible or Poisonous?\n",
"\n",
"Data Source: https://archive.ics.uci.edu/ml/datasets/Mushroom\n",
"\n",
"\n",
"This data set includes descriptions of hypothetical samples corresponding to 23 species of gilled mushrooms in the Agaricus and Lepiota Family (pp. 500-525). Each species is identified as definitely edible, definitely poisonous, or of unknown edibility and not recommended. This latter class was combined with the poisonous one. The Guide clearly states that there is no simple rule for determining the edibility of a mushroom; no rule like ``leaflets three, let it be'' for Poisonous Oak and Ivy.\n",
"\n",
"\n",
"Attribute Information:\n",
"\n",
"1. cap-shape: bell=b,conical=c,convex=x,flat=f, knobbed=k,sunken=s\n",
"2. cap-surface: fibrous=f,grooves=g,scaly=y,smooth=s\n",
"3. cap-color: brown=n,buff=b,cinnamon=c,gray=g,green=r, pink=p,purple=u,red=e,white=w,yellow=y\n",
"4. bruises?: bruises=t,no=f\n",
"5. odor: almond=a,anise=l,creosote=c,fishy=y,foul=f, musty=m,none=n,pungent=p,spicy=s\n",
"6. gill-attachment: attached=a,descending=d,free=f,notched=n\n",
"7. gill-spacing: close=c,crowded=w,distant=d\n",
"8. gill-size: broad=b,narrow=n\n",
"9. gill-color: black=k,brown=n,buff=b,chocolate=h,gray=g, green=r,orange=o,pink=p,purple=u,red=e, white=w,yellow=y\n",
"10. stalk-shape: enlarging=e,tapering=t\n",
"11. stalk-root: bulbous=b,club=c,cup=u,equal=e, rhizomorphs=z,rooted=r,missing=?\n",
"12. stalk-surface-above-ring: fibrous=f,scaly=y,silky=k,smooth=s\n",
"13. stalk-surface-below-ring: fibrous=f,scaly=y,silky=k,smooth=s\n",
"14. stalk-color-above-ring: brown=n,buff=b,cinnamon=c,gray=g,orange=o, pink=p,red=e,white=w,yellow=y\n",
"15. stalk-color-below-ring: brown=n,buff=b,cinnamon=c,gray=g,orange=o, pink=p,red=e,white=w,yellow=y\n",
"16. veil-type: partial=p,universal=u\n",
"17. veil-color: brown=n,orange=o,white=w,yellow=y\n",
"18. ring-number: none=n,one=o,two=t\n",
"19. ring-type: cobwebby=c,evanescent=e,flaring=f,large=l, none=n,pendant=p,sheathing=s,zone=z\n",
"20. spore-print-color: black=k,brown=n,buff=b,chocolate=h,green=r, orange=o,purple=u,white=w,yellow=y\n",
"21. population: abundant=a,clustered=c,numerous=n, scattered=s,several=v,solitary=y\n",
"22. habitat: grasses=g,leaves=l,meadows=m,paths=p, urban=u,waste=w,woods=d"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Imports"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv(\"../DATA/mushrooms.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>class</th>\n",
" <th>cap-shape</th>\n",
" <th>cap-surface</th>\n",
" <th>cap-color</th>\n",
" <th>bruises</th>\n",
" <th>odor</th>\n",
" <th>gill-attachment</th>\n",
" <th>gill-spacing</th>\n",
" <th>gill-size</th>\n",
" <th>gill-color</th>\n",
" <th>...</th>\n",
" <th>stalk-surface-below-ring</th>\n",
" <th>stalk-color-above-ring</th>\n",
" <th>stalk-color-below-ring</th>\n",
" <th>veil-type</th>\n",
" <th>veil-color</th>\n",
" <th>ring-number</th>\n",
" <th>ring-type</th>\n",
" <th>spore-print-color</th>\n",
" <th>population</th>\n",
" <th>habitat</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>p</td>\n",
" <td>x</td>\n",
" <td>s</td>\n",
" <td>n</td>\n",
" <td>t</td>\n",
" <td>p</td>\n",
" <td>f</td>\n",
" <td>c</td>\n",
" <td>n</td>\n",
" <td>k</td>\n",
" <td>...</td>\n",
" <td>s</td>\n",
" <td>w</td>\n",
" <td>w</td>\n",
" <td>p</td>\n",
" <td>w</td>\n",
" <td>o</td>\n",
" <td>p</td>\n",
" <td>k</td>\n",
" <td>s</td>\n",
" <td>u</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>e</td>\n",
" <td>x</td>\n",
" <td>s</td>\n",
" <td>y</td>\n",
" <td>t</td>\n",
" <td>a</td>\n",
" <td>f</td>\n",
" <td>c</td>\n",
" <td>b</td>\n",
" <td>k</td>\n",
" <td>...</td>\n",
" <td>s</td>\n",
" <td>w</td>\n",
" <td>w</td>\n",
" <td>p</td>\n",
" <td>w</td>\n",
" <td>o</td>\n",
" <td>p</td>\n",
" <td>n</td>\n",
" <td>n</td>\n",
" <td>g</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>e</td>\n",
" <td>b</td>\n",
" <td>s</td>\n",
" <td>w</td>\n",
" <td>t</td>\n",
" <td>l</td>\n",
" <td>f</td>\n",
" <td>c</td>\n",
" <td>b</td>\n",
" <td>n</td>\n",
" <td>...</td>\n",
" <td>s</td>\n",
" <td>w</td>\n",
" <td>w</td>\n",
" <td>p</td>\n",
" <td>w</td>\n",
" <td>o</td>\n",
" <td>p</td>\n",
" <td>n</td>\n",
" <td>n</td>\n",
" <td>m</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>p</td>\n",
" <td>x</td>\n",
" <td>y</td>\n",
" <td>w</td>\n",
" <td>t</td>\n",
" <td>p</td>\n",
" <td>f</td>\n",
" <td>c</td>\n",
" <td>n</td>\n",
" <td>n</td>\n",
" <td>...</td>\n",
" <td>s</td>\n",
" <td>w</td>\n",
" <td>w</td>\n",
" <td>p</td>\n",
" <td>w</td>\n",
" <td>o</td>\n",
" <td>p</td>\n",
" <td>k</td>\n",
" <td>s</td>\n",
" <td>u</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>e</td>\n",
" <td>x</td>\n",
" <td>s</td>\n",
" <td>g</td>\n",
" <td>f</td>\n",
" <td>n</td>\n",
" <td>f</td>\n",
" <td>w</td>\n",
" <td>b</td>\n",
" <td>k</td>\n",
" <td>...</td>\n",
" <td>s</td>\n",
" <td>w</td>\n",
" <td>w</td>\n",
" <td>p</td>\n",
" <td>w</td>\n",
" <td>o</td>\n",
" <td>e</td>\n",
" <td>n</td>\n",
" <td>a</td>\n",
" <td>g</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 23 columns</p>\n",
"</div>"
],
"text/plain": [
" class cap-shape cap-surface cap-color bruises odor gill-attachment \\\n",
"0 p x s n t p f \n",
"1 e x s y t a f \n",
"2 e b s w t l f \n",
"3 p x y w t p f \n",
"4 e x s g f n f \n",
"\n",
" gill-spacing gill-size gill-color ... stalk-surface-below-ring \\\n",
"0 c n k ... s \n",
"1 c b k ... s \n",
"2 c b n ... s \n",
"3 c n n ... s \n",
"4 w b k ... s \n",
"\n",
" stalk-color-above-ring stalk-color-below-ring veil-type veil-color \\\n",
"0 w w p w \n",
"1 w w p w \n",
"2 w w p w \n",
"3 w w p w \n",
"4 w w p w \n",
"\n",
" ring-number ring-type spore-print-color population habitat \n",
"0 o p k s u \n",
"1 o p n n g \n",
"2 o p n n m \n",
"3 o p k s u \n",
"4 o e n a g \n",
"\n",
"[5 rows x 23 columns]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Data Prep"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"X = df.drop('class',axis=1)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"y = df['class']"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"X = pd.get_dummies(X,drop_first=True)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>cap-shape_c</th>\n",
" <th>cap-shape_f</th>\n",
" <th>cap-shape_k</th>\n",
" <th>cap-shape_s</th>\n",
" <th>cap-shape_x</th>\n",
" <th>cap-surface_g</th>\n",
" <th>cap-surface_s</th>\n",
" <th>cap-surface_y</th>\n",
" <th>cap-color_c</th>\n",
" <th>cap-color_e</th>\n",
" <th>...</th>\n",
" <th>population_n</th>\n",
" <th>population_s</th>\n",
" <th>population_v</th>\n",
" <th>population_y</th>\n",
" <th>habitat_g</th>\n",
" <th>habitat_l</th>\n",
" <th>habitat_m</th>\n",
" <th>habitat_p</th>\n",
" <th>habitat_u</th>\n",
" <th>habitat_w</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 95 columns</p>\n",
"</div>"
],
"text/plain": [
" cap-shape_c cap-shape_f cap-shape_k cap-shape_s cap-shape_x \\\n",
"0 0 0 0 0 1 \n",
"1 0 0 0 0 1 \n",
"2 0 0 0 0 0 \n",
"3 0 0 0 0 1 \n",
"4 0 0 0 0 1 \n",
"\n",
" cap-surface_g cap-surface_s cap-surface_y cap-color_c cap-color_e ... \\\n",
"0 0 1 0 0 0 ... \n",
"1 0 1 0 0 0 ... \n",
"2 0 1 0 0 0 ... \n",
"3 0 0 1 0 0 ... \n",
"4 0 1 0 0 0 ... \n",
"\n",
" population_n population_s population_v population_y habitat_g \\\n",
"0 0 1 0 0 0 \n",
"1 1 0 0 0 1 \n",
"2 1 0 0 0 0 \n",
"3 0 1 0 0 0 \n",
"4 0 0 0 0 1 \n",
"\n",
" habitat_l habitat_m habitat_p habitat_u habitat_w \n",
"0 0 0 0 1 0 \n",
"1 0 0 0 0 0 \n",
"2 0 1 0 0 0 \n",
"3 0 0 0 1 0 \n",
"4 0 0 0 0 0 \n",
"\n",
"[5 rows x 95 columns]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X.head()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 p\n",
"1 e\n",
"2 e\n",
"3 p\n",
"4 e\n",
"Name: class, dtype: object"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Train Test Split "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.model_selection import train_test_split"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.15, random_state=101)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Gradient Boosting and Grid Search with CV"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.ensemble import GradientBoostingClassifier"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Help on class GradientBoostingClassifier in module sklearn.ensemble._gb:\n",
"\n",
"class GradientBoostingClassifier(sklearn.base.ClassifierMixin, BaseGradientBoosting)\n",
" | GradientBoostingClassifier(*, loss='deviance', learning_rate=0.1, n_estimators=100, subsample=1.0, criterion='friedman_mse', min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_depth=3, min_impurity_decrease=0.0, min_impurity_split=None, init=None, random_state=None, max_features=None, verbose=0, max_leaf_nodes=None, warm_start=False, presort='deprecated', validation_fraction=0.1, n_iter_no_change=None, tol=0.0001, ccp_alpha=0.0)\n",
" | \n",
" | Gradient Boosting for classification.\n",
" | \n",
" | GB builds an additive model in a\n",
" | forward stage-wise fashion; it allows for the optimization of\n",
" | arbitrary differentiable loss functions. In each stage ``n_classes_``\n",
" | regression trees are fit on the negative gradient of the\n",
" | binomial or multinomial deviance loss function. Binary classification\n",
" | is a special case where only a single regression tree is induced.\n",
" | \n",
" | Read more in the :ref:`User Guide <gradient_boosting>`.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | loss : {'deviance', 'exponential'}, default='deviance'\n",
" | loss function to be optimized. 'deviance' refers to\n",
" | deviance (= logistic regression) for classification\n",
" | with probabilistic outputs. For loss 'exponential' gradient\n",
" | boosting recovers the AdaBoost algorithm.\n",
" | \n",
" | learning_rate : float, default=0.1\n",
" | learning rate shrinks the contribution of each tree by `learning_rate`.\n",
" | There is a trade-off between learning_rate and n_estimators.\n",
" | \n",
" | n_estimators : int, default=100\n",
" | The number of boosting stages to perform. Gradient boosting\n",
" | is fairly robust to over-fitting so a large number usually\n",
" | results in better performance.\n",
" | \n",
" | subsample : float, default=1.0\n",
" | The fraction of samples to be used for fitting the individual base\n",
" | learners. If smaller than 1.0 this results in Stochastic Gradient\n",
" | Boosting. `subsample` interacts with the parameter `n_estimators`.\n",
" | Choosing `subsample < 1.0` leads to a reduction of variance\n",
" | and an increase in bias.\n",
" | \n",
" | criterion : {'friedman_mse', 'mse', 'mae'}, default='friedman_mse'\n",
" | The function to measure the quality of a split. Supported criteria\n",
" | are 'friedman_mse' for the mean squared error with improvement\n",
" | score by Friedman, 'mse' for mean squared error, and 'mae' for\n",
" | the mean absolute error. The default value of 'friedman_mse' is\n",
" | generally the best as it can provide a better approximation in\n",
" | some cases.\n",
" | \n",
" | .. versionadded:: 0.18\n",
" | \n",
" | min_samples_split : int or float, default=2\n",
" | The minimum number of samples required to split an internal node:\n",
" | \n",
" | - If int, then consider `min_samples_split` as the minimum number.\n",
" | - If float, then `min_samples_split` is a fraction and\n",
" | `ceil(min_samples_split * n_samples)` are the minimum\n",
" | number of samples for each split.\n",
" | \n",
" | .. versionchanged:: 0.18\n",
" | Added float values for fractions.\n",
" | \n",
" | min_samples_leaf : int or float, default=1\n",
" | The minimum number of samples required to be at a leaf node.\n",
" | A split point at any depth will only be considered if it leaves at\n",
" | least ``min_samples_leaf`` training samples in each of the left and\n",
" | right branches. This may have the effect of smoothing the model,\n",
" | especially in regression.\n",
" | \n",
" | - If int, then consider `min_samples_leaf` as the minimum number.\n",
" | - If float, then `min_samples_leaf` is a fraction and\n",
" | `ceil(min_samples_leaf * n_samples)` are the minimum\n",
" | number of samples for each node.\n",
" | \n",
" | .. versionchanged:: 0.18\n",
" | Added float values for fractions.\n",
" | \n",
" | min_weight_fraction_leaf : float, default=0.0\n",
" | The minimum weighted fraction of the sum total of weights (of all\n",
" | the input samples) required to be at a leaf node. Samples have\n",
" | equal weight when sample_weight is not provided.\n",
" | \n",
" | max_depth : int, default=3\n",
" | maximum depth of the individual regression estimators. The maximum\n",
" | depth limits the number of nodes in the tree. Tune this parameter\n",
" | for best performance; the best value depends on the interaction\n",
" | of the input variables.\n",
" | \n",
" | min_impurity_decrease : float, default=0.0\n",
" | A node will be split if this split induces a decrease of the impurity\n",
" | greater than or equal to this value.\n",
" | \n",
" | The weighted impurity decrease equation is the following::\n",
" | \n",
" | N_t / N * (impurity - N_t_R / N_t * right_impurity\n",
" | - N_t_L / N_t * left_impurity)\n",
" | \n",
" | where ``N`` is the total number of samples, ``N_t`` is the number of\n",
" | samples at the current node, ``N_t_L`` is the number of samples in the\n",
" | left child, and ``N_t_R`` is the number of samples in the right child.\n",
" | \n",
" | ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n",
" | if ``sample_weight`` is passed.\n",
" | \n",
" | .. versionadded:: 0.19\n",
" | \n",
" | min_impurity_split : float, default=None\n",
" | Threshold for early stopping in tree growth. A node will split\n",
" | if its impurity is above the threshold, otherwise it is a leaf.\n",
" | \n",
" | .. deprecated:: 0.19\n",
" | ``min_impurity_split`` has been deprecated in favor of\n",
" | ``min_impurity_decrease`` in 0.19. The default value of\n",
" | ``min_impurity_split`` has changed from 1e-7 to 0 in 0.23 and it\n",
" | will be removed in 0.25. Use ``min_impurity_decrease`` instead.\n",
" | \n",
" | init : estimator or 'zero', default=None\n",
" | An estimator object that is used to compute the initial predictions.\n",
" | ``init`` has to provide :meth:`fit` and :meth:`predict_proba`. If\n",
" | 'zero', the initial raw predictions are set to zero. By default, a\n",
" | ``DummyEstimator`` predicting the classes priors is used.\n",
" | \n",
" | random_state : int or RandomState, default=None\n",
" | Controls the random seed given to each Tree estimator at each\n",
" | boosting iteration.\n",
" | In addition, it controls the random permutation of the features at\n",
" | each split (see Notes for more details).\n",
" | It also controls the random spliting of the training data to obtain a\n",
" | validation set if `n_iter_no_change` is not None.\n",
" | Pass an int for reproducible output across multiple function calls.\n",
" | See :term:`Glossary <random_state>`.\n",
" | \n",
" | max_features : {'auto', 'sqrt', 'log2'}, int or float, default=None\n",
" | The number of features to consider when looking for the best split:\n",
" | \n",
" | - If int, then consider `max_features` features at each split.\n",
" | - If float, then `max_features` is a fraction and\n",
" | `int(max_features * n_features)` features are considered at each\n",
" | split.\n",
" | - If 'auto', then `max_features=sqrt(n_features)`.\n",
" | - If 'sqrt', then `max_features=sqrt(n_features)`.\n",
" | - If 'log2', then `max_features=log2(n_features)`.\n",
" | - If None, then `max_features=n_features`.\n",
" | \n",
" | Choosing `max_features < n_features` leads to a reduction of variance\n",
" | and an increase in bias.\n",
" | \n",
" | Note: the search for a split does not stop until at least one\n",
" | valid partition of the node samples is found, even if it requires to\n",
" | effectively inspect more than ``max_features`` features.\n",
" | \n",
" | verbose : int, default=0\n",
" | Enable verbose output. If 1 then it prints progress and performance\n",
" | once in a while (the more trees the lower the frequency). If greater\n",
" | than 1 then it prints progress and performance for every tree.\n",
" | \n",
" | max_leaf_nodes : int, default=None\n",
" | Grow trees with ``max_leaf_nodes`` in best-first fashion.\n",
" | Best nodes are defined as relative reduction in impurity.\n",
" | If None then unlimited number of leaf nodes.\n",
" | \n",
" | warm_start : bool, default=False\n",
" | When set to ``True``, reuse the solution of the previous call to fit\n",
" | and add more estimators to the ensemble, otherwise, just erase the\n",
" | previous solution. See :term:`the Glossary <warm_start>`.\n",
" | \n",
" | presort : deprecated, default='deprecated'\n",
" | This parameter is deprecated and will be removed in v0.24.\n",
" | \n",
" | .. deprecated :: 0.22\n",
" | \n",
" | validation_fraction : float, default=0.1\n",
" | The proportion of training data to set aside as validation set for\n",
" | early stopping. Must be between 0 and 1.\n",
" | Only used if ``n_iter_no_change`` is set to an integer.\n",
" | \n",
" | .. versionadded:: 0.20\n",
" | \n",
" | n_iter_no_change : int, default=None\n",
" | ``n_iter_no_change`` is used to decide if early stopping will be used\n",
" | to terminate training when validation score is not improving. By\n",
" | default it is set to None to disable early stopping. If set to a\n",
" | number, it will set aside ``validation_fraction`` size of the training\n",
" | data as validation and terminate training when validation score is not\n",
" | improving in all of the previous ``n_iter_no_change`` numbers of\n",
" | iterations. The split is stratified.\n",
" | \n",
" | .. versionadded:: 0.20\n",
" | \n",
" | tol : float, default=1e-4\n",
" | Tolerance for the early stopping. When the loss is not improving\n",
" | by at least tol for ``n_iter_no_change`` iterations (if set to a\n",
" | number), the training stops.\n",
" | \n",
" | .. versionadded:: 0.20\n",
" | \n",
" | ccp_alpha : non-negative float, default=0.0\n",
" | Complexity parameter used for Minimal Cost-Complexity Pruning. The\n",
" | subtree with the largest cost complexity that is smaller than\n",
" | ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n",
" | :ref:`minimal_cost_complexity_pruning` for details.\n",
" | \n",
" | .. versionadded:: 0.22\n",
" | \n",
" | Attributes\n",
" | ----------\n",
" | n_estimators_ : int\n",
" | The number of estimators as selected by early stopping (if\n",
" | ``n_iter_no_change`` is specified). Otherwise it is set to\n",
" | ``n_estimators``.\n",
" | \n",
" | .. versionadded:: 0.20\n",
" | \n",
" | feature_importances_ : ndarray of shape (n_features,)\n",
" | The impurity-based feature importances.\n",
" | The higher, the more important the feature.\n",
" | The importance of a feature is computed as the (normalized)\n",
" | total reduction of the criterion brought by that feature. It is also\n",
" | known as the Gini importance.\n",
" | \n",
" | Warning: impurity-based feature importances can be misleading for\n",
" | high cardinality features (many unique values). See\n",
" | :func:`sklearn.inspection.permutation_importance` as an alternative.\n",
" | \n",
" | oob_improvement_ : ndarray of shape (n_estimators,)\n",
" | The improvement in loss (= deviance) on the out-of-bag samples\n",
" | relative to the previous iteration.\n",
" | ``oob_improvement_[0]`` is the improvement in\n",
" | loss of the first stage over the ``init`` estimator.\n",
" | Only available if ``subsample < 1.0``\n",
" | \n",
" | train_score_ : ndarray of shape (n_estimators,)\n",
" | The i-th score ``train_score_[i]`` is the deviance (= loss) of the\n",
" | model at iteration ``i`` on the in-bag sample.\n",
" | If ``subsample == 1`` this is the deviance on the training data.\n",
" | \n",
" | loss_ : LossFunction\n",
" | The concrete ``LossFunction`` object.\n",
" | \n",
" | init_ : estimator\n",
" | The estimator that provides the initial predictions.\n",
" | Set via the ``init`` argument or ``loss.init_estimator``.\n",
" | \n",
" | estimators_ : ndarray of DecisionTreeRegressor of shape (n_estimators, ``loss_.K``)\n",
" | The collection of fitted sub-estimators. ``loss_.K`` is 1 for binary\n",
" | classification, otherwise n_classes.\n",
" | \n",
" | classes_ : ndarray of shape (n_classes,)\n",
" | The classes labels.\n",
" | \n",
" | n_features_ : int\n",
" | The number of data features.\n",
" | \n",
" | n_classes_ : int\n",
" | The number of classes.\n",
" | \n",
" | max_features_ : int\n",
" | The inferred value of max_features.\n",
" | \n",
" | Notes\n",
" | -----\n",
" | The features are always randomly permuted at each split. Therefore,\n",
" | the best found split may vary, even with the same training data and\n",
" | ``max_features=n_features``, if the improvement of the criterion is\n",
" | identical for several splits enumerated during the search of the best\n",
" | split. To obtain a deterministic behaviour during fitting,\n",
" | ``random_state`` has to be fixed.\n",
" | \n",
" | Examples\n",
" | --------\n",
" | >>> from sklearn.datasets import make_classification\n",
" | >>> from sklearn.ensemble import GradientBoostingClassifier\n",
" | >>> from sklearn.model_selection import train_test_split\n",
" | >>> X, y = make_classification(random_state=0)\n",
" | >>> X_train, X_test, y_train, y_test = train_test_split(\n",
" | ... X, y, random_state=0)\n",
" | >>> clf = GradientBoostingClassifier(random_state=0)\n",
" | >>> clf.fit(X_train, y_train)\n",
" | GradientBoostingClassifier(random_state=0)\n",
" | >>> clf.predict(X_test[:2])\n",
" | array([1, 0])\n",
" | >>> clf.score(X_test, y_test)\n",
" | 0.88\n",
" | \n",
" | See also\n",
" | --------\n",
" | sklearn.ensemble.HistGradientBoostingClassifier,\n",
" | sklearn.tree.DecisionTreeClassifier, RandomForestClassifier\n",
" | AdaBoostClassifier\n",
" | \n",
" | References\n",
" | ----------\n",
" | J. Friedman, Greedy Function Approximation: A Gradient Boosting\n",
" | Machine, The Annals of Statistics, Vol. 29, No. 5, 2001.\n",
" | \n",
" | J. Friedman, Stochastic Gradient Boosting, 1999\n",
" | \n",
" | T. Hastie, R. Tibshirani and J. Friedman.\n",
" | Elements of Statistical Learning Ed. 2, Springer, 2009.\n",
" | \n",
" | Method resolution order:\n",
" | GradientBoostingClassifier\n",
" | sklearn.base.ClassifierMixin\n",
" | BaseGradientBoosting\n",
" | sklearn.ensemble._base.BaseEnsemble\n",
" | sklearn.base.MetaEstimatorMixin\n",
" | sklearn.base.BaseEstimator\n",
" | builtins.object\n",
" | \n",
" | Methods defined here:\n",
" | \n",
" | __init__(self, *, loss='deviance', learning_rate=0.1, n_estimators=100, subsample=1.0, criterion='friedman_mse', min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_depth=3, min_impurity_decrease=0.0, min_impurity_split=None, init=None, random_state=None, max_features=None, verbose=0, max_leaf_nodes=None, warm_start=False, presort='deprecated', validation_fraction=0.1, n_iter_no_change=None, tol=0.0001, ccp_alpha=0.0)\n",
" | Initialize self. See help(type(self)) for accurate signature.\n",
" | \n",
" | decision_function(self, X)\n",
" | Compute the decision function of ``X``.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | X : {array-like, sparse matrix} of shape (n_samples, n_features)\n",
" | The input samples. Internally, it will be converted to\n",
" | ``dtype=np.float32`` and if a sparse matrix is provided\n",
" | to a sparse ``csr_matrix``.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | score : ndarray of shape (n_samples, n_classes) or (n_samples,)\n",
" | The decision function of the input samples, which corresponds to\n",
" | the raw values predicted from the trees of the ensemble . The\n",
" | order of the classes corresponds to that in the attribute\n",
" | :term:`classes_`. Regression and binary classification produce an\n",
" | array of shape [n_samples].\n",
" | \n",
" | predict(self, X)\n",
" | Predict class for X.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | X : {array-like, sparse matrix} of shape (n_samples, n_features)\n",
" | The input samples. Internally, it will be converted to\n",
" | ``dtype=np.float32`` and if a sparse matrix is provided\n",
" | to a sparse ``csr_matrix``.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | y : ndarray of shape (n_samples,)\n",
" | The predicted values.\n",
" | \n",
" | predict_log_proba(self, X)\n",
" | Predict class log-probabilities for X.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | X : {array-like, sparse matrix} of shape (n_samples, n_features)\n",
" | The input samples. Internally, it will be converted to\n",
" | ``dtype=np.float32`` and if a sparse matrix is provided\n",
" | to a sparse ``csr_matrix``.\n",
" | \n",
" | Raises\n",
" | ------\n",
" | AttributeError\n",
" | If the ``loss`` does not support probabilities.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | p : ndarray of shape (n_samples, n_classes)\n",
" | The class log-probabilities of the input samples. The order of the\n",
" | classes corresponds to that in the attribute :term:`classes_`.\n",
" | \n",
" | predict_proba(self, X)\n",
" | Predict class probabilities for X.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | X : {array-like, sparse matrix} of shape (n_samples, n_features)\n",
" | The input samples. Internally, it will be converted to\n",
" | ``dtype=np.float32`` and if a sparse matrix is provided\n",
" | to a sparse ``csr_matrix``.\n",
" | \n",
" | Raises\n",
" | ------\n",
" | AttributeError\n",
" | If the ``loss`` does not support probabilities.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | p : ndarray of shape (n_samples, n_classes)\n",
" | The class probabilities of the input samples. The order of the\n",
" | classes corresponds to that in the attribute :term:`classes_`.\n",
" | \n",
" | staged_decision_function(self, X)\n",
" | Compute decision function of ``X`` for each iteration.\n",
" | \n",
" | This method allows monitoring (i.e. determine error on testing set)\n",
" | after each stage.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | X : {array-like, sparse matrix} of shape (n_samples, n_features)\n",
" | The input samples. Internally, it will be converted to\n",
" | ``dtype=np.float32`` and if a sparse matrix is provided\n",
" | to a sparse ``csr_matrix``.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | score : generator of ndarray of shape (n_samples, k)\n",
" | The decision function of the input samples, which corresponds to\n",
" | the raw values predicted from the trees of the ensemble . The\n",
" | classes corresponds to that in the attribute :term:`classes_`.\n",
" | Regression and binary classification are special cases with\n",
" | ``k == 1``, otherwise ``k==n_classes``.\n",
" | \n",
" | staged_predict(self, X)\n",
" | Predict class at each stage for X.\n",
" | \n",
" | This method allows monitoring (i.e. determine error on testing set)\n",
" | after each stage.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | X : {array-like, sparse matrix} of shape (n_samples, n_features)\n",
" | The input samples. Internally, it will be converted to\n",
" | ``dtype=np.float32`` and if a sparse matrix is provided\n",
" | to a sparse ``csr_matrix``.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | y : generator of ndarray of shape (n_samples,)\n",
" | The predicted value of the input samples.\n",
" | \n",
" | staged_predict_proba(self, X)\n",
" | Predict class probabilities at each stage for X.\n",
" | \n",
" | This method allows monitoring (i.e. determine error on testing set)\n",
" | after each stage.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | X : {array-like, sparse matrix} of shape (n_samples, n_features)\n",
" | The input samples. Internally, it will be converted to\n",
" | ``dtype=np.float32`` and if a sparse matrix is provided\n",
" | to a sparse ``csr_matrix``.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | y : generator of ndarray of shape (n_samples,)\n",
" | The predicted value of the input samples.\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Data and other attributes defined here:\n",
" | \n",
" | __abstractmethods__ = frozenset()\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Methods inherited from sklearn.base.ClassifierMixin:\n",
" | \n",
" | score(self, X, y, sample_weight=None)\n",
" | Return the mean accuracy on the given test data and labels.\n",
" | \n",
" | In multi-label classification, this is the subset accuracy\n",
" | which is a harsh metric since you require for each sample that\n",
" | each label set be correctly predicted.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | X : array-like of shape (n_samples, n_features)\n",
" | Test samples.\n",
" | \n",
" | y : array-like of shape (n_samples,) or (n_samples, n_outputs)\n",
" | True labels for X.\n",
" | \n",
" | sample_weight : array-like of shape (n_samples,), default=None\n",
" | Sample weights.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | score : float\n",
" | Mean accuracy of self.predict(X) wrt. y.\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Data descriptors inherited from sklearn.base.ClassifierMixin:\n",
" | \n",
" | __dict__\n",
" | dictionary for instance variables (if defined)\n",
" | \n",
" | __weakref__\n",
" | list of weak references to the object (if defined)\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Methods inherited from BaseGradientBoosting:\n",
" | \n",
" | apply(self, X)\n",
" | Apply trees in the ensemble to X, return leaf indices.\n",
" | \n",
" | .. versionadded:: 0.17\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | X : {array-like, sparse matrix} of shape (n_samples, n_features)\n",
" | The input samples. Internally, its dtype will be converted to\n",
" | ``dtype=np.float32``. If a sparse matrix is provided, it will\n",
" | be converted to a sparse ``csr_matrix``.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | X_leaves : array-like of shape (n_samples, n_estimators, n_classes)\n",
" | For each datapoint x in X and for each tree in the ensemble,\n",
" | return the index of the leaf x ends up in each estimator.\n",
" | In the case of binary classification n_classes is 1.\n",
" | \n",
" | fit(self, X, y, sample_weight=None, monitor=None)\n",
" | Fit the gradient boosting model.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | X : {array-like, sparse matrix} of shape (n_samples, n_features)\n",
" | The input samples. Internally, it will be converted to\n",
" | ``dtype=np.float32`` and if a sparse matrix is provided\n",
" | to a sparse ``csr_matrix``.\n",
" | \n",
" | y : array-like of shape (n_samples,)\n",
" | Target values (strings or integers in classification, real numbers\n",
" | in regression)\n",
" | For classification, labels must correspond to classes.\n",
" | \n",
" | sample_weight : array-like of shape (n_samples,), default=None\n",
" | Sample weights. If None, then samples are equally weighted. Splits\n",
" | that would create child nodes with net zero or negative weight are\n",
" | ignored while searching for a split in each node. In the case of\n",
" | classification, splits are also ignored if they would result in any\n",
" | single class carrying a negative weight in either child node.\n",
" | \n",
" | monitor : callable, default=None\n",
" | The monitor is called after each iteration with the current\n",
" | iteration, a reference to the estimator and the local variables of\n",
" | ``_fit_stages`` as keyword arguments ``callable(i, self,\n",
" | locals())``. If the callable returns ``True`` the fitting procedure\n",
" | is stopped. The monitor can be used for various things such as\n",
" | computing held-out estimates, early stopping, model introspect, and\n",
" | snapshoting.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | self : object\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Readonly properties inherited from BaseGradientBoosting:\n",
" | \n",
" | feature_importances_\n",
" | The impurity-based feature importances.\n",
" | \n",
" | The higher, the more important the feature.\n",
" | The importance of a feature is computed as the (normalized)\n",
" | total reduction of the criterion brought by that feature. It is also\n",
" | known as the Gini importance.\n",
" | \n",
" | Warning: impurity-based feature importances can be misleading for\n",
" | high cardinality features (many unique values). See\n",
" | :func:`sklearn.inspection.permutation_importance` as an alternative.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | feature_importances_ : array, shape (n_features,)\n",
" | The values of this array sum to 1, unless all trees are single node\n",
" | trees consisting of only the root node, in which case it will be an\n",
" | array of zeros.\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Methods inherited from sklearn.ensemble._base.BaseEnsemble:\n",
" | \n",
" | __getitem__(self, index)\n",
" | Return the index'th estimator in the ensemble.\n",
" | \n",
" | __iter__(self)\n",
" | Return iterator over estimators in the ensemble.\n",
" | \n",
" | __len__(self)\n",
" | Return the number of estimators in the ensemble.\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Data and other attributes inherited from sklearn.ensemble._base.BaseEnsemble:\n",
" | \n",
" | __annotations__ = {'_required_parameters': typing.List[str]}\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Methods inherited from sklearn.base.BaseEstimator:\n",
" | \n",
" | __getstate__(self)\n",
" | \n",
" | __repr__(self, N_CHAR_MAX=700)\n",
" | Return repr(self).\n",
" | \n",
" | __setstate__(self, state)\n",
" | \n",
" | get_params(self, deep=True)\n",
" | Get parameters for this estimator.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | deep : bool, default=True\n",
" | If True, will return the parameters for this estimator and\n",
" | contained subobjects that are estimators.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | params : mapping of string to any\n",
" | Parameter names mapped to their values.\n",
" | \n",
" | set_params(self, **params)\n",
" | Set the parameters of this estimator.\n",
" | \n",
" | The method works on simple estimators as well as on nested objects\n",
" | (such as pipelines). The latter have parameters of the form\n",
" | ``<component>__<parameter>`` so that it's possible to update each\n",
" | component of a nested object.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | **params : dict\n",
" | Estimator parameters.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | self : object\n",
" | Estimator instance.\n",
"\n"
]
}
],
"source": [
"help(GradientBoostingClassifier)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.model_selection import GridSearchCV"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"param_grid = {\"n_estimators\":[1,5,10,20,40,100],'max_depth':[3,4,5,6]}"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"gb_model = GradientBoostingClassifier()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"grid = GridSearchCV(gb_model,param_grid)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Fit to Training Data with CV Search"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"GridSearchCV(estimator=GradientBoostingClassifier(),\n",
" param_grid={'max_depth': [3, 4, 5, 6],\n",
" 'n_estimators': [1, 5, 10, 20, 40, 100]})"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"grid.fit(X_train,y_train)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'max_depth': 3, 'n_estimators': 100}"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"grid.best_params_"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Performance "
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.metrics import classification_report,plot_confusion_matrix,accuracy_score"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"predictions = grid.predict(X_test)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['p', 'e', 'p', ..., 'p', 'p', 'e'], dtype=object)"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"predictions"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" precision recall f1-score support\n",
"\n",
" e 1.00 1.00 1.00 655\n",
" p 1.00 1.00 1.00 564\n",
"\n",
" accuracy 1.00 1219\n",
" macro avg 1.00 1.00 1.00 1219\n",
"weighted avg 1.00 1.00 1.00 1219\n",
"\n"
]
}
],
"source": [
"print(classification_report(y_test,predictions))"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([2.91150176e-04, 1.55427847e-17, 2.67658844e-21, 0.00000000e+00,\n",
" 1.11459235e-16, 1.05030313e-03, 3.26837862e-18, 9.23288948e-17,\n",
" 3.33934930e-18, 0.00000000e+00, 1.27133255e-17, 0.00000000e+00,\n",
" 3.56629935e-17, 2.46527883e-21, 0.00000000e+00, 5.60405971e-07,\n",
" 2.31055039e-03, 5.13955090e-02, 1.84253604e-04, 1.40371481e-02,\n",
" 1.82499853e-02, 3.13472494e-03, 6.14744334e-01, 9.20844491e-04,\n",
" 0.00000000e+00, 0.00000000e+00, 5.26020065e-19, 1.25278108e-02,\n",
" 1.16509070e-02, 0.00000000e+00, 4.86322971e-17, 0.00000000e+00,\n",
" 1.08107877e-17, 1.10350576e-21, 0.00000000e+00, 3.66548515e-17,\n",
" 2.07693543e-16, 0.00000000e+00, 1.80938787e-17, 0.00000000e+00,\n",
" 4.39922283e-04, 0.00000000e+00, 1.35977416e-01, 7.71855052e-03,\n",
" 3.23882633e-02, 4.64723214e-04, 1.49599812e-03, 4.95063766e-06,\n",
" 1.83319493e-05, 1.70638552e-06, 3.38601933e-02, 2.07732168e-03,\n",
" 0.00000000e+00, 0.00000000e+00, 6.80156959e-04, 0.00000000e+00,\n",
" 0.00000000e+00, 5.74694069e-04, 0.00000000e+00, 1.84524355e-04,\n",
" 0.00000000e+00, 0.00000000e+00, 5.33104127e-05, 0.00000000e+00,\n",
" 0.00000000e+00, 0.00000000e+00, 3.02342639e-03, 0.00000000e+00,\n",
" 1.35380870e-07, 7.74443653e-05, 2.62871992e-03, 0.00000000e+00,\n",
" 7.08716926e-05, 0.00000000e+00, 1.32788040e-03, 1.83494013e-03,\n",
" 7.34476580e-03, 2.14240381e-04, 2.08941481e-04, 0.00000000e+00,\n",
" 3.04953583e-02, 4.10000880e-03, 4.86768755e-04, 0.00000000e+00,\n",
" 1.17434515e-03, 0.00000000e+00, 7.67619495e-08, 1.34881889e-05,\n",
" 5.50395653e-04, 1.82220979e-16, 0.00000000e+00, 9.07373812e-17,\n",
" 0.00000000e+00, 1.00485103e-05, 0.00000000e+00])"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"grid.best_estimator_.feature_importances_"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"feat_import = grid.best_estimator_.feature_importances_"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"imp_feats = pd.DataFrame(index=X.columns,data=feat_import,columns=['Importance'])"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Importance</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>cap-shape_c</th>\n",
" <td>2.911502e-04</td>\n",
" </tr>\n",
" <tr>\n",
" <th>cap-shape_f</th>\n",
" <td>1.554278e-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>cap-shape_k</th>\n",
" <td>2.676588e-21</td>\n",
" </tr>\n",
" <tr>\n",
" <th>cap-shape_s</th>\n",
" <td>0.000000e+00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>cap-shape_x</th>\n",
" <td>1.114592e-16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>habitat_l</th>\n",
" <td>0.000000e+00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>habitat_m</th>\n",
" <td>9.073738e-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>habitat_p</th>\n",
" <td>0.000000e+00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>habitat_u</th>\n",
" <td>1.004851e-05</td>\n",
" </tr>\n",
" <tr>\n",
" <th>habitat_w</th>\n",
" <td>0.000000e+00</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>95 rows × 1 columns</p>\n",
"</div>"
],
"text/plain": [
" Importance\n",
"cap-shape_c 2.911502e-04\n",
"cap-shape_f 1.554278e-17\n",
"cap-shape_k 2.676588e-21\n",
"cap-shape_s 0.000000e+00\n",
"cap-shape_x 1.114592e-16\n",
"... ...\n",
"habitat_l 0.000000e+00\n",
"habitat_m 9.073738e-17\n",
"habitat_p 0.000000e+00\n",
"habitat_u 1.004851e-05\n",
"habitat_w 0.000000e+00\n",
"\n",
"[95 rows x 1 columns]"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"imp_feats"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Importance</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>odor_n</th>\n",
" <td>0.614744</td>\n",
" </tr>\n",
" <tr>\n",
" <th>stalk-root_c</th>\n",
" <td>0.135977</td>\n",
" </tr>\n",
" <tr>\n",
" <th>bruises_t</th>\n",
" <td>0.051396</td>\n",
" </tr>\n",
" <tr>\n",
" <th>stalk-surface-below-ring_y</th>\n",
" <td>0.033860</td>\n",
" </tr>\n",
" <tr>\n",
" <th>stalk-root_r</th>\n",
" <td>0.032388</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>veil-color_o</th>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>gill-color_y</th>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>odor_y</th>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>odor_s</th>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>habitat_w</th>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>95 rows × 1 columns</p>\n",
"</div>"
],
"text/plain": [
" Importance\n",
"odor_n 0.614744\n",
"stalk-root_c 0.135977\n",
"bruises_t 0.051396\n",
"stalk-surface-below-ring_y 0.033860\n",
"stalk-root_r 0.032388\n",
"... ...\n",
"veil-color_o 0.000000\n",
"gill-color_y 0.000000\n",
"odor_y 0.000000\n",
"odor_s 0.000000\n",
"habitat_w 0.000000\n",
"\n",
"[95 rows x 1 columns]"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"imp_feats.sort_values(\"Importance\",ascending=False)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>count</th>\n",
" <th>mean</th>\n",
" <th>std</th>\n",
" <th>min</th>\n",
" <th>25%</th>\n",
" <th>50%</th>\n",
" <th>75%</th>\n",
" <th>max</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Importance</th>\n",
" <td>95.0</td>\n",
" <td>0.010526</td>\n",
" <td>0.06463</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>1.822210e-16</td>\n",
" <td>0.000801</td>\n",
" <td>0.614744</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" count mean std min 25% 50% 75% \\\n",
"Importance 95.0 0.010526 0.06463 0.0 0.0 1.822210e-16 0.000801 \n",
"\n",
" max \n",
"Importance 0.614744 "
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"imp_feats.describe().transpose()"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
"imp_feats = imp_feats[imp_feats['Importance'] > 0.000527]"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Importance</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>population_y</th>\n",
" <td>0.000550</td>\n",
" </tr>\n",
" <tr>\n",
" <th>stalk-color-above-ring_w</th>\n",
" <td>0.000575</td>\n",
" </tr>\n",
" <tr>\n",
" <th>stalk-color-above-ring_n</th>\n",
" <td>0.000680</td>\n",
" </tr>\n",
" <tr>\n",
" <th>odor_p</th>\n",
" <td>0.000921</td>\n",
" </tr>\n",
" <tr>\n",
" <th>cap-surface_g</th>\n",
" <td>0.001050</td>\n",
" </tr>\n",
" <tr>\n",
" <th>population_c</th>\n",
" <td>0.001174</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ring-type_n</th>\n",
" <td>0.001328</td>\n",
" </tr>\n",
" <tr>\n",
" <th>stalk-surface-above-ring_s</th>\n",
" <td>0.001496</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ring-type_p</th>\n",
" <td>0.001835</td>\n",
" </tr>\n",
" <tr>\n",
" <th>stalk-color-above-ring_c</th>\n",
" <td>0.002077</td>\n",
" </tr>\n",
" <tr>\n",
" <th>cap-color_y</th>\n",
" <td>0.002311</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ring-number_o</th>\n",
" <td>0.002629</td>\n",
" </tr>\n",
" <tr>\n",
" <th>stalk-color-below-ring_y</th>\n",
" <td>0.003023</td>\n",
" </tr>\n",
" <tr>\n",
" <th>odor_m</th>\n",
" <td>0.003135</td>\n",
" </tr>\n",
" <tr>\n",
" <th>spore-print-color_u</th>\n",
" <td>0.004100</td>\n",
" </tr>\n",
" <tr>\n",
" <th>spore-print-color_h</th>\n",
" <td>0.007345</td>\n",
" </tr>\n",
" <tr>\n",
" <th>stalk-root_e</th>\n",
" <td>0.007719</td>\n",
" </tr>\n",
" <tr>\n",
" <th>gill-size_n</th>\n",
" <td>0.011651</td>\n",
" </tr>\n",
" <tr>\n",
" <th>gill-spacing_w</th>\n",
" <td>0.012528</td>\n",
" </tr>\n",
" <tr>\n",
" <th>odor_f</th>\n",
" <td>0.014037</td>\n",
" </tr>\n",
" <tr>\n",
" <th>odor_l</th>\n",
" <td>0.018250</td>\n",
" </tr>\n",
" <tr>\n",
" <th>spore-print-color_r</th>\n",
" <td>0.030495</td>\n",
" </tr>\n",
" <tr>\n",
" <th>stalk-root_r</th>\n",
" <td>0.032388</td>\n",
" </tr>\n",
" <tr>\n",
" <th>stalk-surface-below-ring_y</th>\n",
" <td>0.033860</td>\n",
" </tr>\n",
" <tr>\n",
" <th>bruises_t</th>\n",
" <td>0.051396</td>\n",
" </tr>\n",
" <tr>\n",
" <th>stalk-root_c</th>\n",
" <td>0.135977</td>\n",
" </tr>\n",
" <tr>\n",
" <th>odor_n</th>\n",
" <td>0.614744</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Importance\n",
"population_y 0.000550\n",
"stalk-color-above-ring_w 0.000575\n",
"stalk-color-above-ring_n 0.000680\n",
"odor_p 0.000921\n",
"cap-surface_g 0.001050\n",
"population_c 0.001174\n",
"ring-type_n 0.001328\n",
"stalk-surface-above-ring_s 0.001496\n",
"ring-type_p 0.001835\n",
"stalk-color-above-ring_c 0.002077\n",
"cap-color_y 0.002311\n",
"ring-number_o 0.002629\n",
"stalk-color-below-ring_y 0.003023\n",
"odor_m 0.003135\n",
"spore-print-color_u 0.004100\n",
"spore-print-color_h 0.007345\n",
"stalk-root_e 0.007719\n",
"gill-size_n 0.011651\n",
"gill-spacing_w 0.012528\n",
"odor_f 0.014037\n",
"odor_l 0.018250\n",
"spore-print-color_r 0.030495\n",
"stalk-root_r 0.032388\n",
"stalk-surface-below-ring_y 0.033860\n",
"bruises_t 0.051396\n",
"stalk-root_c 0.135977\n",
"odor_n 0.614744"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"imp_feats.sort_values('Importance')"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "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
"text/plain": [
"<Figure size 2800x1200 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(14,6),dpi=200)\n",
"sns.barplot(data=imp_feats.sort_values('Importance'),x=imp_feats.sort_values('Importance').index,y='Importance')\n",
"plt.xticks(rotation=90);"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}