-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b19b59
commit da73953
Showing
4 changed files
with
113 additions
and
66 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from abc import abstractmethod | ||
from typing import Iterable | ||
|
||
import numpy as np | ||
|
||
|
||
class Dataset: | ||
@abstractmethod | ||
def __len__(self): | ||
raise NotImplementedError | ||
|
||
@abstractmethod | ||
def __getitem__(self, index): | ||
raise NotImplementedError | ||
|
||
def __iter__(self): | ||
for idx in range(self.__len__()): | ||
yield self.__getitem__(idx) | ||
|
||
def __next__(self): | ||
return self.__getitem__(next(iter(self))) | ||
|
||
|
||
def smooth(iterable: Iterable, factor: float): | ||
""" | ||
Use exponential smoothing to smooth an array | ||
""" | ||
prev = 0 | ||
for val in iterable: | ||
yield prev * factor + (val - prev) * factor | ||
prev = val | ||
|
||
|
||
|
||
def r_squared(actual_values, predicted_values): | ||
""" | ||
calculate R-squared metric. | ||
""" | ||
actual_values = np.array(actual_values) | ||
predicted_values = np.array(predicted_values) | ||
|
||
mean_actual = np.mean(actual_values) | ||
tss = np.sum((actual_values - mean_actual) ** 2) | ||
rss = np.sum((actual_values - predicted_values) ** 2) | ||
|
||
return 1 - (rss / tss) | ||
|
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,31 @@ | ||
from abc import abstractmethod | ||
from typing import Iterable | ||
|
||
import numpy as np | ||
|
||
|
||
class Dataset: | ||
@abstractmethod | ||
def __len__(self): | ||
raise NotImplementedError | ||
|
||
@abstractmethod | ||
def __getitem__(self, index): | ||
raise NotImplementedError | ||
|
||
def __iter__(self): | ||
for idx in range(self.__len__()): | ||
yield self.__getitem__(idx) | ||
|
||
def __next__(self): | ||
return self.__getitem__(next(iter(self))) | ||
|
||
|
||
def smooth(iterable: Iterable, factor: float): | ||
""" | ||
Use exponential smoothing to smooth an array | ||
""" | ||
prev = 0 | ||
for val in iterable: | ||
yield prev * factor + (val - prev) * factor | ||
prev = val |
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