本文简要介绍
pyspark.ml.clustering.PowerIterationClustering
的用法。用法:
class pyspark.ml.clustering.PowerIterationClustering(*, k=2, maxIter=20, initMode='random', srcCol='src', dstCol='dst', weightCol=None)
Power Iteration Clustering (PIC),一种由Lin and Cohen 开发的可扩展图聚类算法。摘要:PIC 使用数据的归一化成对相似性矩阵上的截断幂迭代来找到数据集的极低维嵌入。
该类还不是 Estimator/Transformer,请使用
assignClusters()
方法运行 PowerIterationClustering 算法。2.4.0 版中的新函数。
注意:
见Wikipedia on Spectral clustering
例子:
>>> data = [(1, 0, 0.5), ... (2, 0, 0.5), (2, 1, 0.7), ... (3, 0, 0.5), (3, 1, 0.7), (3, 2, 0.9), ... (4, 0, 0.5), (4, 1, 0.7), (4, 2, 0.9), (4, 3, 1.1), ... (5, 0, 0.5), (5, 1, 0.7), (5, 2, 0.9), (5, 3, 1.1), (5, 4, 1.3)] >>> df = spark.createDataFrame(data).toDF("src", "dst", "weight").repartition(1) >>> pic = PowerIterationClustering(k=2, weightCol="weight") >>> pic.setMaxIter(40) PowerIterationClustering... >>> assignments = pic.assignClusters(df) >>> assignments.sort(assignments.id).show(truncate=False) +---+-------+ |id |cluster| +---+-------+ |0 |0 | |1 |0 | |2 |0 | |3 |0 | |4 |0 | |5 |1 | +---+-------+ ... >>> pic_path = temp_path + "/pic" >>> pic.save(pic_path) >>> pic2 = PowerIterationClustering.load(pic_path) >>> pic2.getK() 2 >>> pic2.getMaxIter() 40 >>> pic2.assignClusters(df).take(6) == assignments.take(6) True
相关用法
- Python pyspark PowerIterationClusteringModel用法及代码示例
- Python pyspark PolynomialExpansion用法及代码示例
- Python pyspark PandasCogroupedOps.applyInPandas用法及代码示例
- Python pyspark PCA用法及代码示例
- Python pyspark PrefixSpanModel用法及代码示例
- Python pyspark PrefixSpan用法及代码示例
- Python pyspark ParamGridBuilder用法及代码示例
- Python pyspark create_map用法及代码示例
- Python pyspark date_add用法及代码示例
- Python pyspark DataFrame.to_latex用法及代码示例
- Python pyspark DataStreamReader.schema用法及代码示例
- Python pyspark MultiIndex.size用法及代码示例
- Python pyspark arrays_overlap用法及代码示例
- Python pyspark Series.asof用法及代码示例
- Python pyspark DataFrame.align用法及代码示例
- Python pyspark Index.is_monotonic_decreasing用法及代码示例
- Python pyspark IsotonicRegression用法及代码示例
- Python pyspark DataFrame.plot.bar用法及代码示例
- Python pyspark DataFrame.to_delta用法及代码示例
- Python pyspark element_at用法及代码示例
- Python pyspark explode用法及代码示例
- Python pyspark MultiIndex.hasnans用法及代码示例
- Python pyspark Series.to_frame用法及代码示例
- Python pyspark DataFrame.quantile用法及代码示例
- Python pyspark Column.withField用法及代码示例
注:本文由纯净天空筛选整理自spark.apache.org大神的英文原创作品 pyspark.ml.clustering.PowerIterationClustering。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。