Skip to content

Instantly share code, notes, and snippets.

@conormm
Last active April 12, 2021 08:52

Revisions

  1. conormm revised this gist Apr 12, 2021. 1 changed file with 0 additions and 4 deletions.
    4 changes: 0 additions & 4 deletions ExponentialDecayRegressor.py
    Original file line number Diff line number Diff line change
    @@ -2,10 +2,6 @@
    from sklearn.base import BaseEstimator, RegressorMixin
    import statsmodels.api as sm

    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
    """
  2. conormm revised this gist Apr 12, 2021. 1 changed file with 1 addition and 5 deletions.
    6 changes: 1 addition & 5 deletions ExponentialDecayRegressor.py
    Original file line number Diff line number Diff line change
    @@ -23,8 +23,4 @@ def predict(self, X, y=None):

    @staticmethod
    def exp_decay_f(X, a, k, b):
    return a * np.exp(-k*X) + b

    @staticmethod
    def exp_decay_f(X, a, k, b):
    return a * np.exp(-k*X) + b
    return a * np.exp(-k*X) + b
  3. conormm revised this gist Apr 11, 2021. 1 changed file with 12 additions and 2 deletions.
    14 changes: 12 additions & 2 deletions ExponentialDecayRegressor.py
    Original file line number Diff line number Diff line change
    @@ -2,19 +2,29 @@
    from sklearn.base import BaseEstimator, RegressorMixin
    import statsmodels.api as sm

    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, **kwargs):

    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=(1.,1.e-5,1.))
    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

    @staticmethod
    def exp_decay_f(X, a, k, b):
    return a * np.exp(-k*X) + b
  4. conormm revised this gist Apr 10, 2021. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion ExponentialDecayRegressor.py
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,6 @@
    class ExponentialDecayRegressor(BaseEstimator, RegressorMixin):
    """Fits an exponential decay curve
    """

    def __init__(self, **kwargs):
    self.kwargs = kwargs
    self.params = None
  5. conormm revised this gist Apr 10, 2021. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions ExponentialDecayRegressor.py
    Original file line number Diff line number Diff line change
    @@ -11,8 +11,7 @@ def __init__(self, **kwargs):
    self.params = None

    def fit(self, X, y=None):
    self.params, _ = curve_fit(self.exp_decay_f, X, y, (1.,1.e-5,1.))

    self.params, _ = curve_fit(self.exp_decay_f, X, y, p0=(1.,1.e-5,1.))

    def predict(self, X, y=None):
    return self.exp_decay_f(X, *self.params)
  6. conormm created this gist Apr 10, 2021.
    22 changes: 22 additions & 0 deletions ExponentialDecayRegressor.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    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, **kwargs):
    self.kwargs = kwargs
    self.params = None

    def fit(self, X, y=None):
    self.params, _ = curve_fit(self.exp_decay_f, X, y, (1.,1.e-5,1.))


    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