Java 类名:com.alibaba.alink.pipeline.clustering.GaussianMixture
Python 类名:GaussianMixture

功能介绍

高斯混合模型聚类

参数说明

名称 中文名称 描述 类型 是否必须? 取值范围 默认值
predictionCol 预测结果列名 预测结果列名 String
vectorCol 向量列名 向量列对应的列名 String
epsilon 收敛阈值 当两轮迭代的中心点距离小于epsilon时,算法收敛。 Double 1.0E-4
k 聚类中心点数量 聚类中心点数量 Integer 2
maxIter 最大迭代步数 最大迭代步数,默认为 100 Integer [1, +inf) 100
modelFilePath 模型的文件路径 模型的文件路径 String null
overwriteSink 是否覆写已有数据 是否覆写已有数据 Boolean false
predictionDetailCol 预测详细信息列名 预测详细信息列名 String
randomSeed 随机数种子 随机数种子 Integer 0
reservedCols 算法保留列名 算法保留列 String[] null
numThreads 组件多线程线程个数 组件多线程线程个数 Integer 1
modelStreamFilePath 模型流的文件路径 模型流的文件路径 String null
modelStreamScanInterval 扫描模型路径的时间间隔 描模型路径的时间间隔,单位秒 Integer 10
modelStreamStartTime 模型流的起始时间 模型流的起始时间。默认从当前时刻开始读。使用yyyy-mm-dd hh:mm:ss.fffffffff格式,详见Timestamp.valueOf(String s) String null

代码示例

Python 代码

  1. from pyalink.alink import *
  2. import pandas as pd
  3. useLocalEnv(1)
  4. df = pd.DataFrame([
  5. ["-0.6264538 0.1836433"],
  6. ["-0.8356286 1.5952808"],
  7. ["0.3295078 -0.8204684"],
  8. ["0.4874291 0.7383247"],
  9. ["0.5757814 -0.3053884"],
  10. ["1.5117812 0.3898432"],
  11. ["-0.6212406 -2.2146999"],
  12. ["11.1249309 9.9550664"],
  13. ["9.9838097 10.9438362"],
  14. ["10.8212212 10.5939013"],
  15. ["10.9189774 10.7821363"],
  16. ["10.0745650 8.0106483"],
  17. ["10.6198257 9.9438713"],
  18. ["9.8442045 8.5292476"],
  19. ["9.5218499 10.4179416"],
  20. ])
  21. data = BatchOperator.fromDataframe(df, schemaStr='features string')
  22. gmm = GaussianMixture() \
  23. .setPredictionCol("cluster_id") \
  24. .setVectorCol("features") \
  25. .setPredictionDetailCol("cluster_detail") \
  26. .setEpsilon(0.)
  27. gmm.fit(data).transform(data).print()

Java 代码

  1. import org.apache.flink.types.Row;
  2. import com.alibaba.alink.operator.batch.BatchOperator;
  3. import com.alibaba.alink.operator.batch.source.MemSourceBatchOp;
  4. import com.alibaba.alink.pipeline.clustering.GaussianMixture;
  5. import org.junit.Test;
  6. import java.util.Arrays;
  7. import java.util.List;
  8. public class GaussianMixtureTest {
  9. @Test
  10. public void testGaussianMixture() throws Exception {
  11. List <Row> df_data = Arrays.asList(
  12. Row.of("-0.6264538 0.1836433"),
  13. Row.of("-0.8356286 1.5952808"),
  14. Row.of("0.3295078 -0.8204684"),
  15. Row.of("0.4874291 0.7383247"),
  16. Row.of("0.5757814 -0.3053884"),
  17. Row.of("1.5117812 0.3898432"),
  18. Row.of("-0.6212406 -2.2146999"),
  19. Row.of("11.1249309 9.9550664"),
  20. Row.of("9.9838097 10.9438362"),
  21. Row.of("10.8212212 10.5939013"),
  22. Row.of("10.9189774 10.7821363"),
  23. Row.of("10.0745650 8.0106483"),
  24. Row.of("10.6198257 9.9438713"),
  25. Row.of("9.8442045 8.5292476"),
  26. Row.of("9.5218499 10.4179416")
  27. );
  28. BatchOperator <?> data = new MemSourceBatchOp(df_data, "features string");
  29. GaussianMixture gmm = new GaussianMixture()
  30. .setPredictionCol("cluster_id")
  31. .setVectorCol("features")
  32. .setPredictionDetailCol("cluster_detail")
  33. .setEpsilon(0.);
  34. gmm.fit(data).transform(data).print();
  35. }
  36. }

运行结果

features cluster_id cluster_detail
-0.6264538 0.1836433 0 1.0 4.275273913968281E-92
-0.8356286 1.5952808 0 1.0 1.0260377730239899E-92
0.3295078 -0.8204684 0 1.0 1.0970173367545207E-80
0.4874291 0.7383247 0 1.0 3.302173132311E-75
0.5757814 -0.3053884 0 1.0 3.1638113605165424E-76
1.5117812 0.3898432 0 1.0 2.101805230873172E-62
-0.6212406 -2.2146999 0 1.0 6.772270268600749E-97
11.1249309 9.9550664 1 3.156783801247968E-56 1.0
9.9838097 10.9438362 1 1.9024447346702425E-51 1.0
10.8212212 10.5939013 1 2.800973098729604E-56 1.0
10.9189774 10.7821363 1 1.7209132744891298E-57 1.0
10.0745650 8.0106483 1 2.8642696635130495E-43 1.0
10.6198257 9.9438713 1 5.773273991940433E-53 1.0
9.8442045 8.5292476 1 2.5273123050925483E-43 1.0
9.5218499 10.4179416 1 1.7314580596767853E-46 1.0