Passed
Push — main ( 081b85...deff66 )
by Mohammad
02:40 queued 12s
created

MetaSkLearnClf.load_model()   A

Complexity

Conditions 4

Size

Total Lines 7
Code Lines 7

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 7
dl 7
loc 7
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
cc 4
nop 2
crap 4
1 1
import os
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2 1
import pickle
3 1
from .meta_clf import MetaClf
4
5
6 1 View Code Duplication
class MetaSkLearnClf(MetaClf):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
7 1
    def __init__(self, classifier_instance, **kwargs):
8 1
        super().__init__(classifier_instance=classifier_instance, **kwargs)
9 1
        if kwargs['load_path'] is not None: self.load_model(kwargs['load_path'])
0 ignored issues
show
Coding Style introduced by
More than one statement on a single line
Loading history...
10
11 1
    def load_model(self, load_path: str):
12 1
        loading_prep = lambda string: f'model_dir/{load_path}/{string}'
13 1
        self.emb.load(loading_prep('emb.pkl'))
14 1
        with open(loading_prep('model.pkl'), 'rb') as f:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
15 1
            self.clf = pickle.load(f)
16 1
        with open(loading_prep('scaler.pkl'), 'rb') as f:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
17 1
            self.scaler = pickle.load(f)
18
19 1
    def save_model(self, save_path: str):
20
        os.makedirs(f'model_dir/{save_path}', exist_ok=True)
21
        saving_prep = lambda string: f'model_dir/{save_path}/{string}'
22
        self.emb.save(saving_prep('emb.pkl'))
23
        with open(saving_prep('scaler.pkl'), 'wb') as f:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
24
            pickle.dump(self.scaler, f, pickle.HIGHEST_PROTOCOL)
25
        with open(saving_prep('model.pkl'), 'wb') as f:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
26
            pickle.dump(self.clf, f, pickle.HIGHEST_PROTOCOL)
27