-2

I am trying to calculate the Sum of Square Error(SSE), code mentioned below


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)

While I run this code I am getting error :


   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

why am I getting this error? I am using Python 3.X.X

  • Possible duplicate of ['numpy.float64' object is not iterable - meanshift clustering](https://stackoverflow.com/questions/39048355/numpy-float64-object-is-not-iterable-meanshift-clustering) – Sombrero Dec 18 '17 at 14:00
  • # Here I try to Convert y_train_predct type List to Series, but it is converted as tuple instead of Pandas Data Series. **y_train_predct_srs = pd.Series(y_train_predct)** – user3631357 Dec 18 '17 at 16:34
  • But the same line of code, once I run in a individual cell it is converted list to Pandas Series. ---- why dual behave ? Please help. – user3631357 Dec 18 '17 at 16:39

1 Answers1

0

I can't see all your code, however, it looks like either

y_train.iloc or y_train_predct_srs.iloc

are not lists, but in fact numpy.float64. You should check they are definitely lists, and try again.

Jgd10
  • 497
  • 2
  • 14