title: Minimizing a function in scipy with three parameters returns the initial guess
body: <p>A set of points with coordinates <code>x</code> and <code>y</code> look like <a href="https://imgur.com/eHL3kzU" rel="nofollow noreferrer">this</a>. I want to construct a curve in the region below <code>y = 0</code> of the form <code>- a - np.exp(-(x - b)/c)</code>, where parameters <code>a</code>, <code>b</code> and <code>c</code> are found by the condition that 90% of the points below <code>y = 0</code> are enclosed by this line and the function in question.</p>
  <p>I've written the following code to do this, but the <code>minimize</code> function gives the initial guess as a result and I don't know what I'm missing.</p>
  <pre><code>from scipy.optimize import minimize
  import numpy as np
  
  def enclosed_points(params):
      a, b, c = params
      den = (y &lt; 0).sum()                   # Calculate the number of points with y coordinate below y0
      func = - a - np.exp(-(x - b)/c)       # Calculate the value of the function for each x
      num = ((y &lt; 0) &amp; (y &gt; func)).sum()    # Calculate the number of points with y coordinate
                                            # below y0 and above the function
      return np.abs(num/den - 0.9)          # Return the absolute value of the difference between
                                            # the ratio of num and den and the target number (0.9)
  
  initial_guess = [0.1, 0.2, 1]             # Dummy initial guess
  result = minimize(enclosed_points, initial_guess)
  </code></pre>
  <p>Edit. <a href="https://ufile.io/f/9mcv4" rel="nofollow noreferrer">Here</a> I have uploaded a random sample of the whole data in npy format.</p>