|
51 | 51 |
|
52 | 52 | # Compute the training set matrices for each fold. |
53 | 53 | print("Training set matrices using training_XTX_XTY:") |
54 | | - for fold in cvm.folds_dict.keys(): |
| 54 | + for fold in cvm.folds_dict: |
55 | 55 | # Notice that the samples associated with fold are considered part of the |
56 | 56 | # validation set. The training set is then all samples not associated with this |
57 | 57 | # fold. |
58 | | - XTX, XTY = cvm.training_XTX_XTY(fold) |
| 58 | + result = cvm.training_XTX_XTY(fold) |
| 59 | + (XTWX, XTWY), (X_mean, X_std, Y_mean, Y_std) = result |
59 | 60 | print(f"Fold {fold}:") |
60 | | - print(f"Training XTWX:\n{XTX}") |
61 | | - print(f"Training XTWY:\n{XTY}") |
| 61 | + print(f"Training XTWX:\n{XTWX}") |
| 62 | + print(f"Training XTWY:\n{XTWY}") |
| 63 | + print(f"Training weighted X mean:\n{X_mean}") |
| 64 | + print(f"Training weighted X std:\n{X_std}") |
| 65 | + print(f"Training weighted Y mean:\n{Y_mean}") |
| 66 | + print(f"Training weighted Y std:\n{Y_std}") |
62 | 67 | print() |
63 | 68 |
|
64 | 69 | # We can also get only XTWX or only XTWY. However, if both XTWX and XTWY are needed, |
65 | 70 | # it is more efficient to call training_XTX_XTY. |
66 | 71 | print("Training set matrices using training_XTX and training_XTY:") |
67 | | - for fold in cvm.folds_dict.keys(): |
68 | | - XTX = cvm.training_XTX(fold) |
| 72 | + for fold in cvm.folds_dict: |
| 73 | + result = cvm.training_XTX(fold) |
| 74 | + XTWX, (X_mean, X_std, Y_mean, Y_std) = result |
69 | 75 | print(f"Fold {fold}:") |
70 | | - print(f"Training XTWX:\n{XTX}") |
| 76 | + print(f"Training XTWX:\n{XTWX}") |
| 77 | + print(f"Training weighted X mean:\n{X_mean}") |
| 78 | + print(f"Training weighted X std:\n{X_std}") |
| 79 | + |
| 80 | + # These two are None as they are not computed when only XTX is requested. |
| 81 | + print(f"Training weighted Y mean:\n{Y_mean}") |
| 82 | + print(f"Training weighted Y std:\n{Y_std}") |
71 | 83 | print() |
72 | | - for fold in cvm.folds_dict.keys(): |
73 | | - XTY = cvm.training_XTY(fold) |
| 84 | + for fold in cvm.folds_dict: |
| 85 | + result = cvm.training_XTY(fold) |
| 86 | + XTWY, (X_mean, X_std, Y_mean, Y_std) = result |
74 | 87 | print(f"Fold {fold}:") |
75 | | - print(f"Training XTWY:\n{XTY}") |
| 88 | + print(f"Training XTWY:\n{XTWY}") |
| 89 | + print(f"Training weighted X mean:\n{X_mean}") |
| 90 | + print(f"Training weighted X std:\n{X_std}") |
| 91 | + print(f"Training weighted Y mean:\n{Y_mean}") |
| 92 | + print(f"Training weighted Y std:\n{Y_std}") |
76 | 93 | print() |
77 | 94 |
|
78 | 95 | # We can also fit on new X and Y. This will recompute the global statistics and |
|
84 | 101 |
|
85 | 102 | print("Fitting on new data:") |
86 | 103 | cvm.fit(X, Y) |
87 | | - for fold in cvm.folds_dict.keys(): |
88 | | - XTX, XTY = cvm.training_XTX_XTY(fold) |
| 104 | + for fold in cvm.folds_dict: |
| 105 | + result = cvm.training_XTX_XTY(fold) |
| 106 | + (XTWX, XTWY), (X_mean, X_std, Y_mean, Y_std) = result |
| 107 | + print(f"Fold {fold}:") |
| 108 | + print(f"Training XTWX:\n{XTWX}") |
| 109 | + print(f"Training XTWY:\n{XTWY}") |
| 110 | + print(f"Training weighted X mean:\n{X_mean}") |
| 111 | + print(f"Training weighted X std:\n{X_std}") |
| 112 | + print(f"Training weighted Y mean:\n{Y_mean}") |
| 113 | + print(f"Training weighted Y std:\n{Y_std}") |
| 114 | + print() |
| 115 | + |
| 116 | + # We can also get the training set statistics without computing the training set |
| 117 | + # matrices. This is useful if we only need the statistics for further processing. |
| 118 | + print("Training set statistics:") |
| 119 | + for fold in cvm.folds_dict: |
| 120 | + result = cvm.training_statistics(fold) |
| 121 | + X_mean, X_std, Y_mean, Y_std = result |
89 | 122 | print(f"Fold {fold}:") |
90 | | - print(f"Training XTWX:\n{XTX}") |
91 | | - print(f"Training XTWY:\n{XTY}") |
| 123 | + print(f"Training weighted X mean:\n{X_mean}") |
| 124 | + print(f"Training weighted X std:\n{X_std}") |
| 125 | + print(f"Training weighted Y mean:\n{Y_mean}") |
| 126 | + print(f"Training weighted Y std:\n{Y_std}") |
92 | 127 | print() |
0 commit comments