Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor package and add utilities documentation #156

Merged
merged 21 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove random_forest module and add kmerf to independence
  • Loading branch information
sampan501 committed Jan 11, 2021
commit 639e7cad95c94adc0b121f0f99eb7cb1cc953cb8
1 change: 0 additions & 1 deletion hyppo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
import hyppo.time_series
import hyppo.tools
import hyppo.discrim
import hyppo.random_forest

__version__ = "0.1.3"
3 changes: 2 additions & 1 deletion hyppo/independence/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
from .dcorr import Dcorr
from .hsic import Hsic
from .mgc import MGC
from .kmerf import KMERF

__all__ = ["RV", "CCA", "HHG", "Dcorr", "Hsic", "MGC"]
__all__ = [s for s in dir()] # add imported tests to __all__
12 changes: 12 additions & 0 deletions hyppo/independence/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,15 @@ def _check_min_samples(self):
def _check_variance(self):
if np.var(self.x) == 0 or np.var(self.y) == 0:
raise ValueError("Test cannot be run, one of the inputs has 0 variance")


def sim_matrix(model, x):
terminals = model.apply(x)
ntrees = terminals.shape[1]

proxMat = 1 * np.equal.outer(terminals[:, 0], terminals[:, 0])
for i in range(1, ntrees):
proxMat += 1 * np.equal.outer(terminals[:, i], terminals[:, i])
proxMat = proxMat / ntrees

return proxMat
8 changes: 4 additions & 4 deletions hyppo/random_forest/kmerf.py → hyppo/independence/kmerf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
from sklearn.metrics import pairwise_distances

from .base import RandomForestTest
from .base import IndependenceTest
from ._utils import _CheckInputs, sim_matrix
from ..independence import Dcorr
from . import Dcorr
from ..tools import perm_test


Expand All @@ -14,7 +14,7 @@
}


class KMERF(RandomForestTest):
class KMERF(IndependenceTest):
r"""
Class for calculating the random forest based Dcorr test statistic and p-value.
"""
Expand All @@ -24,7 +24,7 @@ def __init__(self, forest="regressor", ntrees=500, **kwargs):
self.clf = FOREST_TYPES[forest](n_estimators=ntrees, **kwargs)
else:
raise ValueError("Forest must be of type classification or regression")
RandomForestTest.__init__(self)
IndependenceTest.__init__(self)

def _statistic(self, x, y):
r"""
Expand Down
3 changes: 0 additions & 3 deletions hyppo/random_forest/__init__.py

This file was deleted.

82 changes: 0 additions & 82 deletions hyppo/random_forest/_utils.py

This file was deleted.

48 changes: 0 additions & 48 deletions hyppo/random_forest/base.py

This file was deleted.

Empty file.