| 141 | |
| 142 | # Predict test samples |
| 143 | def predict(self, test_samples, classify=True): |
| 144 | if test_samples.shape[1] > self.samples.shape[1]: |
| 145 | raise ValueError( |
| 146 | "Test samples' feature length does not equal to that of train samples" |
| 147 | ) |
| 148 | |
| 149 | if self._auto_norm: |
| 150 | test_samples = self._norm(test_samples) |
| 151 | |
| 152 | results = [] |
| 153 | for test_sample in test_samples: |
| 154 | result = self._predict(test_sample) |
| 155 | if classify: |
| 156 | results.append(1 if result > 0 else -1) |
| 157 | else: |
| 158 | results.append(result) |
| 159 | return np.array(results) |
| 160 | |
| 161 | # Check if alpha violates the KKT condition |
| 162 | def _check_obey_kkt(self, index): |