Browse Source
* Create abstract model class * Move detectors/*_detector -> models/*_model * Update Model class * Change detectors to models and move fields to self.state * Use models instead of detectors in PatternDetector * Update inits in detectors/ and models/ * Add types to resolve_model_by_pattern * Add types to abstract Model classpull/1/head
7 changed files with 80 additions and 67 deletions
@ -1,5 +1,3 @@ |
|||||||
from detectors.general_detector import GeneralDetector |
|
||||||
from detectors.pattern_detector import PatternDetector |
from detectors.pattern_detector import PatternDetector |
||||||
from detectors.peaks_detector import PeaksDetector |
# TODO: do something with general detector |
||||||
from detectors.step_detector import StepDetector |
from detectors.general_detector import GeneralDetector |
||||||
from detectors.jump_detector import JumpDetector |
|
||||||
|
@ -0,0 +1,4 @@ |
|||||||
|
from models.model import Model |
||||||
|
from models.step_model import StepModel |
||||||
|
from models.peaks_model import PeaksModel |
||||||
|
from models.jump_model import JumpModel |
@ -0,0 +1,30 @@ |
|||||||
|
from abc import ABC, abstractmethod |
||||||
|
from pandas import DataFrame |
||||||
|
import pickle |
||||||
|
|
||||||
|
class Model(ABC): |
||||||
|
|
||||||
|
def __init__(self): |
||||||
|
""" |
||||||
|
Variables which are obtained as a result of fit() method |
||||||
|
should be stored in self.state dict |
||||||
|
in order to be saved in model file |
||||||
|
""" |
||||||
|
self.state = {} |
||||||
|
self.segments = [] |
||||||
|
|
||||||
|
@abstractmethod |
||||||
|
async def fit(self, dataframe: DataFrame, segments: list): |
||||||
|
pass |
||||||
|
|
||||||
|
@abstractmethod |
||||||
|
async def predict(self, dataframe: DataFrame) -> list: |
||||||
|
pass |
||||||
|
|
||||||
|
def save(self, model_filename: str): |
||||||
|
with open(model_filename, 'wb') as file: |
||||||
|
pickle.dump(self.state, file) |
||||||
|
|
||||||
|
def load(self, model_filename: str): |
||||||
|
with open(model_filename, 'rb') as f: |
||||||
|
self.state = pickle.load(f) |
Loading…
Reference in new issue