Package: sklearn-gbmi
Warning:this package has reached the end of its life.
It is incompatible with recent versions of scikit-learn, and I (Ralph Haygood) have neither the time nor the interest to solve this problem.
If you wish to have a go at it yourself, by all means fork the GitHub repository and proceed.Ultimately, the problem may be one or more incompatibilities between recent versions of scikit-learn and/or NumPy and a wad (25,644 lines) of C code not written by me, which I was forced to add to this package when the maintainers of scikit-learn replaced thesklearn.ensemble.partial_dependence.partial_dependencefunction with the not-fully-equivalentsklearn.inspection.partial_dependencefunction.
This package depended on the grid argument of the former, which is missing from the latter.
I worked around this defect by extracting the code that had implemented the grid argument and integrating it into this package.
However, this code may well depend on internal characteristics of scikit-learn or NumPy that have changed since then.sklearn-gbmi: scikit-learn gradient-boosting-model interactionsThis package provides a Python module for computing Friedman and Popescu’sHstatistics, in order to look for
interactions among variables in scikit-learn gradient-boosting models
(http://scikit-learn.org/stable/modules/ensemble.html#gradient-tree-boosting).See Jerome H. Friedman and Bogdan E. Popescu, 2008, “Predictive learning via rule ensembles”,Ann. Appl. Stat.2:916-954,http://projecteuclid.org/download/pdfview_1/euclid.aoas/1223908046, s. 8.1.Installationpip install sklearn-gbmiOn some systems, if you wish to use this package with Python 3, then you must install withpip3rather thanpip.In case of difficulties with installing or using this package, consult “Advanced installation” below.UsageGiven a scikit-learn gradient-boosting modelgbmthat has been fitted to a NumPy array or pandas data framearray_or_frameand a list of indices of columns of the array or columns of the data frameindices_or_columns, theHstatistic of the variables represented by the elements ofarray_or_frameand specified byindices_or_columnscan
be computed viafrom sklearn_gbmi import *h(gbm, array_or_frame, indices_or_columns)Alternatively, the two-variableHstatistic of each pair of variables represented by the elements ofarray_or_frameand specified byindices_or_columnscan be computed viafrom sklearn_gbmi import *h_all_pairs(gbm, array_or_frame, indices_or_columns)(Compared to iteratively callingh, callingh_all_pairsavoids redundant computations.)indices_or_columnsis optional, with default value‘all’. If it is‘all’, then all columns ofarray_or_frameare
used.NaNis returned if a computation is spoiled by weak main effects and rounding errors.Hvaries from 0 to 1. The largerH, the stronger the evidence for an interaction among the variables.ExampleSee the Jupyter notebook example.ipynb (https://github.com/ralphhaygood/sklearn-gbmi/blob/master/example.ipynb) for a
complete example of how to use this package.Notes1. Per Friedman and Popescu, only variables with strong main effects should be examined for interactions. Strengths of
main effects are available asgbm.feature_importances_oncegbmhas been fitted.2. Per Friedman and Popescu, collinearity among variables can lead to interactions ingbmthat are not present in the
target function. To forestall such spurious interactions, check for strong correlations among variables before fittinggbm.Advanced installationInstalling this package requires NumPy, so if installation fails with a complaint that NumPy is missing, add it to the
install command:pip install numpy sklearn-gbmiFor performance, this package is partly implemented using Cython (C extensions for Python). It includes a C file that
was generated by Cython, which is compiled for your system when you install the package. Normally, this C file is fine,
but occasionally, it may not compile, or the result may not run. In the first case, installing the package fails, while
in the second case, using the package fails, typically with a cryptic error message; for example:ValueError: sklearn.tree._criterion.Criterion size changed, may indicate binary incompatibility.In such a case, you may still be able to install and use the package by regenerating the C file, as follows.First, if this package is installed (i.e., installation succeeds, but usage fails), uninstall it:pip uninstall sklearn-gbmiThen, install Cython:pip install cythonNext, set the environment variableUSE_CYTHONIZEto 1. For bash and similar shells:export USE_CYTHONIZE=1For csh and similar shells:setenv USE_CYTHONIZE 1Finally, reinstall this package:pip install sklearn-gbmi –no-cache-dirThe C file should be regenerated and compiled for your system, hopefully making this package usable on your system.