首页 > 解决方案 > 使用 TopN 与考拉进行绘图有任何统计意义吗?

问题描述

我正在浏览Koalas的源代码,试图了解它们如何真正实现绘制大型数据集。事实证明,他们要么使用抽样,要么使用TopN- 选择给定数量的记录。

我了解采样的含义,并且在内部使用它spark.DataFrame.sample来执行此操作。但是,对于TopN,他们只是max_rows使用data = data.head(max_rows + 1).to_pandas().

这看起来很奇怪,我想知道它是否正确反映了以这种方式进行数据选择的数据集的统计属性。

Koalas DataFrame 的绘图访问器:

class KoalasPlotAccessor(PandasObject):
    pandas_plot_data_map = {
        "pie": TopNPlotBase().get_top_n,
        "bar": TopNPlotBase().get_top_n,
        "barh": TopNPlotBase().get_top_n,
        "scatter": SampledPlotBase().get_sampled,
        "area": SampledPlotBase().get_sampled,
        "line": SampledPlotBase().get_sampled,
    }
    _backends = {}  # type: ignore
    
    ...

class TopNPlotBase:
    def get_top_n(self, data):
        from databricks.koalas import DataFrame, Series

        max_rows = get_option("plotting.max_rows")
        # Simply use the first 1k elements and make it into a pandas dataframe
        # For categorical variables, it is likely called from df.x.value_counts().plot.xxx().
        if isinstance(data, (Series, DataFrame)):
            data = data.head(max_rows + 1).to_pandas()
        ...

标签: pandaspysparkstatisticsdata-visualizationspark-koalas

解决方案


推荐阅读