Pandas数据框计算

7

我正在尝试使用pandas数据框计算一个指标。特别地,我得到了一个结果对象。

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

实际的值在一个数据框中给出。
test['actual']. 

我需要计算两个东西:

  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
    
1个回答

8

首先是:

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

第二个是:
((prediction - test['actual'].mean()) ** 2).sum()

我得到了第一个变量的 NaN 值。这意味着什么? - user1802143
你的数据中有任何NaN吗? - Roman Pekar
我认为这些应该是 .sum()。 - Andy Hayden
据我所知,sum(...).sum()慢?使用np.sum(...)可以正确地执行吗? - Roman Pekar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接