メインコンテンツまでスキップ

カウント最小スケッチ

指定された esp、信頼度、シードを持つ列の count-min スケッチを返します。結果はバイト配列であり、使用前にCountMinSketchに逆シリアル化できます。Count-min スケッチは、サブ線形空間を使用してカーディナリティ推定に使用される確率的データ構造です。

構文

Python
from pyspark.sql import functions as sf

sf.count_min_sketch(col, eps, confidence, seed=None)

パラメーター

パラメーター

Type

説明

col

pyspark.sql.Column または文字列

ターゲットカラムをコンピュートに。

eps

pyspark.sql.Column またはフロート

相対誤差は正の値でなければなりません。

confidence

pyspark.sql.Column またはフロート

信頼度は正で、1.0 未満である必要があります。

seed

pyspark.sql.Column または int(オプション)

ランダムシード。

パラメーター

Type

説明

col

pyspark.sql.Column または文字列

ターゲットカラムをコンピュートに。

eps

pyspark.sql.Column またはフロート

相対誤差は正の値でなければなりません。

confidence

pyspark.sql.Column またはフロート

信頼度は正で、1.0 未満である必要があります。

seed

pyspark.sql.Column または int(オプション)

ランダムシード。

戻り値

pyspark.sql.Column: 列の最小スケッチ

例1 : 列を引数として使用する

Python
from pyspark.sql import functions as sf
spark.range(100).select(
sf.hex(sf.count_min_sketch(sf.col("id"), sf.lit(3.0), sf.lit(0.1), sf.lit(1)))
).show(truncate=False)
Output
+------------------------------------------------------------------------+
|hex(count_min_sketch(id, 3.0, 0.1, 1)) |
+------------------------------------------------------------------------+
|0000000100000000000000640000000100000001000000005D8D6AB90000000000000064|
+------------------------------------------------------------------------+

例2 : 数値を引数として使用する

Python
from pyspark.sql import functions as sf
spark.range(100).select(
sf.hex(sf.count_min_sketch("id", 1.0, 0.3, 2))
).show(truncate=False)
Output
+----------------------------------------------------------------------------------------+
|hex(count_min_sketch(id, 1.0, 0.3, 2)) |
+----------------------------------------------------------------------------------------+
|0000000100000000000000640000000100000002000000005D96391C00000000000000320000000000000032|
+----------------------------------------------------------------------------------------+

例3 : 長いシードを使用する

Python
from pyspark.sql import functions as sf
spark.range(100).select(
sf.hex(sf.count_min_sketch("id", sf.lit(1.5), 0.2, 1111111111111111111))
).show(truncate=False)
Output
+----------------------------------------------------------------------------------------+
|hex(count_min_sketch(id, 1.5, 0.2, 1111111111111111111)) |
+----------------------------------------------------------------------------------------+
|00000001000000000000006400000001000000020000000044078BA100000000000000320000000000000032|
+----------------------------------------------------------------------------------------+
このページの見出し