Calculate an error for given examples.
(self, X=None, y=None)
| 132 | return params |
| 133 | |
| 134 | def error(self, X=None, y=None): |
| 135 | """Calculate an error for given examples.""" |
| 136 | training_phase = self.is_training |
| 137 | if training_phase: |
| 138 | # Temporally disable training. |
| 139 | # Some layers work differently while training (e.g. Dropout). |
| 140 | self.is_training = False |
| 141 | if X is None and y is None: |
| 142 | y_pred = self._predict(self.X) |
| 143 | score = self.metric(self.y, y_pred) |
| 144 | else: |
| 145 | y_pred = self._predict(X) |
| 146 | score = self.metric(y, y_pred) |
| 147 | if training_phase: |
| 148 | self.is_training = True |
| 149 | return score |
| 150 | |
| 151 | @property |
| 152 | def is_training(self): |