title: RuntimeWarning: overflow encountered in exp when using curve_fit
body: <p>I’m attempting to fit a curve to time series data, X axis being the number of days elapsed and Y is the corresponding value. There are 2411 days total in the dataset, but when I try and curve fit to the entire dataset, I get the errors <code>RuntimeWarning: overflow encountered in exp</code>, <code>RuntimeWarning: overflow encountered in square</code>, and <code>OptimizeWarning: Covariance of the parameters could not be estimated</code>.</p>
  <p>After reading a few of the solutions here, I came to the conclusion that the values returned from <code>np.exp()</code> must have been too large, so I used <code>sklearn.preprocessing.MinMaxScaler()</code>, but there was no change.</p>
  <p>Through some trial and error I discovered that if I pass only the first 355 values the cell runs without error, but on the 356th value the errors start, with the exp error first showing on the 711th value. Here is the relevant code including the first 711 elements:</p>
  <pre><code>def func0(x,a,b,c):
      return a * np.exp(b*x) + c
  
  yData = np.array([0.00765047, 0.00791042, 0.00870343, 0.00819011, 0.00806836,
         0.00780183, 0.00768995, 0.0076044 , 0.00808153, 0.00914107,
         0.00996371, 0.00852246, 0.00690681, 0.00541291, 0.00522535,
         0.00517599, 0.00474494, 0.00772615, 0.00334646, 0.00285288,
         0.00366564, 0.0041329 , 0.00419213, 0.00492262, 0.00508715,
         0.00726877, 0.00800584, 0.00830528, 0.0093056 , 0.00969059,
         0.00923321, 0.00844019, 0.00881531, 0.00840071, 0.00640007,
         0.00516941, 0.0055215 , 0.00535368, 0.00405393, 0.00278707,
         0.00363603, 0.0038894 , 0.00352086, 0.00266861, 0.00194799,
         0.00265874, 0.0017012 , 0.00233627, 0.00189534, 0.00135241,
         0.00122737, 0.        , 0.00027969, 0.00116814, 0.00053636,
         0.00143138, 0.0033333 , 0.00329381, 0.00275746, 0.00449156,
         0.00607102, 0.00630464, 0.00630464, 0.00722928, 0.00800255,
         0.00717005, 0.00787751, 0.0078117 , 0.00759124, 0.00641981,
         0.0070154 , 0.00686074, 0.00626516, 0.00571564, 0.00587358,
         0.0075353 , 0.00819998, 0.00804533, 0.00701869, 0.01173401,
         0.01122069, 0.01146418, 0.01323449, 0.01233288, 0.01283304,
         0.01189195, 0.01205319, 0.01310616, 0.01413938, 0.01428416,
         0.01484026, 0.01368529, 0.01037831, 0.01113513, 0.01188537,
         0.01244805, 0.01239869, 0.0115991 , 0.01062839, 0.01029605,
         0.01119765, 0.01091138, 0.01175375, 0.01034212, 0.01075343,
         0.00899958, 0.00813417, 0.00874621, 0.00891074, 0.00944709,
         0.00841058, 0.00833161, 0.00953923, 0.0082296 , 0.00746291,
         0.00835793, 0.00880215, 0.01094428, 0.01008875, 0.01092125,
         0.01039147, 0.01325423, 0.01361619, 0.01421835, 0.01432036,
         0.01596562, 0.01718311, 0.01751217, 0.01835125, 0.01885799,
         0.01697252, 0.01653817, 0.01728512, 0.01625848, 0.01707782,
         0.01663689, 0.0187856 , 0.01795968, 0.0171897 , 0.01827886,
         0.01728183, 0.01750888, 0.02025317, 0.02070727, 0.02025317,
         0.01985831, 0.01669283, 0.01612028, 0.01332991, 0.01373136,
         0.01076988, 0.01451779, 0.01091138, 0.01230327, 0.01359973,
         0.01381362, 0.01207951, 0.01150367, 0.00709108, 0.00590978,
         0.0054524 , 0.01072053, 0.01077976, 0.01022037, 0.01260271,
         0.01499163, 0.01643617, 0.01785438, 0.01696923, 0.01613344,
         0.01816698, 0.01939106, 0.01852236, 0.01659082, 0.01829202,
         0.01926931, 0.02026963, 0.02165494, 0.02577467, 0.02656111,
         0.0237839 , 0.02332981, 0.0204868 , 0.02061184, 0.02266513,
         0.02080927, 0.02261906, 0.02022685, 0.01818343, 0.01678496,
         0.01695607, 0.01925943, 0.01992083, 0.02098367, 0.02314883,
         0.02451769, 0.02495533, 0.02473816, 0.02821295, 0.0267717 ,
         0.02728173, 0.02321793, 0.02390236, 0.02428735, 0.02521857,
         0.02177669, 0.01231643, 0.01507389, 0.0185421 , 0.01728841,
         0.01682445, 0.01798271, 0.01886128, 0.0182657 , 0.0184368 ,
         0.01876257, 0.01653488, 0.01639339, 0.01856513, 0.01907187,
         0.01870992, 0.01678825, 0.01433023, 0.01190182, 0.0093056 ,
         0.01032237, 0.00922005, 0.00705159, 0.01091796, 0.00902262,
         0.01030592, 0.01189853, 0.01153658, 0.01160568, 0.0102072 ,
         0.01130295, 0.00971034, 0.01054942, 0.00939444, 0.00642968,
         0.00633097, 0.00667647, 0.00667647, 0.0060414 , 0.00709108,
         0.00440272, 0.00594269, 0.00536684, 0.0050345 , 0.00425136,
         0.00424148, 0.00399141, 0.00594269, 0.00544253, 0.00547543,
         0.00712069, 0.00578803, 0.00604469, 0.00589991, 0.00492262,
         0.00574196, 0.00680809, 0.00936812, 0.01101667, 0.00985841,
         0.0082658 , 0.00856523, 0.00882847, 0.01064484, 0.0113194 ,
         0.01025985, 0.01101338, 0.00608418, 0.00682784, 0.00878899,
         0.00729509, 0.0076406 , 0.00806507, 0.00790055, 0.00808482,
         0.01007558, 0.00998016, 0.00773273, 0.00623883, 0.0070845 ,
         0.00700552, 0.00645272, 0.00589662, 0.00597559, 0.00577816,
         0.00751227, 0.00615986, 0.00627503, 0.00603153, 0.00634742,
         0.00662053, 0.00750239, 0.00877583, 0.00768337, 0.00737735,
         0.00777222, 0.00700552, 0.00771957, 0.00792358, 0.00807824,
         0.01031908, 0.01012165, 0.01034212, 0.01121081, 0.01378729,
         0.01463296, 0.01322461, 0.01435985, 0.01366884, 0.01220126,
         0.01273104, 0.01086531, 0.01099693, 0.01016772, 0.00855865,
         0.00888441, 0.00977944, 0.00904565, 0.00807165, 0.00902262,
         0.00990448, 0.00991435, 0.00954581, 0.00897326, 0.00966098,
         0.0110068 , 0.01152341, 0.02167797, 0.02333968, 0.02272765,
         0.02279675, 0.02253351, 0.02073688, 0.02112187, 0.02070727,
         0.02040454, 0.02162532, 0.02195108, 0.02038808, 0.0208685 ,
         0.02075991, 0.01888432, 0.01740029, 0.01880205, 0.01788729,
         0.01852894, 0.01785767, 0.0170844 , 0.01769644, 0.01588007,
         0.01709098, 0.01554772, 0.01763721, 0.0171897 , 0.0186474 ,
         0.0190291 , 0.0189238 , 0.01827228, 0.01824595, 0.01768985,
         0.01759772, 0.01888102, 0.02029924, 0.02075004, 0.0204177 ,
         0.01961152, 0.02013471, 0.01944699, 0.02126994, 0.02127324,
         0.01985502, 0.02217155, 0.02249073, 0.02255983, 0.02174707,
         0.02108568, 0.02108568, 0.01925943, 0.01888761, 0.01789716,
         0.01889419, 0.01811104, 0.01841377, 0.01859146, 0.02145421,
         0.02215181, 0.02140157, 0.02042428, 0.01845326, 0.01942725,
         0.02512315, 0.02471841, 0.02380036, 0.0234022 , 0.02298102,
         0.02434987, 0.0240274 , 0.02487307, 0.02415573, 0.02405044,
         0.02361938, 0.02351737, 0.02376416, 0.02515605, 0.02651504,
         0.02639   , 0.02612018, 0.02582403, 0.02702507, 0.02639987,
         0.02789377, 0.02729489, 0.02801552, 0.02834786, 0.02805171,
         0.02872627, 0.02859794, 0.02805171, 0.02974962, 0.03230307,
         0.03162851, 0.03116126, 0.0311481 , 0.03266503, 0.03300395,
         0.03192795, 0.03217474, 0.03313886, 0.03285259, 0.03175355,
         0.03087498, 0.030105  , 0.02918694, 0.03146399, 0.03071704,
         0.02995693, 0.02949296, 0.03124352, 0.03274071, 0.03209577,
         0.03227675, 0.02961142, 0.02764698, 0.02739361, 0.02678157,
         0.02738045, 0.02730147, 0.02846961, 0.02760091, 0.02600501,
         0.0239583 , 0.0241327 , 0.02221762, 0.02038479, 0.02542588,
         0.02366545, 0.02341866, 0.02351079, 0.02413928, 0.02520212,
         0.02339233, 0.0218425 , 0.02150028, 0.02155293, 0.02159571,
         0.02039467, 0.01962139, 0.0211449 , 0.02261906, 0.0239583 ,
         0.02535678, 0.02596552, 0.02719618, 0.02712379, 0.02834457,
         0.02971343, 0.02997009, 0.02940412, 0.03011487, 0.03059858,
         0.03040444, 0.03037153, 0.02856175, 0.02952258, 0.02987466,
         0.02970685, 0.029029  , 0.03056567, 0.03271768, 0.03192466,
         0.03307963, 0.03157257, 0.03213196, 0.02884473, 0.02873943,
         0.0277095 , 0.02958181, 0.0317009 , 0.0320859 , 0.03230636,
         0.03536984, 0.03468541, 0.03467554, 0.0343432 , 0.03519873,
         0.03677489, 0.03650178, 0.03552449, 0.03603452, 0.03657417,
         0.0359391 , 0.03525467, 0.0370151 , 0.04048002, 0.03786406,
         0.03270122, 0.03678476, 0.03439584, 0.03423132, 0.03257947,
         0.03485323, 0.03331655, 0.03266174, 0.03322771, 0.031668  ,
         0.03215829, 0.03570218, 0.0356265 , 0.03426093, 0.03579432,
         0.03469528, 0.03454063, 0.03436952, 0.03254328, 0.03237546,
         0.03365548, 0.03399111, 0.03447482, 0.03689993, 0.03771598,
         0.03712369, 0.0371533 , 0.03725531, 0.0362846 , 0.03723557,
         0.03755475, 0.03447482, 0.03318493, 0.03189175, 0.03140476,
         0.03169103, 0.03041102, 0.03184569, 0.03127643, 0.03268806,
         0.03433003, 0.03472161, 0.03311583, 0.03367851, 0.03226687,
         0.03228333, 0.03109874, 0.03224055, 0.03296118, 0.03415564,
         0.03582722, 0.03682096, 0.03512634, 0.03664656, 0.03502104,
         0.03239521, 0.03269135, 0.03375419, 0.03551462, 0.03547514,
         0.03742313, 0.03087827, 0.02920998, 0.03054922, 0.02871311,
         0.03013462, 0.0319444 , 0.03117771, 0.03183911, 0.03215171,
         0.0326387 , 0.03378052, 0.03407008, 0.03532706, 0.03474464,
         0.03394175, 0.03584367, 0.03509672, 0.03550146, 0.03356005,
         0.03317835, 0.03315861, 0.03498485, 0.03440571, 0.03483348,
         0.03561334, 0.03484994, 0.03446165, 0.03494536, 0.03516254,
         0.03813717, 0.03951919, 0.03744945, 0.0364261 , 0.03778179,
         0.0371895 , 0.03852874, 0.03974623, 0.03856165, 0.03700852,
         0.03698219, 0.0360773 , 0.0365643 , 0.03836751, 0.03836092,
         0.03840699, 0.03985811, 0.04039447, 0.04049318, 0.04110193,
         0.04265177, 0.04296108, 0.04322432, 0.04563627, 0.0482325 ,
         0.04791002, 0.04800874, 0.04860761, 0.04710056, 0.04746909,
         0.04689325, 0.04609695, 0.04539935, 0.04686693, 0.04970007,
         0.04775537, 0.04654117, 0.04614959, 0.04758097, 0.04713346,
         0.04607391, 0.04599494, 0.04473138, 0.04434639, 0.04484655,
         0.04465899, 0.04376396, 0.04289856, 0.04129607, 0.04075314,
         0.04099992, 0.04150008, 0.04067087, 0.04236878, 0.04246092,
         0.04121052, 0.03947312, 0.03968701, 0.04047673, 0.03948957,
         0.04206276, 0.04365538, 0.04380674, 0.04438587, 0.04565272,
         0.04586661, 0.04562969, 0.04537303, 0.04506372, 0.04445168,
         0.0471203 , 0.04970665, 0.04971652, 0.05112487, 0.04952896,
         0.05039766, 0.04991066, 0.05171058, 0.05101628, 0.04990737,
         0.0526418 , 0.05249701, 0.05060496, 0.05201331, 0.04904855,
         0.04681099, 0.04516573, 0.04744935, 0.04933153, 0.04926901,
         0.04785409, 0.04919991, 0.04929204, 0.05526763, 0.05444829,
         0.05645551, 0.05455359, 0.05634693, 0.06660678, 0.06488584,
         0.06637973])
  xData = np.array([*range(yData.shape[0])])
  
  popt,pcov = curve_fit(func0, xData, yData)
  </code></pre>
  <p>The last value here isn't the highest, nor the lowest, in the list so why is it here that the error is being thrown?</p>