我在数据上应用了scikit决策树算法来获得结果。现在,我想要一种机制来确定对我的算法以用户可读格式进行的预测贡献最大的因素是什么。
示例:假设我的训练和测试数据与下表相同。
<table border='1'>
<thead>
<th>Parameter1</th>
<th>Parameter2</th>
<th>Parameter3</th>
<th>Parameter4</th>
<th>Class</th>
</thead>
<tr>
<td>abc</td>
<td>1</td>
<td>0.5</td>
<td>2</td>
<td>Success</td>
</tr>
<tr>
<td>pqr</td>
<td>1.2</td>
<td>0.6</td>
<td>1.4</td>
<td>Success</td>
</tr>
<tr>
<td>abc</td>
<td>0.9</td>
<td>1</td>
<td>2</td>
<td>Failure</td>
</tr>
</table>
在应用该算法后,我能够以良好的精度预测事物。现在,我想要的是向用户提供对预测成功/失败有贡献的所有参数的权重。
示例:
<table border='1'>
<thead>
<th>Parameter1</th>
<th>Parameter2</th>
<th>Parameter3</th>
<th>Parameter4</th>
<th>Class</th>
</thead>
<tr>
<td style="background-color:#FEF3AD;">50%</td>
<td style="background-color:#00FF00;">80%</td>
<td style="background-color:#00FF00;">80%</td>
<td style="background-color:#FEF3AD;">50%</td>
<td>Success</td>
</tr>
<tr>
<td style="background-color:#00BB00;">100%</td>
<td style="background-color:#00D500;">90%</td>
<td style="background-color:#c9ff00;">70%</td>
<td style="background-color:#00D500;">90%</td>
<td>Success</td>
</tr>
<tr>
<td style="background-color:#FEF3AD;">50%</td>
<td style="background-color:#ff7f39;">10%</td>
<td style="background-color:#ff1a00;">5%</td>
<td style="background-color:#FEF3AD;">50%</td>
<td>Failure</td>
</tr>
</table>
因此,第二个表指示了相关参数在多大程度上有助于该特定行的成功。
到目前为止,我所尝试的是建立以下机制:
- 我正在使用Kendalltau为所有参数寻找相关系数
- 对于所有参数,按查询激发组以获得成功百分比:
SELECT Parameter1, COUNT('SUCCESS')/COUNT(*) FROM table and joins WHERE clauses GROUP BY Parameter1;
-
将参数相关系数添加到从查询中获得的成功百分比中。此步骤是将相关因素添加到正常统计百分比中。
-
将每个参数存储在我的数据库中:示例:
参数1,abc,50%
参数1,pqr,100%
等等…
有更好或更有效的方法吗?请提供详细信息。
谢谢。
您可以使用feature_importances_
来了解每个特性的贡献。然而,feature_importances_
返回的值不直接考虑预测精度。
为此,可以使用mean decrease accuracy
来评估关于特定评估度量的每个特征贡献。下面的博客文章包含了很好的解释和python示例代码。
选择好的功能-第三部分:随机森林-深入数据
mean decrease accuracy
的主要思想是选择一个特征,并在数据集中的所有实例中随机排列特征值,使该特征变得毫无意义。
(A) If accuracy decreases, the selected feature is important for prediction.
(B) If not, the selected feature is not so important for prediction.
使用mean decrease accuracy
的优点是:
(1) You can apply it to any classifiers including ensemble models.
(2) You can apply it to any evaluation metric.