**Ошибка UFuncTypeError: Не удается привести значение ufunc ‘greater_equal’ на входе 0 из dtype(‘<m8[ns]') в dtype('**

#python #pandas #numpy #parameters #estimation

Вопрос:

Я столкнулся с этой проблемой, пытаясь запустить оценку параметров. Проблема в том, что код отлично работает для моего товарища по команде, но не для меня ( буквально тот же код, разница только в каталоге файла ). Может ли кто-нибудь помочь мне понять, в чем здесь может быть проблема? Это дает мне следующую ошибку : Ошибка UFuncTypeError: Не удается привести ufunc ‘greater_equal’ к входу 0 из dtype(‘lt;m8[ns]’) в dtype(‘lt;m8’) с правилом приведения ‘same_kind’ при его запуске. Что бы это могло значить?

 # import package import matplotlib.pyplot as plt import numpy as np import pandas as pd  # read the dataset data = pd.read_excel('/Users/vladimirbarshchuk/Desktop/PythonMathCapStone/data/data.xlsx') print(data)  # define the actual data x = np.array(data.loc[:,"WHO report date"][:265]) y = np.array(data.loc[:,"Total Cases, Guinea"][:265])  # Define values that we already know, such as initial values. N = 5364500 S0 = N E0 = 0 I0 = 2 R0 = 0 C0 = I0 k=1/5.30 g=1/5.61  b_0=0.33 b_1=0.09 t=0.71 Tao=56 q=np.log(2)/t  # define the function that will solve the differential equations def odes(y, t, b_0, b_1, q, g, k):  if tlt;Tao:  b=b_0  else:  b=(b_1 (b_0-b_1)*np.exp((-q*(t-Tao))))    dSdt = -b*y[0]*y[2]/N  dEdt = b*y[0]*y[2]/N-k*y[1]  dIdt = k*y[1]-g*y[2]  dRdt = g*y[2]  dCdt = k*y[1]  return dSdt, dEdt, dIdt, dRdt, dCdt  from scipy import integrate from scipy import optimize  # begin fitting the model to the data def params(t, b_0, b_1, q, g, k):  return integrate.odeint(odes, (S0, E0, I0, R0, C0), x, args = (b_0, b_1, q, g, k))[:,4]  fitted_curve, popx = optimize.curve_fit(params, x, y, p0 = [0.33,0.09,0.976,1/5.61,1/5.3]) fitted = params(t, *fitted_curve)  # get standard deviations of parameters stdevs = np.sqrt(np.diag(popx))  # print the parameters print("b_0 = "   str(round(fitted_curve[0],3))   " with a standard deviation of "   str(round(stdevs[0],3))) print("b_1 = "   str(round(fitted_curve[1],3))   " with a standard deviation of "   str(round(stdevs[1],3))) print("q = "   str(round(fitted_curve[2],3))   " with a standard deviation of "   str(round(stdevs[2],3))) print("g = "   str(round(fitted_curve[3],3))   " with a standard deviation of "   str(round(stdevs[3],3))) print("k = "   str(round(fitted_curve[4],3))   " with a standard deviation of "   str(round(stdevs[4],3)))  # Find confidence intervals import scipy.stats as st lower_b_0 = fitted_curve[0] - 1.96*(stdevs[0]/(len(x)**.5)) upper_b_0 = fitted_curve[0]   1.96*(stdevs[0]/(len(x)**.5)) lower_b_1 = fitted_curve[1] - 1.96*(stdevs[1]/(len(x)**.5)) upper_b_1 = fitted_curve[1]   1.96*(stdevs[1]/(len(x)**.5)) lower_q = fitted_curve[2] - 1.96*(stdevs[2]/(len(x)**.5)) upper_q = fitted_curve[2]   1.96*(stdevs[2]/(len(x)**.5)) lower_g = fitted_curve[3] - 1.96*(stdevs[3]/(len(x)**.5)) upper_g = fitted_curve[3]   1.96*(stdevs[3]/(len(x)**.5)) lower_k = fitted_curve[4] - 1.96*(stdevs[4]/(len(x)**.5)) upper_k = fitted_curve[4]   1.96*(stdevs[4]/(len(x)**.5))  print("The confidence interval of b_0 is "   str(round(lower_b_0,3))   " to "   str(round(upper_b_0,3))) print("The confidence interval of b_1 is "   str(round(lower_b_1,3))   " to "   str(round(upper_b_1,3))) print("The confidence interval of q is "   str(round(lower_q,3))   " to "   str(round(upper_q,3))) print("The confidence interval of g is "   str(round(lower_g,3))   " to "   str(round(upper_g,3))) print("The confidence interval of k is "   str(round(lower_k,3))   " to "   str(round(upper_k,3)))  # plot the fitted values against the data plt.plot(x, y) plt.plot(x, fitted) plt.show()  # find the error import math residuals = abs(x - fitted) residuals_sq = residuals**2 RMSE = math.sqrt(sum(residuals_sq)) print("The Root Mean Squared Error is "   str(RMSE))  

Комментарии:

1. m8[ns] dtype-это np.datetime64 dtype. Ошибка говорит о несоответствии между единицами измерения времени двух массивов, которые он должен сравнивать. Вы не предоставили обратную трассировку или не показали никаких промежуточных данных, но я предполагаю, что даты взяты из фрейма данных, загруженного из вашего файла. Это gt;= может произойти глубоко в curve_fit (так как я не вижу ничего подобного в вашем коде).