pyspark.ml.stat.
Summarizer
Tools for vectorized statistics on MLlib Vectors. The methods in this package provide various statistics for Vectors contained inside DataFrames. This class lets users pick the statistics they would like to extract for a given column.
New in version 2.4.0.
Examples
>>> from pyspark.ml.stat import Summarizer >>> from pyspark.sql import Row >>> from pyspark.ml.linalg import Vectors >>> summarizer = Summarizer.metrics("mean", "count") >>> df = sc.parallelize([Row(weight=1.0, features=Vectors.dense(1.0, 1.0, 1.0)), ... Row(weight=0.0, features=Vectors.dense(1.0, 2.0, 3.0))]).toDF() >>> df.select(summarizer.summary(df.features, df.weight)).show(truncate=False) +-----------------------------------+ |aggregate_metrics(features, weight)| +-----------------------------------+ |{[1.0,1.0,1.0], 1} | +-----------------------------------+ >>> df.select(summarizer.summary(df.features)).show(truncate=False) +--------------------------------+ |aggregate_metrics(features, 1.0)| +--------------------------------+ |{[1.0,1.5,2.0], 2} | +--------------------------------+ >>> df.select(Summarizer.mean(df.features, df.weight)).show(truncate=False) +--------------+ |mean(features)| +--------------+ |[1.0,1.0,1.0] | +--------------+ >>> df.select(Summarizer.mean(df.features)).show(truncate=False) +--------------+ |mean(features)| +--------------+ |[1.0,1.5,2.0] | +--------------+
Methods
count(col[, weightCol])
count
return a column of count summary
max(col[, weightCol])
max
return a column of max summary
mean(col[, weightCol])
mean
return a column of mean summary
metrics(*metrics)
metrics
Given a list of metrics, provides a builder that it turns computes metrics from a column.
min(col[, weightCol])
min
return a column of min summary
normL1(col[, weightCol])
normL1
return a column of normL1 summary
normL2(col[, weightCol])
normL2
return a column of normL2 summary
numNonZeros(col[, weightCol])
numNonZeros
return a column of numNonZero summary
std(col[, weightCol])
std
return a column of std summary
sum(col[, weightCol])
sum
return a column of sum summary
variance(col[, weightCol])
variance
return a column of variance summary
Methods Documentation
See the documentation of Summarizer for an example.
mean: a vector that contains the coefficient-wise mean.
sum: a vector that contains the coefficient-wise sum.
variance: a vector tha contains the coefficient-wise variance.
std: a vector tha contains the coefficient-wise standard deviation.
count: the count of all vectors seen.
numNonzeros: a vector with the number of non-zeros for each coefficients
max: the maximum for each coefficient.
min: the minimum for each coefficient.
normL2: the Euclidean norm for each coefficient.
normL1: the L1 norm of each coefficient (sum of the absolute values).
pyspark.ml.stat.SummaryBuilder
Notes
Currently, the performance of this interface is about 2x~3x slower than using the RDD interface.
metrics that can be provided.
New in version 3.0.0.