pyspark.ml.fpm.
PrefixSpan
A parallel PrefixSpan algorithm to mine frequent sequential patterns. The PrefixSpan algorithm is described in J. Pei, et al., PrefixSpan: Mining Sequential Patterns Efficiently by Prefix-Projected Pattern Growth (see here). This class is not yet an Estimator/Transformer, use findFrequentSequentialPatterns() method to run the PrefixSpan algorithm.
findFrequentSequentialPatterns()
New in version 2.4.0.
Notes
See Sequential Pattern Mining (Wikipedia)
Examples
>>> from pyspark.ml.fpm import PrefixSpan >>> from pyspark.sql import Row >>> df = sc.parallelize([Row(sequence=[[1, 2], [3]]), ... Row(sequence=[[1], [3, 2], [1, 2]]), ... Row(sequence=[[1, 2], [5]]), ... Row(sequence=[[6]])]).toDF() >>> prefixSpan = PrefixSpan() >>> prefixSpan.getMaxLocalProjDBSize() 32000000 >>> prefixSpan.getSequenceCol() 'sequence' >>> prefixSpan.setMinSupport(0.5) PrefixSpan... >>> prefixSpan.setMaxPatternLength(5) PrefixSpan... >>> prefixSpan.findFrequentSequentialPatterns(df).sort("sequence").show(truncate=False) +----------+----+ |sequence |freq| +----------+----+ |[[1]] |3 | |[[1], [3]]|2 | |[[2]] |3 | |[[2, 1]] |3 | |[[3]] |2 | +----------+----+ ...
Methods
clear(param)
clear
Clears a param from the param map if it has been explicitly set.
copy([extra])
copy
Creates a copy of this instance with the same uid and some extra params.
explainParam(param)
explainParam
Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.
explainParams()
explainParams
Returns the documentation of all params with their optionally default values and user-supplied values.
extractParamMap([extra])
extractParamMap
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.
findFrequentSequentialPatterns(dataset)
findFrequentSequentialPatterns
Finds the complete set of frequent sequential patterns in the input sequences of itemsets.
getMaxLocalProjDBSize()
getMaxLocalProjDBSize
Gets the value of maxLocalProjDBSize or its default value.
getMaxPatternLength()
getMaxPatternLength
Gets the value of maxPatternLength or its default value.
getMinSupport()
getMinSupport
Gets the value of minSupport or its default value.
getOrDefault(param)
getOrDefault
Gets the value of a param in the user-supplied param map or its default value.
getParam(paramName)
getParam
Gets a param by its name.
getSequenceCol()
getSequenceCol
Gets the value of sequenceCol or its default value.
hasDefault(param)
hasDefault
Checks whether a param has a default value.
hasParam(paramName)
hasParam
Tests whether this instance contains a param with a given (string) name.
isDefined(param)
isDefined
Checks whether a param is explicitly set by user or has a default value.
isSet(param)
isSet
Checks whether a param is explicitly set by user.
set(param, value)
set
Sets a parameter in the embedded param map.
setMaxLocalProjDBSize(value)
setMaxLocalProjDBSize
Sets the value of maxLocalProjDBSize.
maxLocalProjDBSize
setMaxPatternLength(value)
setMaxPatternLength
Sets the value of maxPatternLength.
maxPatternLength
setMinSupport(value)
setMinSupport
Sets the value of minSupport.
minSupport
setParams(self, \*[, minSupport, …])
setParams
setSequenceCol(value)
setSequenceCol
Sets the value of sequenceCol.
sequenceCol
Attributes
params
Returns all params ordered by name.
Methods Documentation
Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java pipeline component with extra params. So both the Python wrapper and the Java pipeline component get copied.
Extra parameters to copy to the new instance
JavaParams
Copy of this instance
extra param values
merged param map
pyspark.sql.DataFrame
A dataframe containing a sequence column which is ArrayType(ArrayType(T)) type, T is the item type for the input dataset.
A DataFrame that contains columns of sequence and corresponding frequency. The schema of it will be:
sequence: ArrayType(ArrayType(T)) (T is the item type)
freq: Long
New in version 3.0.0.
Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.
Attributes Documentation
Returns all params ordered by name. The default implementation uses dir() to get all attributes of type Param.
dir()
Param