You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ENH/Design: collect tools for neighborhood indices, binning, coarsening #5388
We need every once in a while function for defining neighborhood or converting continuous variables into groups or bins.
two different cases
neighborhoods of each observation:
for one, possibly multivariate variable: find neighbors e.g. local regression
for two variables: find neighbors in second dataset, e.g. matching estimators PSM
binning or coarsening (has weird name in pandas and R): partition continuous sample space
partition dataset into finite discrete subsets
several use cases already for binning, e.g. kde, in my differencing nonparametric PR, gof tests
grid: equal spaced
coarsening: approximately equal spaced
aside: setup cost and keeping intermediate information around.
AFAIR (might be incorrect):
lowess does not store the neighborhood indices, it is directly integrated in the estimation model, This makes it impossible to swap the neighborhood
full, non-binned kde also loops through the intervals without keeping neighborhood indices
scikit-learn keeps indices or neighborhood data as attribute for reuse during optimization and similar.
current use cases in statsmodels (AFAIR)
binning:
kde, my kernel regression, differencing PR (includes 2-D binning IIRC)
gof-tests, equal spacing or equal weight bins. chisquare test, Hosmer-Lemeshow (not yet) but similar in discrete._diagnostic_count
GAM, splines knot selection, defines intervals based on quantiles (of data) or equal spaced
neighbor matching
imputation
propensity score matching PR
related
discrete points instead of intervals: e.g. predict when we want to evaluate a function on percentiles of exog.
We need helper functions for the predict_at and margins use case to create new selective datasets, e.g. similar to the lsmeans case.
It is a bit cumbersome to create DataFrames when looking at different percentiles of one or two variables keeping the others constant or averaging over the others, or creating it for each level of the categorical variables. It's similar if we want to plot predictions at predefined grid values.
Aside: R mgcv package is nice because it has the tools functions exposed and in the documentation, especially linalg tools.
R robust base is the opposite, essentially everything is hiding behind a few high level function or models that combine various different approaches in a few huge functions.
semi-random thought
binning for discretized GOF test might be easier to do with pandas.
i.e. I think we need unique_rows or pivot table or something similar after coarsening the data.
binning with freq_weights or binning discrete distributions #4359
I wrote the discrete distribution binning initially for the scipy unit test suite to use with chisquare test.
Related, combining cells in categorical analysis and contingency tables to get a minimum number of observations in each bin.
Kerby had added weightstats quantiles that also use freq_weights to compute the quantiles (i.e. corresponding to cut points)
tool: (experiments for Hosmer-Lemeshow type tests)
np.array_split works well for close to equal binning, i.e. split sorted arrays into close to equal subarrays to compute statistics like freq for chi2 test for subarrays.
Activity
josef-pkt commentedon Nov 16, 2018
Aside: R mgcv package is nice because it has the
toolsfunctions exposed and in the documentation, especially linalg tools.R robust base is the opposite, essentially everything is hiding behind a few high level function or models that combine various different approaches in a few huge functions.
josef-pkt commentedon Feb 1, 2019
semi-random thought
binning for discretized GOF test might be easier to do with pandas.
i.e. I think we need unique_rows or pivot table or something similar after coarsening the data.
josef-pkt commentedon May 28, 2019
(just found by chance in related search)
binning with freq_weights or binning discrete distributions #4359
I wrote the discrete distribution binning initially for the scipy unit test suite to use with chisquare test.
Related, combining cells in categorical analysis and contingency tables to get a minimum number of observations in each bin.
Kerby had added weightstats quantiles that also use freq_weights to compute the quantiles (i.e. corresponding to cut points)
josef-pkt commentedon Oct 4, 2020
tool: (experiments for Hosmer-Lemeshow type tests)
np.array_splitworks well for close to equal binning, i.e. split sorted arrays into close to equal subarrays to compute statistics like freq for chi2 test for subarrays.