Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 66c3e0df

Přidáno uživatelem Roman Kalivoda před více než 3 roky(ů)

re #8598

Update Server/ServerApp/ServerApp.csproj
fixed corrupted dependencies
working simple classification

Zobrazit rozdíly:

Server/ServerApp/Predictor/NaiveBayesClassifier.cs
24 24
        public IEnumerable<ModelInput> ExtractModelInput(List<WeatherInfo> weatherInfos, List<ActivityInfo> activityInfos)
25 25
        {
26 26
            return weatherInfos.Select(e => new ModelInput(){
27
                Col1 = e.temp,
28
                LabelCol = "Empty",
27
                Temp = (float)e.temp,
28
                Label = e.temp > 15.0 ? "Full" : "Empty",
29 29
            }).ToList();
30 30
        }
31 31

  
32 32
        public void Fit(IEnumerable<ModelInput> trainingData)
33 33
        {
34 34
            IDataView trainingDataView = mlContext.Data.LoadFromEnumerable(trainingData);
35
            var dataProcessPipeline = mlContext.Transforms.Conversion.MapValueToKey("label", "label")
36
                .Append(mlContext.Transforms.CopyColumns("Features", "temp"))
37
                .Append(mlContext.Transforms.NormalizeMinMax("Features", "Features"));
35
            var dataProcessPipeline = mlContext.Transforms.Conversion.MapValueToKey(nameof(ModelInput.Label))
36
                .Append(mlContext.Transforms.Concatenate("Features", new[] { "temp" })
37
                .Append(mlContext.Transforms.NormalizeMinMax("Features", "Features")));
38 38
            var trainer = mlContext.MulticlassClassification.Trainers.NaiveBayes();
39
            var traininingPipeline = dataProcessPipeline.Append(trainer);
39
            var traininingPipeline = dataProcessPipeline.Append(trainer)
40
                .Append(mlContext.Transforms.Conversion.MapKeyToValue("prediction", "PredictedLabel"));
40 41

  
41 42
            this.model = traininingPipeline.Fit(trainingDataView);
42 43

  
43 44
        }
44 45

  
45
        public ModelOutput Predict(IEnumerable<ModelInput> input)
46
        public String[] Predict(IEnumerable<ModelInput> input)
46 47
        {
47 48
            var data = mlContext.Data.LoadFromEnumerable(input);
48
            var prediction = model.Transform(data);
49
            var result = mlContext.Data.CreateEnumerable<ModelOutput>(prediction, reuseRowObject: false);
50
            return (ModelOutput)result;
49
            IDataView result = model.Transform(data);
50
            String[] prediction = result.GetColumn<String>("prediction").ToArray();
51

  
52
            return prediction;
51 53
        }
52 54
    }
53 55
}

Také k dispozici: Unified diff