-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add tests for penalised score
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Tests for compositions.""" |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Tests for penalised scores.""" | ||
|
||
import numpy as np | ||
import pandas as pd | ||
import pytest | ||
|
||
from skchange.change_scores import CUSUM, MultivariateGaussianScore | ||
from skchange.compose import PenalisedScore | ||
from skchange.penalties.constant_penalties import BICPenalty | ||
from skchange.penalties.linear_penalties import LinearChiSquarePenalty | ||
|
||
|
||
def test_penalised_score_init(): | ||
scorer = CUSUM() | ||
penalty = BICPenalty() | ||
penalised_score = PenalisedScore(scorer, penalty) | ||
assert penalised_score.expected_cut_entries == scorer.expected_cut_entries | ||
|
||
scorer = MultivariateGaussianScore() | ||
penalty = LinearChiSquarePenalty() | ||
|
||
with pytest.raises(ValueError): | ||
PenalisedScore(scorer, penalty) | ||
|
||
|
||
def test_penalised_score_fit(): | ||
scorer = CUSUM() | ||
penalty = BICPenalty() | ||
|
||
df2 = pd.DataFrame(np.random.randn(100, 2)) | ||
df3 = pd.DataFrame(np.random.randn(100, 3)) | ||
|
||
penalty.fit(df3, scorer) | ||
penalised_score = PenalisedScore(scorer, penalty) | ||
penalised_score.fit(df3, scorer) | ||
assert penalised_score.is_fitted | ||
|
||
penalty.fit(df2, scorer) | ||
penalised_score = PenalisedScore(scorer, penalty) | ||
|
||
with pytest.raises(ValueError): | ||
penalised_score.fit(df3, scorer) | ||
|
||
|
||
def test_penalised_score_get_param_size(): | ||
scorer = CUSUM() | ||
penalty = BICPenalty() | ||
penalised_score = PenalisedScore(scorer, penalty) | ||
assert penalised_score.get_param_size(1) == scorer.get_param_size(1) | ||
assert penalised_score.get_param_size(5) == scorer.get_param_size(5) |