-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #345 from D-X-Y/main
Fix errors when SignalRecord is not called before SigAna/PortAna
- Loading branch information
Showing
4 changed files
with
100 additions
and
11 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
import re | ||
import pandas as pd | ||
from sklearn.metrics import mean_squared_error | ||
from pprint import pprint | ||
import numpy as np | ||
|
||
from ...workflow.record_temp import SignalRecord | ||
from ...log import get_module_logger | ||
|
||
logger = get_module_logger("workflow", "INFO") | ||
|
||
|
||
class SignalMseRecord(SignalRecord): | ||
""" | ||
This is the Signal MSE Record class that computes the mean squared error (MSE). | ||
This class inherits the ``SignalMseRecord`` class. | ||
""" | ||
|
||
artifact_path = "sig_analysis" | ||
|
||
def __init__(self, recorder, **kwargs): | ||
super().__init__(recorder=recorder, **kwargs) | ||
|
||
def generate(self, **kwargs): | ||
try: | ||
self.check(parent=True) | ||
except FileExistsError: | ||
super().generate() | ||
|
||
pred = self.load("pred.pkl") | ||
label = self.load("label.pkl") | ||
masks = ~np.isnan(label.values) | ||
mse = mean_squared_error(pred.values[masks], label[masks]) | ||
metrics = {"MSE": mse, "RMSE": np.sqrt(mse)} | ||
objects = {"mse.pkl": mse, "rmse.pkl": np.sqrt(mse)} | ||
self.recorder.log_metrics(**metrics) | ||
self.recorder.save_objects(**objects, artifact_path=self.get_path()) | ||
pprint(metrics) | ||
|
||
def list(self): | ||
paths = [self.get_path("mse.pkl"), self.get_path("rmse.pkl")] | ||
return paths |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters