使用Spark DF的数据,Sklearn Mean_absolute_error在相同数据上始终给出不同的值。我该如何解决?

发布于 2025-02-05 00:19:58 字数 474 浏览 3 评论 0原文

我想计算Spark DataFrame的平均平均误差(MAE)到列的平均误差(MAE),但是我无法从pyspark.mllib.mllib.evaluation import intimpry recressionmetrics 使用,因为我的并发群很高。 因此,我使用Sklearn并将其转换为Pandas。

这是我的代码:

mean_absolute_error(test.select("qty").toPandas(),test.select("pred").toPandas()) 
mean_absolute_percentage_error(test.select("qty").toPandas(),test.select("pred").toPandas())

MAE和MAPE每次运行时都会给出不同的值。 什么是原因? 我该如何解决?

顺便说一句:我正在使用databricks,我无法共享数据

I want to calculate the mean average error (MAE) of to columns of a spark dataframe, but I cannot use from pyspark.mllib.evaluation import RegressionMetrics because I have high concurrency cluster.
Therefore, I use sklearn and convert to columns to pandas.

Here is my code:

mean_absolute_error(test.select("qty").toPandas(),test.select("pred").toPandas()) 
mean_absolute_percentage_error(test.select("qty").toPandas(),test.select("pred").toPandas())

Both MAE and MAPE gives different values every time I run it.
What can be the reason?
How can I solve it?

Btw: I am using databricks and I cannot share the data

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水中月 2025-02-12 00:19:58

运行.topandas()整个Spark DataFrame作为Pandas DataFrame移动到驱动程序节点。
这是一个非常宽敞的操作,也可以利用驱动程序的内存,因此请小心。
另外,不能保证熊猫DF中的行的顺序

我认为发生的事情是您运行.topandas() 4次,每次以不同的顺序获取数据框。
这会导致结果变化。

如果您必须使用pandas,建议您进行tmp = test.Select('qty','pred')。topandas()一次,然后将其子集中到MAE和MAPE功能。

When running .toPandas() the entire Spark dataframe is moved into the Driver node as a pandas DataFrame.
This is a very expansive operation that also makes use of the Drivers memory, so be careful.
In addition there is no guarantee what would be the order of the rows in the pandas df.

I think what happens is you run .toPandas() 4 times and each time you get the DataFrame in a different order.
this causes the changing results.

If you have to use pandas I recommend going tmp = test.select('qty', 'pred').toPandas() only once and then subsetting it to the MAE and MAPE functions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文