public void PredictCustomerClusters()
        {
            //var data = _mlContext.Data.LoadFromTextFile(path: _pivotDataLocation,
            //                columns: new[]
            //                            {
            //                              new TextLoader.Column("Features", DataKind.Single, new[] {new TextLoader.Range(0, 31) }),
            //                              new TextLoader.Column(nameof(PivotData.LastName), DataKind.String, 32)
            //                            },
            //                hasHeader: true,
            //                separatorChar: ',');


            var predEngine = _mlContext.Model.CreatePredictionEngine <ModelInput, ClusteringPrediction>(_trainedModel);

            //Load sample data for prediction
            var data = new ModelInput
            {
                Features = new float[] { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                LastName = "Mera"
            };

            // Try model on sample data
            ClusteringPrediction        result     = predEngine.Predict(data);
            List <ClusteringPrediction> enumResult = new List <ClusteringPrediction>
            {
                result
            };

            Console.WriteLine($"\nCustomer: {data.LastName} | Prediction: {result.SelectedClusterId} cluster");
            Console.WriteLine($"Location X: {result.Location[0].ToString()} | Location Y: {result.Location[1].ToString()} ");

            SaveCustomerSegmentationPlotChartSingle(enumResult.ToArray(), "customerSegmentation2.svg");
            OpenChartInDefaultWindow("customerSegmentation2.svg");
        }
示例#2
0
 internal static Candidate FromPrediction(ClusteringPrediction cp)
 {
     return(new Candidate
     {
         UserId = cp.UserId,
         Score = cp.Distance[cp.SelectedClusterId]
     });
 }