|
2 | 2 |
|
3 | 3 | This example shows a very small yet functional ML backend that trains a |
4 | 4 | classifier on labeled time series CSV files and predicts segments for new |
5 | | -tasks. The logic is intentionally simple so that it can serve as a starting |
| 5 | +tasks. The logic is intentionally simple so that it can serve as a starting |
6 | 6 | point for your own experiments. |
7 | 7 | """ |
8 | 8 |
|
@@ -46,6 +46,7 @@ def _get_model(self, blank: bool = False) -> LogisticRegression: |
46 | 46 | global _model |
47 | 47 | if _model is not None and not blank: |
48 | 48 | return _model |
| 49 | + |
49 | 50 | model_path = os.path.join(self.MODEL_DIR, "model.pkl") |
50 | 51 | if not blank and os.path.exists(model_path): |
51 | 52 | with open(model_path, "rb") as f: |
@@ -158,7 +159,9 @@ def _collect_samples(self, tasks: List[Dict], params: Dict, label2idx: Dict[str, |
158 | 159 | df = self._read_csv(task, task['data'][params['value']]) |
159 | 160 | if df.empty: |
160 | 161 | continue |
| 162 | + |
161 | 163 | annotations = [a for a in task['annotations'] if a.get('result')] |
| 164 | + |
162 | 165 | for ann in annotations: |
163 | 166 | for r in ann['result']: |
164 | 167 | if r['from_name'] != params['from_name']: |
@@ -209,12 +212,14 @@ def fit(self, event, data, **kwargs): |
209 | 212 | ): |
210 | 213 | logger.info("Skip training: event %s is not supported", event) |
211 | 214 | return |
| 215 | + |
212 | 216 | project_id = data['annotation']['project'] |
213 | 217 | tasks = self._get_tasks(project_id) |
214 | 218 | if len(tasks) % self.START_TRAINING_EACH_N_UPDATES != 0 and event != 'START_TRAINING': |
215 | 219 | logger.info( |
216 | 220 | f'Skip training: {len(tasks)} tasks are not multiple of {self.START_TRAINING_EACH_N_UPDATES}') |
217 | 221 | return |
| 222 | + |
218 | 223 | params = self._get_labeling_params() |
219 | 224 | label2idx = {l: i for i, l in enumerate(params['labels'])} |
220 | 225 |
|
|
0 commit comments