Following my previous two posts (post1, post 2), I have now reached the point where I use scipy
to find a curve fit. However, the code I have produces an error.
A sample of the .csv
file I'm working with is located in post1. I tried to copy and substitute examples from the Internet, but it doesn't seem to be working.
Here's what I have (the .py
file)
import pandas as pd
import numpy as np
from scipy import optimize
df = pd.read_csv("~/Truncated raw data hcl.csv", usecols=['time' , '1mnaoh trial 1']).dropna()
data1 = df
array1 = np.asarray(data1)
x , y = np.split(array1,[-1],axis=1)
def func(x, a , b , c , d , e):
return a + (b - a)/((1 + c*np.exp(-d*x))**(1/e))
popt, pcov = optimize.curve_fit(func, x , y , p0=[23.2, 30.1 , 1 , 1 , 1])
popt
From the limited research I've done, it might be a problem with the x and y arrays. The title states the error that is written. It is a minpack.error
.
Edit: the error returned
ValueError: object too deep for desired array
Traceback (most recent call last):
File "~/test2.py", line 15, in <module>
popt, pcov = optimize.curve_fit(func, x , y , p0=[23.2, 30.1 , 1 , 1 , 1])
File "~/'virtualenvname'/lib/python3.7/site-packages/scipy/optimize/minpack.py", line 744, in curve_fit
res = leastsq(func, p0, Dfun=jac, full_output=1, **kwargs)
File "~/'virtualenvname'/lib/python3.7/site-packages/scipy/optimize/minpack.py", line 394, in leastsq
gtol, maxfev, epsfcn, factor, diag)
minpack.error: Result from function call is not a proper array of floats.
Thank you.