Skip to content

Commit 4fa0378

Browse files
committed
✅ Changes following the PR and adapt the root of the 'make coverage' command
1 parent 23aa9b4 commit 4fa0378

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
coverage:
2-
pytest --cov-branch --cov=qolmat --cov-report=xml
2+
pytest --cov-branch --cov=qolmat --cov-report=xml tests
33

44
doctest:
55
pytest --doctest-modules --pyargs qolmat

examples/tutorials/plot_tuto_mcar_test.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
Tutorial for testing the MCAR case
44
============================================
55
6-
In this tutorial, we show how to use the mcar test classe and it methods
6+
In this tutorial, we show how to use the mcar test class and its methods.
77
8-
Keep in my mind that, at this moment, the mcar tests are only handle tabular data.
8+
Keep in my mind that, at this moment, the mcar tests only handle tabular data.
99
"""
1010
# %%
1111
# First import some libraries
@@ -33,6 +33,13 @@
3333
# missing patterns and won't be efficient to detect the heterogeneity of covariance between missing
3434
# patterns.
3535
#
36+
# The null hypothesis, H0, is : "The data are MCAR". Against,
37+
# The alternative hypothesis : " The data are not MCAR, the means of the observed variables can
38+
# vary across the patterns"
39+
#
40+
# We choose to use the classic threshold, equal to 5%. If the test pval is below this threshold,
41+
# we reject the null hypothesis.
42+
#
3643
# This notebook shows how the Little's test performs and its limitations.
3744

3845
np.random.seed(11)
@@ -43,7 +50,7 @@
4350
# Case 1 : Normal iid feature with MCAR holes
4451
# ===========================================
4552

46-
matrix = np.random.multivariate_normal(mean=[0, 0], cov=[[1, 0], [0, 1]], size=100)
53+
matrix = np.random.multivariate_normal(mean=[0, 0], cov=[[1, 0], [0, 1]], size=200)
4754
matrix.ravel()[np.random.choice(matrix.size, size=20, replace=False)] = np.nan
4855
matrix_masked = matrix[np.argwhere(np.isnan(matrix))]
4956
df_1 = pd.DataFrame(matrix)
@@ -53,7 +60,7 @@
5360

5461
plt.legend(
5562
(plt_1, plt_2),
56-
("observed_values", "masked_vlues"),
63+
("observed_values", "masked_values"),
5764
scatterpoints=1,
5865
loc="lower left",
5966
ncol=1,
@@ -78,9 +85,9 @@
7885
# ==========================================
7986
np.random.seed(11)
8087

81-
matrix = np.random.multivariate_normal(mean=[0, 0], cov=[[1, 0], [0, 1]], size=100)
88+
matrix = np.random.multivariate_normal(mean=[0, 0], cov=[[1, 0], [0, 1]], size=200)
8289
threshold = random.uniform(0, 1)
83-
matrix[np.argwhere(matrix[:, 0] > 1.96), 1] = np.nan
90+
matrix[np.argwhere(matrix[:, 0] >= 1.96), 1] = np.nan
8491
matrix_masked = matrix[np.argwhere(np.isnan(matrix))]
8592
df_2 = pd.DataFrame(matrix)
8693

@@ -118,8 +125,8 @@
118125

119126
np.random.seed(11)
120127

121-
matrix = np.random.multivariate_normal(mean=[0, 0], cov=[[1, 0], [0, 1]], size=100)
122-
matrix[np.argwhere(abs(matrix[:, 0]) >= 1.95), 1] = np.nan
128+
matrix = np.random.multivariate_normal(mean=[0, 0], cov=[[1, 0], [0, 1]], size=200)
129+
matrix[np.argwhere(abs(matrix[:, 0]) >= 1.96), 1] = np.nan
123130
matrix_masked = matrix[np.argwhere(np.isnan(matrix))]
124131
df_3 = pd.DataFrame(matrix)
125132

tests/audit/test_holes_characterization.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,32 @@
99
@pytest.fixture
1010
def mcar_df() -> pd.DataFrame:
1111
rng = np.random.default_rng(42)
12-
matrix = rng.multivariate_normal(mean=[0, 0], cov=[[1, 0], [0, 1]], size=100)
12+
matrix = rng.multivariate_normal(mean=[0, 0], cov=[[1, 0], [0, 1]], size=200)
1313
matrix.ravel()[rng.choice(matrix.size, size=20, replace=False)] = np.nan
1414
return pd.DataFrame(data=matrix)
1515

1616

1717
@pytest.fixture
1818
def mar_hm_df() -> pd.DataFrame:
1919
rng = np.random.default_rng(42)
20-
matrix = rng.multivariate_normal(mean=[0, 0], cov=[[1, 0], [0, 1]], size=100)
21-
matrix[np.argwhere(matrix[:, 0] > 1.96), 1] = np.nan
20+
matrix = rng.multivariate_normal(mean=[0, 0], cov=[[1, 0], [0, 1]], size=200)
21+
matrix[np.argwhere(matrix[:, 0] >= 1.96), 1] = np.nan
2222
return pd.DataFrame(data=matrix)
2323

2424

2525
@pytest.fixture
2626
def mcar_hc_df() -> pd.DataFrame:
2727
rng = np.random.default_rng(42)
28-
matrix = rng.multivariate_normal(mean=[0, 0], cov=[[1, 0], [0, 1]], size=100)
29-
matrix[np.argwhere(abs(matrix[:, 0]) >= 1.95), 1] = np.nan
28+
matrix = rng.multivariate_normal(mean=[0, 0], cov=[[1, 0], [0, 1]], size=200)
29+
matrix[np.argwhere(abs(matrix[:, 0]) >= 1.96), 1] = np.nan
3030
return pd.DataFrame(data=matrix)
3131

3232

33+
def test_mcar__init__():
34+
with pytest.raises(ValueError):
35+
_ = MCARTest(method="hello")
36+
37+
3338
@pytest.mark.parametrize(
3439
"df_input, expected", [("mcar_df", True), ("mar_hm_df", False), ("mcar_hc_df", True)]
3540
)

0 commit comments

Comments
 (0)