0
$\begingroup$

I have a dataset with binary output ($Y$) and I have a column (Duration) contains the duration of each task that is stored by "days" and varied from 1day to 350 days.

when I think logically in our situation, I can deduce that the probability of getting a positive output value ($Y = 1$) require to have small duration task.

But I need to justify my opinion with some plots

I have tried the following source code but It doesn't represent correctly my assumption.

#LoadData

min_duration = plot_data['Duration'].min()
max_duration = plot_data['Duration'].max()
xr_ = list(range(min_duration,  max_duration,  5))
y_ = []

for i in range(0,(len(xr_)-1)):
    a_ = np.logical_and(plot_data['Duration'].values >= xr_[i], plot_data['Duration'].values < xr_[i+1])
    b_ = np.logical_and(np.logical_and(plot_data['Duration'].values >= xr_[i], plot_data['Duration'].values < xr_[i+1]), plot_data['output'].values==1)
    y_.append(sum(b_)/sum(a_))

import matplotlib
matplotlib.pyplot.plot(xr_[1:len(xr_)], y_, 'o')

Based on my previous assumption I must get a plot which contains an exponential form like :

enter image description here

But I have got contrary the following plot:

enter image description here

I want to know where I have a mistake and If there is any other method to justify my assumption

$\endgroup$
1
$\begingroup$

The model you are looking for is this:

$Y=A e^{-Bx} + c$, I know the implementation in R, because I don't know of a nonlinear estimation in Python

This code in R might work:

R=data.frame(X=c(1,2,3,4,5,6,7,8,9),Y=c(1,2,3,3,3,3,3,3,3)) # Data in which X, Y are your data
model=nls(formula = Y~A*exp(-B*X)+C,data=R)
summary(model)

There is a limitation to take into account, is explained in this link, is summarized in the impossibility for all possible models to exist, the "most inside" model should be linear.

First steps with Non-Linear Regression in R

Singular Gradient Error in nls with correct starting values

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you juan, I will try to look for the equivalent function in python . $\endgroup$ – Nirmine Apr 27 '19 at 23:38
  • 1
    $\begingroup$ @Nirmine Check out scipy.optimize.curve_fit for Python. $\endgroup$ – Esmailian Apr 28 '19 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.