虽然计算SSE收到错误:“numpy.float64”对象不是可迭代
我试图计算方误差之和(SSE),下面提到虽然计算SSE收到错误:“numpy.float64”对象不是可迭代
def SSEadver(tv_train,radio_train,newsppr_train,y_train): y_train_predct = []
sse_train = 0
y_train_predct_srs = 0
# Calculating the predicted sales values on training data
for i in range(0,len(tv_train)):
y_train_predct.append(2.8769666223179353 + (0.04656457* tv_train.iloc[i])+ (0.17915812*(radio_train.iloc[i])) + (0.00345046*(newsppr_train.iloc[i])))
# ** Here I Convert y_train_predct's type List to Series, but still it is showing type as list**
y_train_predct_srs = pd.Series(y_train_predct)
# *** Due above converting not working here y_train_predct_srs.iloc[j]) is not working***
# Now calculate SSE (sum of Squared Errors)
for j in range (len(y_train)):
sse_train += sum((y_train.iloc[j] - y_train_predct_srs.iloc[j])**2)
return y_train_predct, y_train_predct_srs
sse_train = SSEadver(tv_train,radio_train,newsppr_train, y_train)
代码,而我运行此代码我收到错误:
TypeError Traceback (most recent call last) <ipython-input-446-576e1af02461> in <module>()
20 return y_train_predct, y_train_predct_srs
21
---> 22 sse_train = SSEadver(tv_train,radio_train,newsppr_train, y_train)
23
<ipython-input-446-576e1af02461> in SSEadver(tv_train, radio_train, newsppr_train, y_train)
14 # Now calculate SSE (sum of Squared Errors)
15 for j in range (len(y_train)):
---> 16 sse_train += sum((y_train.iloc[j] - y_train_predct_srs.iloc[j])**2)
17
18
TypeError: 'numpy.float64' object is not iterable
为什么我收到THI错误?我使用Python 3.X.X
回答:
我不能看到所有的代码,但是,它看起来像任何
y_train.iloc
或y_train_predct_srs.iloc
不是列表,但实际上numpy.float64。你应该检查他们是绝对是列表,然后再试一次。
以上是 虽然计算SSE收到错误:“numpy.float64”对象不是可迭代 的全部内容, 来源链接: utcz.com/qa/263898.html