Best exponential decay line greater than 95% of data I've got some data that has an exponential decay. And I want to do some curve fitting.
X = [x for x in range(0,900)]
N_0 = 300
m_lambda = .005    
left_shift = 0
up_shift = 0

plt.close()
Y = [ N_0 * np.exp(1)**(-1*m_lambda*(m_x+left_shift)) + up_shift + np.random.normal(0,15) for m_x  in X]

Y_fit = [ N_0 * np.exp(1)**(-1*m_lambda*(m_x+left_shift)) + up_shift for m_x  in X]

plt.plot(X,Y,'o')
plt.plot(X,Y_fit,'-')


But the catch is, I don't want the best fit for all the data.  I want the best fit that keeps the line above 95% of the data.
Something like this 
X = [x for x in range(0,900)]
N_0 = 300
m_lambda = .005    
left_shift = 0
up_shift = 1

plt.close()
Y = [ N_0 * np.exp(1)**(-1*m_lambda*(m_x+left_shift)) + up_shift + np.random.normal(0,15) for m_x  in X]

Y_fit = [ N_0 * np.exp(1)**(-1*1.1*m_lambda*(m_x+left_shift)) + 30*up_shift for m_x  in X]

plt.plot(X,Y,'bo')
yy  = pd.DataFrame(Y)
yy = yy[yy>pd.DataFrame(Y_fit)].dropna()

plt.plot(yy.index,yy,'ro')
plt.plot(X,Y_fit,'-g')


My current plan is to just modify the parameters of the equation, but that is inefficient and not very rigorous.
So I was wondering if there's any known technique for getting the 'best' possible curve that lies under 5% of my data.
 A: As whuber notes, quantile regression is what you want. You can simply exponentiate the model results from a log linear model to get the quantile. Here is an example in python:
import numpy as np
from statsmodels.regression.quantile_regression import QuantReg
import matplotlib.pyplot as plt
%matplotlib inline

x = np.random.gamma(1,1,size = 1000)
xx = np.linspace(0,6,101)
y = 10*np.exp(-x/2) + np.random.normal(0, 0.25, size = x.size)

plt.scatter(x,y, c = 'C0', alpha = 0.5, s = 5)

X = np.c_[np.ones_like(x), x]
XX = np.c_[np.ones_like(xx), xx]
model = QuantReg(np.log(y),X).fit(q = 0.95)

preds = np.exp(model.predict(XX))

plt.plot(xx, preds, color = 'red')

This yeilds the following plot

And as required, approx 95% of model predictions are above the data

np.mean(np.exp(model.predict(X))>y)

>>>0.949

```

A: If you add to the equation a constant value of, say, 25.0 then the existing parameter named "up_shift" will be adjusted by the nonlinear fitting algorithm to account for the added value.  When using the fitted equation, no longer add the fixed value - this will shift the fitted curve by the amount of the fixed constant.
Once you see that this is working, you can adjust the fitted curve up or down the Y axis as you please.
A: This may be just a little late, but like someone else has said, you want quantile regression. You can do this with pystan. Your family will be asymmetric laplace with quantile set to .95, set the mu_link to 'log', this will get you your exponential curve, and that is exactly what you want. 
