| Total Complexity | 9 |
| Total Lines | 26 |
| Duplicated Lines | 76.92 % |
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | import os |
||
|
|
|||
| 2 | import pickle |
||
| 3 | from .meta_clf import MetaClf |
||
| 4 | |||
| 5 | |||
| 6 | View Code Duplication | class MetaSkLearnClf(MetaClf): |
|
| 7 | def __init__(self, classifier_instance, **kwargs): |
||
| 8 | super().__init__(classifier_instance=classifier_instance, **kwargs) |
||
| 9 | |||
| 10 | def load_model(self, load_path: str): |
||
| 11 | loading_prep = lambda string: f'model_dir/{load_path}/{string}' |
||
| 12 | self.emb.load(loading_prep('emb.pkl')) |
||
| 13 | with open(loading_prep('model.pkl'), 'rb') as f: |
||
| 14 | self.scaler = pickle.load(f) |
||
| 15 | with open(loading_prep('scaler.pkl'), 'rb') as f: |
||
| 16 | self.scaler = pickle.load(f) |
||
| 17 | |||
| 18 | def save_model(self, save_path: str): |
||
| 19 | os.makedirs(f'model_dir/{save_path}', exist_ok=True) |
||
| 20 | saving_prep = lambda string: f'model_dir/{save_path}/{string}' |
||
| 21 | self.emb.save(saving_prep('emb.pkl')) |
||
| 22 | with open(saving_prep('scaler.pkl'), 'wb') as f: |
||
| 23 | pickle.dump(self.scaler, f, pickle.HIGHEST_PROTOCOL) |
||
| 24 | with open(saving_prep('model.pkl'), 'wb') as f: |
||
| 25 | pickle.dump(self.clf, f, pickle.HIGHEST_PROTOCOL) |
||
| 26 |