Last active
April 12, 2021 08:52
-
-
Save conormm/aad9a9d250bc7694a46addb39fcb45ca to your computer and use it in GitHub Desktop.
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
from scipy.optimize import curve_fit | |
from sklearn.base import BaseEstimator, RegressorMixin | |
import statsmodels.api as sm | |
class ExponentialDecayRegressor(BaseEstimator, RegressorMixin): | |
"""Fits an exponential decay curve | |
""" | |
def __init__(self, starting_values=[1.,1.e-5,1.], **kwargs,): | |
self.starting_values = starting_values | |
self.kwargs = kwargs | |
self.params = None | |
def fit(self, X, y=None): | |
self.params, _ = curve_fit(self.exp_decay_f, X, y, p0=self.starting_values) | |
def predict(self, X, y=None): | |
return self.exp_decay_f(X, *self.params) | |
@staticmethod | |
def exp_decay_f(X, a, k, b): | |
return a * np.exp(-k*X) + b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment