@@ -221,22 +221,42 @@ def imputeMCA(
221
221
Z_mean = Z .apply (lambda col : moy_p (col .values , row_w ))
222
222
Z = Z .subtract (Z_mean , axis = 1 )
223
223
Zscale = Z .multiply (np .sqrt (M ), axis = 1 )
224
- U , s , Vt = np .linalg .svd (Zscale .values , full_matrices = False )
225
- V = Vt .T
226
- U = U [:, :ncp ]
227
- V = V [:, :ncp ]
228
- s = s [:ncp ]
224
+
225
+ #U, s, Vt = np.linalg.svd(Zscale.values, full_matrices=False)
226
+ #V = Vt.T
227
+ #U = U[:, :ncp]
228
+ #V = V[:, :ncp]
229
+ #s = s[:ncp]
230
+ U_full , s_full , Vt_full = np .linalg .svd (Zscale .values , full_matrices = False )
229
231
if method .lower () == "em" :
230
232
moyeig = 0
231
233
else :
232
- if len (s ) > ncp :
233
- moyeig = np .mean (s [ncp :] ** 2 )
234
- moyeig = min (moyeig * coeff_ridge , s [ncp - 1 ] ** 2 )
234
+ if len (s_full ) > ncp :
235
+ moyeig = np .mean (s_full [ncp :] ** 2 )
236
+ moyeig = min (moyeig * coeff_ridge , s_full [ncp - 1 ] ** 2 )
235
237
else :
236
238
moyeig = 0
237
- eig_shrunk = (s ** 2 - moyeig ) / s
238
- eig_shrunk = np .maximum (eig_shrunk , 0 )
239
- rec = U @ np .diag (eig_shrunk ) @ V .T
239
+ U = U_full [:, :ncp ]
240
+ V = Vt_full .T [:, :ncp ]
241
+ s_retained = s_full [:ncp ]
242
+ s_shrunk = (s_retained ** 2 - moyeig ) / s_retained
243
+ s_shrunk = np .maximum (s_shrunk , 0 )
244
+ rec = U @ np .diag (s_shrunk ) @ V .T
245
+
246
+
247
+ # if method.lower() == "em":
248
+ # moyeig = 0
249
+ # else:
250
+ # if len(s) > ncp:
251
+ # moyeig = np.mean(s[ncp:] ** 2)
252
+ # moyeig = min(moyeig * coeff_ridge, s[ncp - 1] ** 2)
253
+ # else:
254
+ # moyeig = 0
255
+
256
+ #eig_shrunk = (s**2 - moyeig) / s
257
+ #eig_shrunk = np.maximum(eig_shrunk, 0)
258
+ #rec = U @ np.diag(eig_shrunk) @ V.T
259
+
240
260
tab_disj_rec = pd .DataFrame (
241
261
rec , columns = tab_disj_comp .columns , index = tab_disj_comp .index
242
262
)
0 commit comments