Create 模型解释.ipynb

pull/2/head
benjas 5 years ago
parent 96228851b4
commit 0045dee9be

@ -0,0 +1,845 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Permutation Importance"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.ensemble import RandomForestClassifier"
]
},
{
"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>Date</th>\n",
" <th>Team</th>\n",
" <th>Opponent</th>\n",
" <th>Goal Scored</th>\n",
" <th>Ball Possession %</th>\n",
" <th>Attempts</th>\n",
" <th>On-Target</th>\n",
" <th>Off-Target</th>\n",
" <th>Blocked</th>\n",
" <th>Corners</th>\n",
" <th>...</th>\n",
" <th>Yellow Card</th>\n",
" <th>Yellow &amp; Red</th>\n",
" <th>Red</th>\n",
" <th>Man of the Match</th>\n",
" <th>1st Goal</th>\n",
" <th>Round</th>\n",
" <th>PSO</th>\n",
" <th>Goals in PSO</th>\n",
" <th>Own goals</th>\n",
" <th>Own goal Time</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>14-06-2018</td>\n",
" <td>Russia</td>\n",
" <td>Saudi Arabia</td>\n",
" <td>5</td>\n",
" <td>40</td>\n",
" <td>13</td>\n",
" <td>7</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>6</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>Yes</td>\n",
" <td>12.0</td>\n",
" <td>Group Stage</td>\n",
" <td>No</td>\n",
" <td>0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>14-06-2018</td>\n",
" <td>Saudi Arabia</td>\n",
" <td>Russia</td>\n",
" <td>0</td>\n",
" <td>60</td>\n",
" <td>6</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>2</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>No</td>\n",
" <td>NaN</td>\n",
" <td>Group Stage</td>\n",
" <td>No</td>\n",
" <td>0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>15-06-2018</td>\n",
" <td>Egypt</td>\n",
" <td>Uruguay</td>\n",
" <td>0</td>\n",
" <td>43</td>\n",
" <td>8</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>No</td>\n",
" <td>NaN</td>\n",
" <td>Group Stage</td>\n",
" <td>No</td>\n",
" <td>0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>15-06-2018</td>\n",
" <td>Uruguay</td>\n",
" <td>Egypt</td>\n",
" <td>1</td>\n",
" <td>57</td>\n",
" <td>14</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>...</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>Yes</td>\n",
" <td>89.0</td>\n",
" <td>Group Stage</td>\n",
" <td>No</td>\n",
" <td>0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>15-06-2018</td>\n",
" <td>Morocco</td>\n",
" <td>Iran</td>\n",
" <td>0</td>\n",
" <td>64</td>\n",
" <td>13</td>\n",
" <td>3</td>\n",
" <td>6</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>No</td>\n",
" <td>NaN</td>\n",
" <td>Group Stage</td>\n",
" <td>No</td>\n",
" <td>0</td>\n",
" <td>1.0</td>\n",
" <td>90.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>5 rows × 27 columns</p>\n",
"</div>"
],
"text/plain": [
" Date Team Opponent Goal Scored Ball Possession % \\\n",
"0 14-06-2018 Russia Saudi Arabia 5 40 \n",
"1 14-06-2018 Saudi Arabia Russia 0 60 \n",
"2 15-06-2018 Egypt Uruguay 0 43 \n",
"3 15-06-2018 Uruguay Egypt 1 57 \n",
"4 15-06-2018 Morocco Iran 0 64 \n",
"\n",
" Attempts On-Target Off-Target Blocked Corners ... Yellow Card \\\n",
"0 13 7 3 3 6 ... 0 \n",
"1 6 0 3 3 2 ... 0 \n",
"2 8 3 3 2 0 ... 2 \n",
"3 14 4 6 4 5 ... 0 \n",
"4 13 3 6 4 5 ... 1 \n",
"\n",
" Yellow & Red Red Man of the Match 1st Goal Round PSO \\\n",
"0 0 0 Yes 12.0 Group Stage No \n",
"1 0 0 No NaN Group Stage No \n",
"2 0 0 No NaN Group Stage No \n",
"3 0 0 Yes 89.0 Group Stage No \n",
"4 0 0 No NaN Group Stage No \n",
"\n",
" Goals in PSO Own goals Own goal Time \n",
"0 0 NaN NaN \n",
"1 0 NaN NaN \n",
"2 0 NaN NaN \n",
"3 0 NaN NaN \n",
"4 0 1.0 90.0 \n",
"\n",
"[5 rows x 27 columns]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data = pd.read_csv('data/FIFA 2018 Statistics.csv') # 足球赛事数据集\n",
"data.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"怎么知道哪些特征影响多大\n",
"\n",
"破坏特征比如把Goal Scored上下的顺序打乱其它不变然后比较破坏前和后的区别\n",
"\n",
"如果前 ≈ 后,说明这个特征对结果没影响\n",
"如果后 前,说明这个特征对结果影响起正作用\n",
"如果后 前,说明这个特征对结果影响起负作用(一般不会出现)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 True\n",
"1 False\n",
"2 False\n",
"3 True\n",
"4 False\n",
"Name: Man of the Match, dtype: bool"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y = (data['Man of the Match'] == 'Yes') # 转换标签\n",
"y[:5]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"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>Goal Scored</th>\n",
" <th>Ball Possession %</th>\n",
" <th>Attempts</th>\n",
" <th>On-Target</th>\n",
" <th>Off-Target</th>\n",
" <th>Blocked</th>\n",
" <th>Corners</th>\n",
" <th>Offsides</th>\n",
" <th>Free Kicks</th>\n",
" <th>Saves</th>\n",
" <th>Pass Accuracy %</th>\n",
" <th>Passes</th>\n",
" <th>Distance Covered (Kms)</th>\n",
" <th>Fouls Committed</th>\n",
" <th>Yellow Card</th>\n",
" <th>Yellow &amp; Red</th>\n",
" <th>Red</th>\n",
" <th>Goals in PSO</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>5</td>\n",
" <td>40</td>\n",
" <td>13</td>\n",
" <td>7</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>6</td>\n",
" <td>3</td>\n",
" <td>11</td>\n",
" <td>0</td>\n",
" <td>78</td>\n",
" <td>306</td>\n",
" <td>118</td>\n",
" <td>22</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0</td>\n",
" <td>60</td>\n",
" <td>6</td>\n",
" <td>0</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>25</td>\n",
" <td>2</td>\n",
" <td>86</td>\n",
" <td>511</td>\n",
" <td>105</td>\n",
" <td>10</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>43</td>\n",
" <td>8</td>\n",
" <td>3</td>\n",
" <td>3</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>7</td>\n",
" <td>3</td>\n",
" <td>78</td>\n",
" <td>395</td>\n",
" <td>112</td>\n",
" <td>12</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1</td>\n",
" <td>57</td>\n",
" <td>14</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>1</td>\n",
" <td>13</td>\n",
" <td>3</td>\n",
" <td>86</td>\n",
" <td>589</td>\n",
" <td>111</td>\n",
" <td>6</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0</td>\n",
" <td>64</td>\n",
" <td>13</td>\n",
" <td>3</td>\n",
" <td>6</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>0</td>\n",
" <td>14</td>\n",
" <td>2</td>\n",
" <td>86</td>\n",
" <td>433</td>\n",
" <td>101</td>\n",
" <td>22</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Goal Scored Ball Possession % Attempts On-Target Off-Target Blocked \\\n",
"0 5 40 13 7 3 3 \n",
"1 0 60 6 0 3 3 \n",
"2 0 43 8 3 3 2 \n",
"3 1 57 14 4 6 4 \n",
"4 0 64 13 3 6 4 \n",
"\n",
" Corners Offsides Free Kicks Saves Pass Accuracy % Passes \\\n",
"0 6 3 11 0 78 306 \n",
"1 2 1 25 2 86 511 \n",
"2 0 1 7 3 78 395 \n",
"3 5 1 13 3 86 589 \n",
"4 5 0 14 2 86 433 \n",
"\n",
" Distance Covered (Kms) Fouls Committed Yellow Card Yellow & Red Red \\\n",
"0 118 22 0 0 0 \n",
"1 105 10 0 0 0 \n",
"2 112 12 2 0 0 \n",
"3 111 6 0 0 0 \n",
"4 101 22 1 0 0 \n",
"\n",
" Goals in PSO \n",
"0 0 \n",
"1 0 \n",
"2 0 \n",
"3 0 \n",
"4 0 "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"feature_names = [i for i in data.columns if data[i].dtype in [np.int64]]\n",
"X = data[feature_names]\n",
"X.head()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"D:\\Anaconda3\\lib\\site-packages\\sklearn\\ensemble\\forest.py:245: FutureWarning: The default value of n_estimators will change from 10 in version 0.20 to 100 in 0.22.\n",
" \"10 in version 0.20 to 100 in 0.22.\", FutureWarning)\n"
]
}
],
"source": [
"train_X, val_X,train_y,val_y = train_test_split(X, y,random_state=1)\n",
"my_model = RandomForestClassifier(random_state=0).fit(train_X,train_y)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" <style>\n",
" table.eli5-weights tr:hover {\n",
" filter: brightness(85%);\n",
" }\n",
"</style>\n",
"\n",
"\n",
"\n",
" \n",
"\n",
" \n",
"\n",
" \n",
"\n",
" \n",
"\n",
" \n",
"\n",
" \n",
"\n",
"\n",
" \n",
"\n",
" \n",
"\n",
" \n",
"\n",
" \n",
"\n",
" \n",
"\n",
" \n",
"\n",
"\n",
" \n",
"\n",
" \n",
"\n",
" \n",
"\n",
" \n",
"\n",
" \n",
" <table class=\"eli5-weights eli5-feature-importances\" style=\"border-collapse: collapse; border: none; margin-top: 0em; table-layout: auto;\">\n",
" <thead>\n",
" <tr style=\"border: none;\">\n",
" <th style=\"padding: 0 1em 0 0.5em; text-align: right; border: none;\">Weight</th>\n",
" <th style=\"padding: 0 0.5em 0 0.5em; text-align: left; border: none;\">Feature</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" \n",
" <tr style=\"background-color: hsl(120, 100.00%, 80.00%); border: none;\">\n",
" <td style=\"padding: 0 1em 0 0.5em; text-align: right; border: none;\">\n",
" 0.0750\n",
" \n",
" &plusmn; 0.1159\n",
" \n",
" </td>\n",
" <td style=\"padding: 0 0.5em 0 0.5em; text-align: left; border: none;\">\n",
" Goal Scored\n",
" </td>\n",
" </tr>\n",
" \n",
" <tr style=\"background-color: hsl(120, 100.00%, 82.40%); border: none;\">\n",
" <td style=\"padding: 0 1em 0 0.5em; text-align: right; border: none;\">\n",
" 0.0625\n",
" \n",
" &plusmn; 0.0791\n",
" \n",
" </td>\n",
" <td style=\"padding: 0 0.5em 0 0.5em; text-align: left; border: none;\">\n",
" Corners\n",
" </td>\n",
" </tr>\n",
" \n",
" <tr style=\"background-color: hsl(120, 100.00%, 86.29%); border: none;\">\n",
" <td style=\"padding: 0 1em 0 0.5em; text-align: right; border: none;\">\n",
" 0.0437\n",
" \n",
" &plusmn; 0.0500\n",
" \n",
" </td>\n",
" <td style=\"padding: 0 0.5em 0 0.5em; text-align: left; border: none;\">\n",
" Distance Covered (Kms)\n",
" </td>\n",
" </tr>\n",
" \n",
" <tr style=\"background-color: hsl(120, 100.00%, 87.69%); border: none;\">\n",
" <td style=\"padding: 0 1em 0 0.5em; text-align: right; border: none;\">\n",
" 0.0375\n",
" \n",
" &plusmn; 0.0729\n",
" \n",
" </td>\n",
" <td style=\"padding: 0 0.5em 0 0.5em; text-align: left; border: none;\">\n",
" On-Target\n",
" </td>\n",
" </tr>\n",
" \n",
" <tr style=\"background-color: hsl(120, 100.00%, 87.69%); border: none;\">\n",
" <td style=\"padding: 0 1em 0 0.5em; text-align: right; border: none;\">\n",
" 0.0375\n",
" \n",
" &plusmn; 0.0468\n",
" \n",
" </td>\n",
" <td style=\"padding: 0 0.5em 0 0.5em; text-align: left; border: none;\">\n",
" Free Kicks\n",
" </td>\n",
" </tr>\n",
" \n",
" <tr style=\"background-color: hsl(120, 100.00%, 92.42%); border: none;\">\n",
" <td style=\"padding: 0 1em 0 0.5em; text-align: right; border: none;\">\n",
" 0.0187\n",
" \n",
" &plusmn; 0.0306\n",
" \n",
" </td>\n",
" <td style=\"padding: 0 0.5em 0 0.5em; text-align: left; border: none;\">\n",
" Blocked\n",
" </td>\n",
" </tr>\n",
" \n",
" <tr style=\"background-color: hsl(120, 100.00%, 94.29%); border: none;\">\n",
" <td style=\"padding: 0 1em 0 0.5em; text-align: right; border: none;\">\n",
" 0.0125\n",
" \n",
" &plusmn; 0.0750\n",
" \n",
" </td>\n",
" <td style=\"padding: 0 0.5em 0 0.5em; text-align: left; border: none;\">\n",
" Pass Accuracy %\n",
" </td>\n",
" </tr>\n",
" \n",
" <tr style=\"background-color: hsl(120, 100.00%, 94.29%); border: none;\">\n",
" <td style=\"padding: 0 1em 0 0.5em; text-align: right; border: none;\">\n",
" 0.0125\n",
" \n",
" &plusmn; 0.0500\n",
" \n",
" </td>\n",
" <td style=\"padding: 0 0.5em 0 0.5em; text-align: left; border: none;\">\n",
" Yellow Card\n",
" </td>\n",
" </tr>\n",
" \n",
" <tr style=\"background-color: hsl(120, 100.00%, 96.49%); border: none;\">\n",
" <td style=\"padding: 0 1em 0 0.5em; text-align: right; border: none;\">\n",
" 0.0063\n",
" \n",
" &plusmn; 0.0468\n",
" \n",
" </td>\n",
" <td style=\"padding: 0 0.5em 0 0.5em; text-align: left; border: none;\">\n",
" Saves\n",
" </td>\n",
" </tr>\n",
" \n",
" <tr style=\"background-color: hsl(120, 100.00%, 96.49%); border: none;\">\n",
" <td style=\"padding: 0 1em 0 0.5em; text-align: right; border: none;\">\n",
" 0.0063\n",
" \n",
" &plusmn; 0.0250\n",
" \n",
" </td>\n",
" <td style=\"padding: 0 0.5em 0 0.5em; text-align: left; border: none;\">\n",
" Offsides\n",
" </td>\n",
" </tr>\n",
" \n",
" <tr style=\"background-color: hsl(120, 100.00%, 96.49%); border: none;\">\n",
" <td style=\"padding: 0 1em 0 0.5em; text-align: right; border: none;\">\n",
" 0.0063\n",
" \n",
" &plusmn; 0.1741\n",
" \n",
" </td>\n",
" <td style=\"padding: 0 0.5em 0 0.5em; text-align: left; border: none;\">\n",
" Off-Target\n",
" </td>\n",
" </tr>\n",
" \n",
" <tr style=\"background-color: hsl(0, 100.00%, 100.00%); border: none;\">\n",
" <td style=\"padding: 0 1em 0 0.5em; text-align: right; border: none;\">\n",
" 0.0000\n",
" \n",
" &plusmn; 0.1046\n",
" \n",
" </td>\n",
" <td style=\"padding: 0 0.5em 0 0.5em; text-align: left; border: none;\">\n",
" Passes\n",
" </td>\n",
" </tr>\n",
" \n",
" <tr style=\"background-color: hsl(0, 100.00%, 100.00%); border: none;\">\n",
" <td style=\"padding: 0 1em 0 0.5em; text-align: right; border: none;\">\n",
" 0\n",
" \n",
" &plusmn; 0.0000\n",
" \n",
" </td>\n",
" <td style=\"padding: 0 0.5em 0 0.5em; text-align: left; border: none;\">\n",
" Red\n",
" </td>\n",
" </tr>\n",
" \n",
" <tr style=\"background-color: hsl(0, 100.00%, 100.00%); border: none;\">\n",
" <td style=\"padding: 0 1em 0 0.5em; text-align: right; border: none;\">\n",
" 0\n",
" \n",
" &plusmn; 0.0000\n",
" \n",
" </td>\n",
" <td style=\"padding: 0 0.5em 0 0.5em; text-align: left; border: none;\">\n",
" Yellow &amp; Red\n",
" </td>\n",
" </tr>\n",
" \n",
" <tr style=\"background-color: hsl(0, 100.00%, 100.00%); border: none;\">\n",
" <td style=\"padding: 0 1em 0 0.5em; text-align: right; border: none;\">\n",
" 0\n",
" \n",
" &plusmn; 0.0000\n",
" \n",
" </td>\n",
" <td style=\"padding: 0 0.5em 0 0.5em; text-align: left; border: none;\">\n",
" Goals in PSO\n",
" </td>\n",
" </tr>\n",
" \n",
" <tr style=\"background-color: hsl(0, 100.00%, 89.16%); border: none;\">\n",
" <td style=\"padding: 0 1em 0 0.5em; text-align: right; border: none;\">\n",
" -0.0312\n",
" \n",
" &plusmn; 0.0884\n",
" \n",
" </td>\n",
" <td style=\"padding: 0 0.5em 0 0.5em; text-align: left; border: none;\">\n",
" Fouls Committed\n",
" </td>\n",
" </tr>\n",
" \n",
" <tr style=\"background-color: hsl(0, 100.00%, 87.69%); border: none;\">\n",
" <td style=\"padding: 0 1em 0 0.5em; text-align: right; border: none;\">\n",
" -0.0375\n",
" \n",
" &plusmn; 0.0919\n",
" \n",
" </td>\n",
" <td style=\"padding: 0 0.5em 0 0.5em; text-align: left; border: none;\">\n",
" Attempts\n",
" </td>\n",
" </tr>\n",
" \n",
" <tr style=\"background-color: hsl(0, 100.00%, 84.94%); border: none;\">\n",
" <td style=\"padding: 0 1em 0 0.5em; text-align: right; border: none;\">\n",
" -0.0500\n",
" \n",
" &plusmn; 0.0500\n",
" \n",
" </td>\n",
" <td style=\"padding: 0 0.5em 0 0.5em; text-align: left; border: none;\">\n",
" Ball Possession %\n",
" </td>\n",
" </tr>\n",
" \n",
" \n",
" </tbody>\n",
"</table>\n",
" \n",
"\n",
" \n",
"\n",
"\n",
" \n",
"\n",
" \n",
"\n",
" \n",
"\n",
" \n",
"\n",
" \n",
"\n",
" \n",
"\n",
"\n",
"\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import eli5 # pip install eli5\n",
"from eli5.sklearn import PermutationImportance\n",
"\n",
"perm = PermutationImportance(my_model,random_state=1).fit(val_X, val_y)\n",
"\n",
"eli5.show_weights(perm, feature_names=val_X.columns.tolist())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Partial Dependence Plots\n",
"\n",
"特征重要性展示了每个特征发挥的作用情况partial dependence plots 可以展示一个特征怎么影响预测结果\n",
"\n",
"模型建立完成后进行使用,概述如下:"
]
}
],
"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
}
Loading…
Cancel
Save