Skip to content

Commit f6e55a1

Browse files
author
vm-aifluence-jro
committed
prints removed and reshapping issue resolved
1 parent bd2239a commit f6e55a1

File tree

6 files changed

+38
-27
lines changed

6 files changed

+38
-27
lines changed

examples/benchmark.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,20 @@ imputer_regressor = imputers.ImputerRegressor(groups=["station"], estimator=Line
145145

146146
dict_imputers = {
147147
"mean": imputer_mean,
148-
# "median": imputer_median,
148+
"median": imputer_median,
149149
# "mode": imputer_mode,
150150
"interpolation": imputer_interpol,
151151
# "spline": imputer_spline,
152-
# "shuffle": imputer_shuffle,
152+
"shuffle": imputer_shuffle,
153153
# "residuals": imputer_residuals,
154154
# "OU": imputer_ou,
155-
# "TSOU": imputer_tsou,
156-
# "TSMLE": imputer_tsmle,
155+
"TSOU": imputer_tsou,
156+
"TSMLE": imputer_tsmle,
157157
# "RPCA": imputer_rpca,
158-
# "RPCA_opti": imputer_rpca_opti,
158+
"RPCA_opti": imputer_rpca_opti,
159159
# "locf": imputer_locf,
160160
# "nocb": imputer_nocb,
161-
# "knn": imputer_knn,
161+
"knn": imputer_knn,
162162
"ols": imputer_regressor,
163163
# "mice_ols": imputer_mice,
164164
}
@@ -207,6 +207,21 @@ plt.bar(df_plot.index, df_plot, color=tab10(0))
207207
plt.show()
208208
```
209209

210+
```python
211+
fig = plt.figure(figsize=(16, 6))
212+
fig.add_subplot(1, 2, 1)
213+
df_plot = results.loc["mae"].mean().sort_values(ascending=False)
214+
plt.barh(df_plot.index, df_plot, color=[tab10(0) if i<n_imputers-1 else "red" for i in range(n_imputers)])
215+
plt.xlabel("Erreur MAE")
216+
# plt.show()
217+
218+
fig.add_subplot(1, 2, 2)
219+
df_plot = results.loc["energy"].mean().sort_values(ascending=False)
220+
plt.barh(df_plot.index, df_plot, color=[tab10(0) if i<n_imputers-1 else "red" for i in range(n_imputers)])
221+
plt.xlabel("Erreur énergétique")
222+
plt.show()
223+
```
224+
210225
```python
211226
fig = plt.figure(figsize=(24, 8))
212227
fig.add_subplot(2, 1, 1)
@@ -247,8 +262,9 @@ for col in cols_to_impute:
247262
values_orig = df_station[col]
248263

249264
plt.plot(values_orig, ".", color='black', label="original")
250-
251265
for ind, (name, model) in enumerate(list(dict_imputers.items())):
266+
if name not in ["mean", "TSMLE"]:
267+
continue
252268
values_imp = dfs_imputed_station[name][col].copy()
253269
values_imp[values_orig.notna()] = np.nan
254270
plt.plot(values_imp, ".", color=tab10(ind), label=name, alpha=1)

qolmat/benchmark/cross_validation.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,6 @@ def fit_transform(
168168
"""
169169

170170
n0 = max(5, self.n_calls // 5)
171-
print("---")
172-
print(self.n_calls)
173-
print(n0)
174171

175172
# res = skopt.gp_minimize(
176173
# self.objective(X=df),
@@ -191,8 +188,8 @@ def fit_transform(
191188
)
192189

193190
hyperparams_flat = {space.name: val for space, val in zip(self.list_spaces, res["x"])}
194-
print(f"Optimal hyperparameters : {hyperparams_flat}")
195-
print(f"Results: {res}")
191+
# print(f"Optimal hyperparameters : {hyperparams_flat}")
192+
# print(f"Results: {res}")
196193

197194
self.imputer.hyperparams_optim = self.deflat_hyperparams(hyperparams_flat)
198195
df_imputed = self.imputer.fit_transform(df)

qolmat/imputations/rpca/rpca.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,10 @@ def _prepare_data(self, X: NDArray) -> NDArray:
5656
return X.copy()
5757
else:
5858
raise ValueError("`n_rows` should not be specified when imputing 2D data.")
59+
60+
def get_shape_original(self, X: NDArray, shape: Tuple[int]) -> NDArray:
61+
if len(shape) == 1 or shape[0] == 1:
62+
n_values = sum(shape)
63+
return X.reshape(1, -1)[:, :n_values]
64+
else:
65+
return X

qolmat/imputations/rpca/rpca_noisy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def decompose_rpca_signal(
366366
elif self.norm == "L2":
367367
M, A, U, V, errors = self.decompose_rpca_L2(D_proj, Omega, lam, tau, rank)
368368

369-
M = M.reshape(X.shape)
370-
A = A.reshape(X.shape)
369+
M_final = self.get_shape_original(M, X.shape)
370+
A_final = self.get_shape_original(A, X.shape)
371371

372-
return M, A
372+
return M_final, A_final

qolmat/imputations/rpca/rpca_pcp.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,6 @@ def decompose_rpca_signal(
100100
D = self._prepare_data(X)
101101
M, A = self.decompose_rpca(D)
102102

103-
# U, _, V = np.linalg.svd(M, full_matrices=False, compute_uv=True)
104-
105-
# if X.shape[0] == 1:
106-
# M = M.reshape(1, -1)[:, : X.size]
107-
# M = M.reshape(X)
108-
# A = A.reshape(1, -1)[:, : X.size]
109-
M = M.reshape(X.shape)
110-
A = A.reshape(X.shape)
111-
return M, A
103+
M_final = self.get_shape_original(M, X.shape)
104+
A_final = self.get_shape_original(A, X.shape)
105+
return M_final, A_final

tests/utils/test_data.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ def test_preprocess_data():
7676
],
7777
columns=columns_raw,
7878
)
79-
print(df_raw)
8079
result = data.preprocess_data(df_raw)
81-
print(result)
82-
print(df)
8380
# assert result.equals(df)
8481
pd.testing.assert_frame_equal(result, df, atol=1e-3)
8582

0 commit comments

Comments
 (0)