-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
15 changed files
with
206 additions
and
144 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,14 @@ | ||
import pandas as pd | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def analysis_df(): | ||
return pd.DataFrame( | ||
{ | ||
"target": [0, 1, 0, 1], | ||
"treatment": ["A", "B", "B", "A"], | ||
"cluster": ["Cluster 1", "Cluster 1", "Cluster 1", "Cluster 1"], | ||
"date": ["2022-01-01", "2022-01-01", "2022-01-01", "2022-01-01"], | ||
} | ||
) |
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
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 |
---|---|---|
@@ -1,18 +1,17 @@ | ||
import pandas as pd | ||
|
||
from cluster_experiments.experiment_analysis import OLSAnalysis | ||
from tests.examples import analysis_df | ||
|
||
|
||
def test_binary_treatment(): | ||
def test_binary_treatment(analysis_df): | ||
analyser = OLSAnalysis() | ||
assert ( | ||
analyser._create_binary_treatment(analysis_df)["treatment"] | ||
== pd.Series([0, 1, 1, 0]) | ||
).all() | ||
|
||
|
||
def test_get_pvalue(): | ||
def test_get_pvalue(analysis_df): | ||
analysis_df_full = pd.concat([analysis_df for _ in range(100)]) | ||
analyser = OLSAnalysis() | ||
assert analyser.get_pvalue(analysis_df_full) >= 0 |
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,12 @@ | ||
import pandas as pd | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def binary_df(): | ||
return pd.DataFrame( | ||
{ | ||
"target": [0, 1, 0, 1], | ||
"treatment": ["A", "B", "B", "A"], | ||
} | ||
) |
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
This file was deleted.
Oops, something went wrong.
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,57 @@ | ||
import pandas as pd | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def binary_df(): | ||
return pd.DataFrame( | ||
{ | ||
"target": [0, 1, 0, 1], | ||
"treatment": ["A", "B", "B", "A"], | ||
} | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def continuous_df(): | ||
return pd.DataFrame( | ||
{ | ||
"target": [0.5, 0.5, 0.5, 0.5], | ||
"treatment": ["A", "B", "B", "A"], | ||
} | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def generate_clustered_data() -> pd.DataFrame: | ||
analysis_df = pd.DataFrame( | ||
{ | ||
"country_code": ["ES"] * 4 + ["IT"] * 4 + ["PL"] * 4 + ["RO"] * 4, | ||
"city_code": ["BCN", "BCN", "MAD", "BCN"] | ||
+ ["NAP"] * 4 | ||
+ ["WAW"] * 4 | ||
+ ["BUC"] * 4, | ||
"user_id": [1, 1, 2, 1, 3, 4, 5, 6, 7, 8, 8, 8, 9, 9, 9, 10], | ||
"date": ["2022-01-01", "2022-01-02", "2022-01-03", "2022-01-04"] * 4, | ||
"treatment": [ | ||
"A", | ||
"A", | ||
"B", | ||
"A", | ||
"B", | ||
"B", | ||
"A", | ||
"B", | ||
"B", | ||
"A", | ||
"A", | ||
"A", | ||
"B", | ||
"B", | ||
"B", | ||
"A", | ||
], # Randomization is done at user level, so same user will always have same treatment | ||
"target": [0.01] * 15 + [0.1], | ||
} | ||
) | ||
return analysis_df |
Oops, something went wrong.