@Test public void transformPredictDataToTrainDataTest() { KMeansPredictModelData predictModelData = new KMeansModelDataConverter().load(modelRows); Assert.assertEquals(predictModelData.params.k, 2); Assert.assertEquals(predictModelData.params.vectorSize, 3); Assert.assertEquals(predictModelData.params.vectorColName, "Y"); Assert.assertNull(predictModelData.params.longtitudeColName); Assert.assertNull(predictModelData.params.latitudeColName); Assert.assertEquals(predictModelData.params.distanceType, HasKMeansWithHaversineDistanceType.DistanceType.EUCLIDEAN); Assert.assertEquals(predictModelData.centroids.getVectors(), new DenseMatrix(3, 2, new double[]{9.1, 9.1, 9.1, 0.1, 0.1, 0.1})); }
public static KMeansTrainModelData transformPredictDataToTrainData(KMeansPredictModelData predictModelData) { KMeansTrainModelData modelData = new KMeansTrainModelData(); modelData.params = predictModelData.params; modelData.centroids = new ArrayList<>(); for (int i = 0; i < predictModelData.params.k; i++) { KMeansTrainModelData.ClusterSummary clusterSummary = new KMeansTrainModelData.ClusterSummary( predictModelData.getClusterVector(i), predictModelData.getClusterId(i), predictModelData.getClusterWeight(i)); modelData.centroids.add(clusterSummary); } return modelData; }
KMeansUtil implements Serializable { public static KMeansTrainModelData transformPredictDataToTrainData(KMeansPredictModelData predictModelData) { KMeansTrainModelData modelData = new KMeansTrainModelData(); modelData.params = predictModelData.params; modelData.centroids = new ArrayList<>(); for (int i = 0; i < predictModelData.params.k; i++) { KMeansTrainModelData.ClusterSummary clusterSummary = new KMeansTrainModelData.ClusterSummary( predictModelData.getClusterVector(i), predictModelData.getClusterId(i), predictModelData.getClusterWeight(i)); modelData.centroids.add(clusterSummary); } return modelData; } }
KMeansUtil implements Serializable { public static KMeansTrainModelData transformPredictDataToTrainData(KMeansPredictModelData predictModelData) { KMeansTrainModelData modelData = new KMeansTrainModelData(); modelData.params = predictModelData.params; modelData.centroids = new ArrayList<>(); for (int i = 0; i < predictModelData.params.k; i++) { KMeansTrainModelData.ClusterSummary clusterSummary = new KMeansTrainModelData.ClusterSummary( predictModelData.getClusterVector(i), predictModelData.getClusterId(i), predictModelData.getClusterWeight(i)); modelData.centroids.add(clusterSummary); } return modelData; }  }
KMeansUtil implements Serializable { public static KMeansTrainModelData transformPredictDataToTrainData(KMeansPredictModelData predictModelData) { KMeansTrainModelData modelData = new KMeansTrainModelData(); modelData.params = predictModelData.params; modelData.centroids = new ArrayList<>(); for (int i = 0; i < predictModelData.params.k; i++) { KMeansTrainModelData.ClusterSummary clusterSummary = new KMeansTrainModelData.ClusterSummary( predictModelData.getClusterVector(i), predictModelData.getClusterId(i), predictModelData.getClusterWeight(i)); modelData.centroids.add(clusterSummary); } return modelData; }  static FastDistanceMatrixData buildCentroidsMatrix(List<FastDistanceVectorData> vectors,
                                                              FastDistance distance,
                                                              int vectorSize); static int updateSumMatrix(FastDistanceVectorData sample,
                                      long sampleWeight,
                                      FastDistanceMatrixData centroids,
                                      int vectorSize,
                                      double[] sumMatrix,
                                      int k,
                                      FastDistance fastDistance,
                                      DenseMatrix distanceMatrix); static Tuple2<Integer, Double> getClosestClusterIndex(FastDistanceVectorData sample,
                                                                 FastDistanceMatrixData centroids,
                                                                 int k,
                                                                 FastDistance distance,
                                                                 DenseMatrix distanceMatrix); static double[] getClusterDistances(FastDistanceVectorData sample,
                                               FastDistanceMatrixData centroids,
                                               FastDistance distance,
                                               DenseMatrix distanceMatrix); static Tuple2<Integer, Double> getClosestClusterIndex(KMeansTrainModelData trainModelData,
                                                                 Vector sample,
                                                                 ContinuousDistance distance); static double[] getClusterDistances(KMeansTrainModelData trainModelData,
                                               Vector sample,
                                               ContinuousDistance distance); static int getMinPointIndex(double[] data, int endIndex); static int[] getKmeansPredictColIdxs(KMeansTrainModelData.ParamSummary params, String[] dataCols); static Vector getKMeansPredictVector(int[] colIdxs, Row row); static KMeansTrainModelData transformPredictDataToTrainData(KMeansPredictModelData predictModelData); static KMeansPredictModelData transformTrainDataToPredictData(KMeansTrainModelData trainModelData); static double[] getProbArrayFromDistanceArray(double[] distances); static KMeansTrainModelData loadModelForTrain(Params params, Iterable<String> data); }
KMeansUtil implements Serializable { public static KMeansTrainModelData transformPredictDataToTrainData(KMeansPredictModelData predictModelData) { KMeansTrainModelData modelData = new KMeansTrainModelData(); modelData.params = predictModelData.params; modelData.centroids = new ArrayList<>(); for (int i = 0; i < predictModelData.params.k; i++) { KMeansTrainModelData.ClusterSummary clusterSummary = new KMeansTrainModelData.ClusterSummary( predictModelData.getClusterVector(i), predictModelData.getClusterId(i), predictModelData.getClusterWeight(i)); modelData.centroids.add(clusterSummary); } return modelData; }  static FastDistanceMatrixData buildCentroidsMatrix(List<FastDistanceVectorData> vectors,
                                                              FastDistance distance,
                                                              int vectorSize); static int updateSumMatrix(FastDistanceVectorData sample,
                                      long sampleWeight,
                                      FastDistanceMatrixData centroids,
                                      int vectorSize,
                                      double[] sumMatrix,
                                      int k,
                                      FastDistance fastDistance,
                                      DenseMatrix distanceMatrix); static Tuple2<Integer, Double> getClosestClusterIndex(FastDistanceVectorData sample,
                                                                 FastDistanceMatrixData centroids,
                                                                 int k,
                                                                 FastDistance distance,
                                                                 DenseMatrix distanceMatrix); static double[] getClusterDistances(FastDistanceVectorData sample,
                                               FastDistanceMatrixData centroids,
                                               FastDistance distance,
                                               DenseMatrix distanceMatrix); static Tuple2<Integer, Double> getClosestClusterIndex(KMeansTrainModelData trainModelData,
                                                                 Vector sample,
                                                                 ContinuousDistance distance); static double[] getClusterDistances(KMeansTrainModelData trainModelData,
                                               Vector sample,
                                               ContinuousDistance distance); static int getMinPointIndex(double[] data, int endIndex); static int[] getKmeansPredictColIdxs(KMeansTrainModelData.ParamSummary params, String[] dataCols); static Vector getKMeansPredictVector(int[] colIdxs, Row row); static KMeansTrainModelData transformPredictDataToTrainData(KMeansPredictModelData predictModelData); static KMeansPredictModelData transformTrainDataToPredictData(KMeansTrainModelData trainModelData); static double[] getProbArrayFromDistanceArray(double[] distances); static KMeansTrainModelData loadModelForTrain(Params params, Iterable<String> data);  }