scipy.optimize.minimize returns “ValueError: The truth value of a Series is ambiguous”
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am maximising the LogLikelihood of an ARMA model, using the scipy.optimize.minimize package and using the BFGS method. However, I get the following error:
The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
The function I am optimizing returns the correct output, i.e. the log likelihood of a specified ARMA model, hence I am trying to look at the source code of the minimize package, however it's quite complex and I can't figure out what the problem is. I realise it's not a straightforward question, however I hope that someone with experience using the minimize package can give me some guidance on what may be causing the error.
The given traceback is as follows:
ValueError Traceback (most recent call last)
/......../.py in fit_ARMA(data, p, q)
150 optim_args=(data, p, q)
151
--> 152 fitted_params = minimize(minus_ll_ARMA, x0=init_params, args=optim_args, method='BFGS')
153
154 return fitted_params.x
/anaconda3/lib/python3.6/site-packages/scipy/optimize/_minimize.py in minimize(fun, x0, args, method, jac, hess, hessp, bounds, constraints, tol, callback, options)
595 return _minimize_cg(fun, x0, args, jac, callback, **options)
596 elif meth == 'bfgs':
--> 597 return _minimize_bfgs(fun, x0, args, jac, callback, **options)
598 elif meth == 'newton-cg':
599 return _minimize_newtoncg(fun, x0, args, jac, hess, hessp, callback,
/anaconda3/lib/python3.6/site-packages/scipy/optimize/optimize.py in _minimize_bfgs(fun, x0, args, jac, callback, gtol, norm, eps, maxiter, disp, return_all, **unknown_options)
981 alpha_k, fc, gc, old_fval, old_old_fval, gfkp1 =
982 _line_search_wolfe12(f, myfprime, xk, pk, gfk,
--> 983 old_fval, old_old_fval, amin=1e-100, amax=1e100)
984 except _LineSearchError:
985 # Line search failed to find a better solution.
/anaconda3/lib/python3.6/site-packages/scipy/optimize/optimize.py in _line_search_wolfe12(f, fprime, xk, pk, gfk, old_fval, old_old_fval, **kwargs)
801 ret = line_search_wolfe1(f, fprime, xk, pk, gfk,
802 old_fval, old_old_fval,
--> 803 **kwargs)
804
805 if ret[0] is not None and extra_condition is not None:
/anaconda3/lib/python3.6/site-packages/scipy/optimize/linesearch.py in line_search_wolfe1(f, fprime, xk, pk, gfk, old_fval, old_old_fval, args, c1, c2, amax, amin, xtol)
99 stp, fval, old_fval = scalar_search_wolfe1(
100 phi, derphi, old_fval, old_old_fval, derphi0,
--> 101 c1=c1, c2=c2, amax=amax, amin=amin, xtol=xtol)
102
103 return stp, fc[0], gc[0], fval, old_fval, gval[0]
/anaconda3/lib/python3.6/site-packages/scipy/optimize/linesearch.py in scalar_search_wolfe1(phi, derphi, phi0, old_phi0, derphi0, c1, c2, amax, amin, xtol)
153
154 if old_phi0 is not None and derphi0 != 0:
--> 155 alpha1 = min(1.0, 1.01*2*(phi0 - old_phi0)/derphi0)
156 if alpha1 < 0:
157 alpha1 = 1.0
/anaconda3/lib/python3.6/site-packages/pandas/core/generic.py in __nonzero__(self)
1574 raise ValueError("The truth value of a {0} is ambiguous. "
1575 "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
-> 1576 .format(self.__class__.__name__))
1577
1578 __bool__ = __nonzero__
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Below are the two functions used:
def ll_ARMA(params, data, p, q):
'''Returns the log-likelihood of the ARMA model.
Data index must be increasing (oldest observations on top)
p= # coeff. AR
q= # coeff MA'''
n = data.shape[0]
if p>0:
lagged_data = data.shift(1).copy()
for i in range(1,p):
lagged_data = pd.concat([lagged_data, data.shift(i+1)], axis=1)
else:
lagged_data = pd.DataFrame(index = data.index, columns=[i+1 for i in range(p)])
errors_index = pd.Index([i for i in range(q)]).append(data.index)
errors = pd.DataFrame(np.zeros(shape=(n+q,1)),index=errors_index)
for i in range(q, n+q):
a = data.iloc[i-q,:] - params[0] - np.sum(np.dot(lagged_data, params[1:p+1])) -
np.dot(params[p+1:], np.asarray([errors.iloc[i-j,:] for j in range(1, q+1)]))
errors.iloc[i,:] = a.item()
errors = errors[q:] # gets rid of initial q values set at 0
var = np.var(errors)
log_likelihood = np.log(2*np.pi*var)*(-1/2) + (-1/2)*(errors**2)/var
return np.sum(log_likelihood)
def fit_ARMA(data, p, q):
'''Returns the fitted parameters of an ARMA model (including the constant).
Order is -constant -p AR coeff -q MA coeff
Data must be a 1-column DF.
p is the parameter of the AR, q of the MA'''
init_params = np.random.random(p+q+1)
def minus_ll_ARMA(params, data, p, q):
return -1*ll_ARMA(params, data, p, q)
optim_args=(data, p, q)
fitted_params = minimize(minus_ll_ARMA, x0=init_params, args=optim_args, method='BFGS')
return fitted_params.x
And this is a workable example that produces the error:
import pandas as pd # version 0.23.4
import numpy as np # version 1.15.4
from scipy.optimize import minimize # version 1.1.0
data = pd.DataFrame(np.random.random(500)*0.4-0.2, index = [i for i in range(1,501)]) # randomly generates returns in a sensible range
parameters = fit_ARMA(data, 2, 3) # this returns the error
P.S. I already looked into the following question: scipy.optimize.minimize Jacobian function causes 'Value Error: The truth value of an array with more than one element is ambiguous', however I'm not including the gradient, so the error is of different nature.
python pandas optimization scipy minimize
|
show 1 more comment
I am maximising the LogLikelihood of an ARMA model, using the scipy.optimize.minimize package and using the BFGS method. However, I get the following error:
The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
The function I am optimizing returns the correct output, i.e. the log likelihood of a specified ARMA model, hence I am trying to look at the source code of the minimize package, however it's quite complex and I can't figure out what the problem is. I realise it's not a straightforward question, however I hope that someone with experience using the minimize package can give me some guidance on what may be causing the error.
The given traceback is as follows:
ValueError Traceback (most recent call last)
/......../.py in fit_ARMA(data, p, q)
150 optim_args=(data, p, q)
151
--> 152 fitted_params = minimize(minus_ll_ARMA, x0=init_params, args=optim_args, method='BFGS')
153
154 return fitted_params.x
/anaconda3/lib/python3.6/site-packages/scipy/optimize/_minimize.py in minimize(fun, x0, args, method, jac, hess, hessp, bounds, constraints, tol, callback, options)
595 return _minimize_cg(fun, x0, args, jac, callback, **options)
596 elif meth == 'bfgs':
--> 597 return _minimize_bfgs(fun, x0, args, jac, callback, **options)
598 elif meth == 'newton-cg':
599 return _minimize_newtoncg(fun, x0, args, jac, hess, hessp, callback,
/anaconda3/lib/python3.6/site-packages/scipy/optimize/optimize.py in _minimize_bfgs(fun, x0, args, jac, callback, gtol, norm, eps, maxiter, disp, return_all, **unknown_options)
981 alpha_k, fc, gc, old_fval, old_old_fval, gfkp1 =
982 _line_search_wolfe12(f, myfprime, xk, pk, gfk,
--> 983 old_fval, old_old_fval, amin=1e-100, amax=1e100)
984 except _LineSearchError:
985 # Line search failed to find a better solution.
/anaconda3/lib/python3.6/site-packages/scipy/optimize/optimize.py in _line_search_wolfe12(f, fprime, xk, pk, gfk, old_fval, old_old_fval, **kwargs)
801 ret = line_search_wolfe1(f, fprime, xk, pk, gfk,
802 old_fval, old_old_fval,
--> 803 **kwargs)
804
805 if ret[0] is not None and extra_condition is not None:
/anaconda3/lib/python3.6/site-packages/scipy/optimize/linesearch.py in line_search_wolfe1(f, fprime, xk, pk, gfk, old_fval, old_old_fval, args, c1, c2, amax, amin, xtol)
99 stp, fval, old_fval = scalar_search_wolfe1(
100 phi, derphi, old_fval, old_old_fval, derphi0,
--> 101 c1=c1, c2=c2, amax=amax, amin=amin, xtol=xtol)
102
103 return stp, fc[0], gc[0], fval, old_fval, gval[0]
/anaconda3/lib/python3.6/site-packages/scipy/optimize/linesearch.py in scalar_search_wolfe1(phi, derphi, phi0, old_phi0, derphi0, c1, c2, amax, amin, xtol)
153
154 if old_phi0 is not None and derphi0 != 0:
--> 155 alpha1 = min(1.0, 1.01*2*(phi0 - old_phi0)/derphi0)
156 if alpha1 < 0:
157 alpha1 = 1.0
/anaconda3/lib/python3.6/site-packages/pandas/core/generic.py in __nonzero__(self)
1574 raise ValueError("The truth value of a {0} is ambiguous. "
1575 "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
-> 1576 .format(self.__class__.__name__))
1577
1578 __bool__ = __nonzero__
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Below are the two functions used:
def ll_ARMA(params, data, p, q):
'''Returns the log-likelihood of the ARMA model.
Data index must be increasing (oldest observations on top)
p= # coeff. AR
q= # coeff MA'''
n = data.shape[0]
if p>0:
lagged_data = data.shift(1).copy()
for i in range(1,p):
lagged_data = pd.concat([lagged_data, data.shift(i+1)], axis=1)
else:
lagged_data = pd.DataFrame(index = data.index, columns=[i+1 for i in range(p)])
errors_index = pd.Index([i for i in range(q)]).append(data.index)
errors = pd.DataFrame(np.zeros(shape=(n+q,1)),index=errors_index)
for i in range(q, n+q):
a = data.iloc[i-q,:] - params[0] - np.sum(np.dot(lagged_data, params[1:p+1])) -
np.dot(params[p+1:], np.asarray([errors.iloc[i-j,:] for j in range(1, q+1)]))
errors.iloc[i,:] = a.item()
errors = errors[q:] # gets rid of initial q values set at 0
var = np.var(errors)
log_likelihood = np.log(2*np.pi*var)*(-1/2) + (-1/2)*(errors**2)/var
return np.sum(log_likelihood)
def fit_ARMA(data, p, q):
'''Returns the fitted parameters of an ARMA model (including the constant).
Order is -constant -p AR coeff -q MA coeff
Data must be a 1-column DF.
p is the parameter of the AR, q of the MA'''
init_params = np.random.random(p+q+1)
def minus_ll_ARMA(params, data, p, q):
return -1*ll_ARMA(params, data, p, q)
optim_args=(data, p, q)
fitted_params = minimize(minus_ll_ARMA, x0=init_params, args=optim_args, method='BFGS')
return fitted_params.x
And this is a workable example that produces the error:
import pandas as pd # version 0.23.4
import numpy as np # version 1.15.4
from scipy.optimize import minimize # version 1.1.0
data = pd.DataFrame(np.random.random(500)*0.4-0.2, index = [i for i in range(1,501)]) # randomly generates returns in a sensible range
parameters = fit_ARMA(data, 2, 3) # this returns the error
P.S. I already looked into the following question: scipy.optimize.minimize Jacobian function causes 'Value Error: The truth value of an array with more than one element is ambiguous', however I'm not including the gradient, so the error is of different nature.
python pandas optimization scipy minimize
2
What if you change toinit_params = np.random.random((p+q+1,))
?
– BlackBear
Jan 4 at 12:18
1
Can you give an idea about whatdata
is?
– Cleb
Jan 4 at 12:26
@BlackBear: same error occurs
– Daniele
Jan 4 at 13:18
@Cleb: data is a 1-column dataframe with dates as index and returns as values
– Daniele
Jan 4 at 13:19
Could you give an example?! Also, please include all your imports, then it becomes easier to copy&paste.
– Cleb
Jan 5 at 18:15
|
show 1 more comment
I am maximising the LogLikelihood of an ARMA model, using the scipy.optimize.minimize package and using the BFGS method. However, I get the following error:
The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
The function I am optimizing returns the correct output, i.e. the log likelihood of a specified ARMA model, hence I am trying to look at the source code of the minimize package, however it's quite complex and I can't figure out what the problem is. I realise it's not a straightforward question, however I hope that someone with experience using the minimize package can give me some guidance on what may be causing the error.
The given traceback is as follows:
ValueError Traceback (most recent call last)
/......../.py in fit_ARMA(data, p, q)
150 optim_args=(data, p, q)
151
--> 152 fitted_params = minimize(minus_ll_ARMA, x0=init_params, args=optim_args, method='BFGS')
153
154 return fitted_params.x
/anaconda3/lib/python3.6/site-packages/scipy/optimize/_minimize.py in minimize(fun, x0, args, method, jac, hess, hessp, bounds, constraints, tol, callback, options)
595 return _minimize_cg(fun, x0, args, jac, callback, **options)
596 elif meth == 'bfgs':
--> 597 return _minimize_bfgs(fun, x0, args, jac, callback, **options)
598 elif meth == 'newton-cg':
599 return _minimize_newtoncg(fun, x0, args, jac, hess, hessp, callback,
/anaconda3/lib/python3.6/site-packages/scipy/optimize/optimize.py in _minimize_bfgs(fun, x0, args, jac, callback, gtol, norm, eps, maxiter, disp, return_all, **unknown_options)
981 alpha_k, fc, gc, old_fval, old_old_fval, gfkp1 =
982 _line_search_wolfe12(f, myfprime, xk, pk, gfk,
--> 983 old_fval, old_old_fval, amin=1e-100, amax=1e100)
984 except _LineSearchError:
985 # Line search failed to find a better solution.
/anaconda3/lib/python3.6/site-packages/scipy/optimize/optimize.py in _line_search_wolfe12(f, fprime, xk, pk, gfk, old_fval, old_old_fval, **kwargs)
801 ret = line_search_wolfe1(f, fprime, xk, pk, gfk,
802 old_fval, old_old_fval,
--> 803 **kwargs)
804
805 if ret[0] is not None and extra_condition is not None:
/anaconda3/lib/python3.6/site-packages/scipy/optimize/linesearch.py in line_search_wolfe1(f, fprime, xk, pk, gfk, old_fval, old_old_fval, args, c1, c2, amax, amin, xtol)
99 stp, fval, old_fval = scalar_search_wolfe1(
100 phi, derphi, old_fval, old_old_fval, derphi0,
--> 101 c1=c1, c2=c2, amax=amax, amin=amin, xtol=xtol)
102
103 return stp, fc[0], gc[0], fval, old_fval, gval[0]
/anaconda3/lib/python3.6/site-packages/scipy/optimize/linesearch.py in scalar_search_wolfe1(phi, derphi, phi0, old_phi0, derphi0, c1, c2, amax, amin, xtol)
153
154 if old_phi0 is not None and derphi0 != 0:
--> 155 alpha1 = min(1.0, 1.01*2*(phi0 - old_phi0)/derphi0)
156 if alpha1 < 0:
157 alpha1 = 1.0
/anaconda3/lib/python3.6/site-packages/pandas/core/generic.py in __nonzero__(self)
1574 raise ValueError("The truth value of a {0} is ambiguous. "
1575 "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
-> 1576 .format(self.__class__.__name__))
1577
1578 __bool__ = __nonzero__
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Below are the two functions used:
def ll_ARMA(params, data, p, q):
'''Returns the log-likelihood of the ARMA model.
Data index must be increasing (oldest observations on top)
p= # coeff. AR
q= # coeff MA'''
n = data.shape[0]
if p>0:
lagged_data = data.shift(1).copy()
for i in range(1,p):
lagged_data = pd.concat([lagged_data, data.shift(i+1)], axis=1)
else:
lagged_data = pd.DataFrame(index = data.index, columns=[i+1 for i in range(p)])
errors_index = pd.Index([i for i in range(q)]).append(data.index)
errors = pd.DataFrame(np.zeros(shape=(n+q,1)),index=errors_index)
for i in range(q, n+q):
a = data.iloc[i-q,:] - params[0] - np.sum(np.dot(lagged_data, params[1:p+1])) -
np.dot(params[p+1:], np.asarray([errors.iloc[i-j,:] for j in range(1, q+1)]))
errors.iloc[i,:] = a.item()
errors = errors[q:] # gets rid of initial q values set at 0
var = np.var(errors)
log_likelihood = np.log(2*np.pi*var)*(-1/2) + (-1/2)*(errors**2)/var
return np.sum(log_likelihood)
def fit_ARMA(data, p, q):
'''Returns the fitted parameters of an ARMA model (including the constant).
Order is -constant -p AR coeff -q MA coeff
Data must be a 1-column DF.
p is the parameter of the AR, q of the MA'''
init_params = np.random.random(p+q+1)
def minus_ll_ARMA(params, data, p, q):
return -1*ll_ARMA(params, data, p, q)
optim_args=(data, p, q)
fitted_params = minimize(minus_ll_ARMA, x0=init_params, args=optim_args, method='BFGS')
return fitted_params.x
And this is a workable example that produces the error:
import pandas as pd # version 0.23.4
import numpy as np # version 1.15.4
from scipy.optimize import minimize # version 1.1.0
data = pd.DataFrame(np.random.random(500)*0.4-0.2, index = [i for i in range(1,501)]) # randomly generates returns in a sensible range
parameters = fit_ARMA(data, 2, 3) # this returns the error
P.S. I already looked into the following question: scipy.optimize.minimize Jacobian function causes 'Value Error: The truth value of an array with more than one element is ambiguous', however I'm not including the gradient, so the error is of different nature.
python pandas optimization scipy minimize
I am maximising the LogLikelihood of an ARMA model, using the scipy.optimize.minimize package and using the BFGS method. However, I get the following error:
The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
The function I am optimizing returns the correct output, i.e. the log likelihood of a specified ARMA model, hence I am trying to look at the source code of the minimize package, however it's quite complex and I can't figure out what the problem is. I realise it's not a straightforward question, however I hope that someone with experience using the minimize package can give me some guidance on what may be causing the error.
The given traceback is as follows:
ValueError Traceback (most recent call last)
/......../.py in fit_ARMA(data, p, q)
150 optim_args=(data, p, q)
151
--> 152 fitted_params = minimize(minus_ll_ARMA, x0=init_params, args=optim_args, method='BFGS')
153
154 return fitted_params.x
/anaconda3/lib/python3.6/site-packages/scipy/optimize/_minimize.py in minimize(fun, x0, args, method, jac, hess, hessp, bounds, constraints, tol, callback, options)
595 return _minimize_cg(fun, x0, args, jac, callback, **options)
596 elif meth == 'bfgs':
--> 597 return _minimize_bfgs(fun, x0, args, jac, callback, **options)
598 elif meth == 'newton-cg':
599 return _minimize_newtoncg(fun, x0, args, jac, hess, hessp, callback,
/anaconda3/lib/python3.6/site-packages/scipy/optimize/optimize.py in _minimize_bfgs(fun, x0, args, jac, callback, gtol, norm, eps, maxiter, disp, return_all, **unknown_options)
981 alpha_k, fc, gc, old_fval, old_old_fval, gfkp1 =
982 _line_search_wolfe12(f, myfprime, xk, pk, gfk,
--> 983 old_fval, old_old_fval, amin=1e-100, amax=1e100)
984 except _LineSearchError:
985 # Line search failed to find a better solution.
/anaconda3/lib/python3.6/site-packages/scipy/optimize/optimize.py in _line_search_wolfe12(f, fprime, xk, pk, gfk, old_fval, old_old_fval, **kwargs)
801 ret = line_search_wolfe1(f, fprime, xk, pk, gfk,
802 old_fval, old_old_fval,
--> 803 **kwargs)
804
805 if ret[0] is not None and extra_condition is not None:
/anaconda3/lib/python3.6/site-packages/scipy/optimize/linesearch.py in line_search_wolfe1(f, fprime, xk, pk, gfk, old_fval, old_old_fval, args, c1, c2, amax, amin, xtol)
99 stp, fval, old_fval = scalar_search_wolfe1(
100 phi, derphi, old_fval, old_old_fval, derphi0,
--> 101 c1=c1, c2=c2, amax=amax, amin=amin, xtol=xtol)
102
103 return stp, fc[0], gc[0], fval, old_fval, gval[0]
/anaconda3/lib/python3.6/site-packages/scipy/optimize/linesearch.py in scalar_search_wolfe1(phi, derphi, phi0, old_phi0, derphi0, c1, c2, amax, amin, xtol)
153
154 if old_phi0 is not None and derphi0 != 0:
--> 155 alpha1 = min(1.0, 1.01*2*(phi0 - old_phi0)/derphi0)
156 if alpha1 < 0:
157 alpha1 = 1.0
/anaconda3/lib/python3.6/site-packages/pandas/core/generic.py in __nonzero__(self)
1574 raise ValueError("The truth value of a {0} is ambiguous. "
1575 "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
-> 1576 .format(self.__class__.__name__))
1577
1578 __bool__ = __nonzero__
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Below are the two functions used:
def ll_ARMA(params, data, p, q):
'''Returns the log-likelihood of the ARMA model.
Data index must be increasing (oldest observations on top)
p= # coeff. AR
q= # coeff MA'''
n = data.shape[0]
if p>0:
lagged_data = data.shift(1).copy()
for i in range(1,p):
lagged_data = pd.concat([lagged_data, data.shift(i+1)], axis=1)
else:
lagged_data = pd.DataFrame(index = data.index, columns=[i+1 for i in range(p)])
errors_index = pd.Index([i for i in range(q)]).append(data.index)
errors = pd.DataFrame(np.zeros(shape=(n+q,1)),index=errors_index)
for i in range(q, n+q):
a = data.iloc[i-q,:] - params[0] - np.sum(np.dot(lagged_data, params[1:p+1])) -
np.dot(params[p+1:], np.asarray([errors.iloc[i-j,:] for j in range(1, q+1)]))
errors.iloc[i,:] = a.item()
errors = errors[q:] # gets rid of initial q values set at 0
var = np.var(errors)
log_likelihood = np.log(2*np.pi*var)*(-1/2) + (-1/2)*(errors**2)/var
return np.sum(log_likelihood)
def fit_ARMA(data, p, q):
'''Returns the fitted parameters of an ARMA model (including the constant).
Order is -constant -p AR coeff -q MA coeff
Data must be a 1-column DF.
p is the parameter of the AR, q of the MA'''
init_params = np.random.random(p+q+1)
def minus_ll_ARMA(params, data, p, q):
return -1*ll_ARMA(params, data, p, q)
optim_args=(data, p, q)
fitted_params = minimize(minus_ll_ARMA, x0=init_params, args=optim_args, method='BFGS')
return fitted_params.x
And this is a workable example that produces the error:
import pandas as pd # version 0.23.4
import numpy as np # version 1.15.4
from scipy.optimize import minimize # version 1.1.0
data = pd.DataFrame(np.random.random(500)*0.4-0.2, index = [i for i in range(1,501)]) # randomly generates returns in a sensible range
parameters = fit_ARMA(data, 2, 3) # this returns the error
P.S. I already looked into the following question: scipy.optimize.minimize Jacobian function causes 'Value Error: The truth value of an array with more than one element is ambiguous', however I'm not including the gradient, so the error is of different nature.
python pandas optimization scipy minimize
python pandas optimization scipy minimize
edited Jan 15 at 15:00
Daniele
asked Jan 4 at 12:04
DanieleDaniele
1038
1038
2
What if you change toinit_params = np.random.random((p+q+1,))
?
– BlackBear
Jan 4 at 12:18
1
Can you give an idea about whatdata
is?
– Cleb
Jan 4 at 12:26
@BlackBear: same error occurs
– Daniele
Jan 4 at 13:18
@Cleb: data is a 1-column dataframe with dates as index and returns as values
– Daniele
Jan 4 at 13:19
Could you give an example?! Also, please include all your imports, then it becomes easier to copy&paste.
– Cleb
Jan 5 at 18:15
|
show 1 more comment
2
What if you change toinit_params = np.random.random((p+q+1,))
?
– BlackBear
Jan 4 at 12:18
1
Can you give an idea about whatdata
is?
– Cleb
Jan 4 at 12:26
@BlackBear: same error occurs
– Daniele
Jan 4 at 13:18
@Cleb: data is a 1-column dataframe with dates as index and returns as values
– Daniele
Jan 4 at 13:19
Could you give an example?! Also, please include all your imports, then it becomes easier to copy&paste.
– Cleb
Jan 5 at 18:15
2
2
What if you change to
init_params = np.random.random((p+q+1,))
?– BlackBear
Jan 4 at 12:18
What if you change to
init_params = np.random.random((p+q+1,))
?– BlackBear
Jan 4 at 12:18
1
1
Can you give an idea about what
data
is?– Cleb
Jan 4 at 12:26
Can you give an idea about what
data
is?– Cleb
Jan 4 at 12:26
@BlackBear: same error occurs
– Daniele
Jan 4 at 13:18
@BlackBear: same error occurs
– Daniele
Jan 4 at 13:18
@Cleb: data is a 1-column dataframe with dates as index and returns as values
– Daniele
Jan 4 at 13:19
@Cleb: data is a 1-column dataframe with dates as index and returns as values
– Daniele
Jan 4 at 13:19
Could you give an example?! Also, please include all your imports, then it becomes easier to copy&paste.
– Cleb
Jan 5 at 18:15
Could you give an example?! Also, please include all your imports, then it becomes easier to copy&paste.
– Cleb
Jan 5 at 18:15
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54038649%2fscipy-optimize-minimize-returns-valueerror-the-truth-value-of-a-series-is-ambi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54038649%2fscipy-optimize-minimize-returns-valueerror-the-truth-value-of-a-series-is-ambi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
What if you change to
init_params = np.random.random((p+q+1,))
?– BlackBear
Jan 4 at 12:18
1
Can you give an idea about what
data
is?– Cleb
Jan 4 at 12:26
@BlackBear: same error occurs
– Daniele
Jan 4 at 13:18
@Cleb: data is a 1-column dataframe with dates as index and returns as values
– Daniele
Jan 4 at 13:19
Could you give an example?! Also, please include all your imports, then it becomes easier to copy&paste.
– Cleb
Jan 5 at 18:15