7

I am trying compute a metric with panda dataframes. In particular, I get a results object

prediction = results.predict(start=1,end=len(test),exog=test)

The actual values are in a dataframe given by

test['actual']. 

I need to compute two things:

  1. How can I compute the sum of squares of errors? So basically, I would be doing an element by element subtraction and then summing the squares of these.

  2. How can I compute the sum of squares of the predicted minus the mean of the actual values? So it would be

    (x1-mean_actual)^2 + (x2-mean_actual)^2...+(xn-mean_actual)^2
    
0

1 Answer 1

8

First one would be

((prediction - test['actual']) ** 2).sum()

Second one would be:

((prediction - test['actual'].mean()) ** 2).sum()
Sign up to request clarification or add additional context in comments.

4 Comments

I get a nan value for the first one. What does that imply?
do you have any NaN in your data?
I think these should be .sum()
@AndyHayden AFAIK, sum(...) will be slower than .sum()? is it possible to do it right with np.sum(...)?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.