-
Notifications
You must be signed in to change notification settings - Fork 80
add ranks #268
Merged
Merged
add ranks #268
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a2dd7be
add ranks
Ama16 25d8833
fix MRMR transform
Ama16 522f42e
fix
Ama16 88b726c
fix lint
Ama16 588d1f4
final
Ama16 2f7b365
final (no mrmr)
Ama16 d635cb4
final
Ama16 d097515
fix conflicts
Ama16 29a9ac8
Merge branch 'master' of https://github.com/tinkoff-ai/etna-ts into E…
julia-shenshina 42ef927
Upd CHANGELOG
julia-shenshina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,6 +142,7 @@ class MRMRFeatureSelectionTransform(Transform): | |
def __init__( | ||
self, | ||
relevance_method: RelevanceTable, | ||
return_ranks: bool, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
top_k: int, | ||
clustering_method: HierarchicalClustering = EuclideanClustering(), | ||
n_clusters: int = 10, | ||
|
@@ -155,6 +156,8 @@ def __init__( | |
---------- | ||
relevance_method: | ||
method to calculate relevance table | ||
return_ranks: | ||
if False use relevance table else use ranks of relevance table | ||
top_k: | ||
num of regressors to select; if there are not enough regressors, then all will be selected | ||
clustering_method: | ||
|
@@ -171,6 +174,7 @@ def __init__( | |
raise ValueError("Parameter n_clusters should be integer and greater than 1") | ||
|
||
self.relevance_method = relevance_method | ||
self.return_ranks = return_ranks | ||
self.clustering = clustering_method | ||
self.n_clusters = n_clusters | ||
self.linkage = linkage | ||
|
@@ -208,7 +212,9 @@ def fit(self, df: pd.DataFrame) -> "MRMRFeatureSelectionTransform": | |
self.clustering.build_distance_matrix(ts=ts) | ||
self.clustering.build_clustering_algo(n_clusters=self.n_clusters, linkage=self.linkage) | ||
s2c = self.clustering.fit_predict() | ||
relevance_table = self.relevance_method(ts[:, :, "target"], ts[:, :, ts.regressors], **self.relevance_params) | ||
relevance_table = self.relevance_method( | ||
alex-hse-repository marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ts[:, :, "target"], ts[:, :, ts.regressors], return_ranks=self.return_ranks, **self.relevance_params | ||
) | ||
y = np.empty(len(relevance_table)) | ||
for k, cluster in enumerate(relevance_table.index): | ||
y[k] = s2c[cluster] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,7 @@ def ts_with_regressors(): | |
def test_mrmr_right_len(relevance_method, clustering_method, top_k, ts_with_regressors): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to use keyword arguments, fix it pls in this file |
||
"""Check that transform selects exactly top_k regressors.""" | ||
df = ts_with_regressors.to_pandas() | ||
mrmr = MRMRFeatureSelectionTransform(relevance_method, top_k, clustering_method, n_clusters=2) | ||
mrmr = MRMRFeatureSelectionTransform(relevance_method, False, top_k, clustering_method, n_clusters=2) | ||
df_selected = mrmr.fit_transform(df) | ||
all_regressors = ts_with_regressors.regressors | ||
selected_regressors = set() | ||
|
@@ -93,7 +93,7 @@ def test_mrmr_right_len(relevance_method, clustering_method, top_k, ts_with_regr | |
def test_mrmr_right_regressors(relevance_method, clustering_method, ts_with_regressors): | ||
"""Check that transform selects right top_k regressors.""" | ||
df = ts_with_regressors.to_pandas() | ||
mrmr = MRMRFeatureSelectionTransform(relevance_method, 3, clustering_method, n_clusters=2) | ||
mrmr = MRMRFeatureSelectionTransform(relevance_method, False, 3, clustering_method, n_clusters=2) | ||
df_selected = mrmr.fit_transform(df) | ||
selected_regressors = set() | ||
for column in df_selected.columns.get_level_values("feature"): | ||
|
@@ -105,14 +105,14 @@ def test_mrmr_right_regressors(relevance_method, clustering_method, ts_with_regr | |
def test_mrmr_fails_negative_parameters(): | ||
"""Check that transform doesn't allow you to set top_k to negative values and n_clusters >= 2.""" | ||
with pytest.raises(ValueError, match="positive integer"): | ||
MRMRFeatureSelectionTransform(StatisticsRelevanceTable(), top_k=-1) | ||
MRMRFeatureSelectionTransform(StatisticsRelevanceTable(), False, top_k=-1) | ||
with pytest.raises(ValueError, match="greater than"): | ||
MRMRFeatureSelectionTransform(StatisticsRelevanceTable(), top_k=1, n_clusters=1) | ||
MRMRFeatureSelectionTransform(StatisticsRelevanceTable(), False, top_k=1, n_clusters=1) | ||
|
||
|
||
def test_mrmr_fails(ts_with_regressors): | ||
"""Check that transform doesn't allow you to set n_clusters greater than number of regressors.""" | ||
mrmr = MRMRFeatureSelectionTransform(StatisticsRelevanceTable(), top_k=4, freq="D", n_clusters=25) | ||
mrmr = MRMRFeatureSelectionTransform(StatisticsRelevanceTable(), False, top_k=4, freq="D", n_clusters=25) | ||
with pytest.raises(ValueError, match="strictly less than"): | ||
mrmr.fit_transform(ts_with_regressors.to_pandas()) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we add
False
as default value forreturn_ranks
?