commit 9fc5fa935116bb7a5edfa51ba9705a2adac920ef
Author: Roman Kalivoda <kalivodaroman@gmail.com>
Date:   Fri Apr 16 00:10:57 2021 +0200

    Draft Predictor
    
    re #8598 @2h

diff --git a/Server/ServerApp.sln b/Server/ServerApp.sln
index 7b80087..0e1c084 100644
--- a/Server/ServerApp.sln
+++ b/Server/ServerApp.sln
@@ -8,13 +8,19 @@ EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
+		Debug|x64 = Debug|x64
 		Release|Any CPU = Release|Any CPU
+		Release|x64 = Release|x64
 	EndGlobalSection
 	GlobalSection(ProjectConfigurationPlatforms) = postSolution
 		{B49B2821-751C-4032-8637-B4E9282DCF06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{B49B2821-751C-4032-8637-B4E9282DCF06}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{B49B2821-751C-4032-8637-B4E9282DCF06}.Debug|x64.ActiveCfg = Debug|x64
+		{B49B2821-751C-4032-8637-B4E9282DCF06}.Debug|x64.Build.0 = Debug|x64
 		{B49B2821-751C-4032-8637-B4E9282DCF06}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{B49B2821-751C-4032-8637-B4E9282DCF06}.Release|Any CPU.Build.0 = Release|Any CPU
+		{B49B2821-751C-4032-8637-B4E9282DCF06}.Release|x64.ActiveCfg = Release|x64
+		{B49B2821-751C-4032-8637-B4E9282DCF06}.Release|x64.Build.0 = Release|x64
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
diff --git a/Server/ServerApp/Predictor/IPredictor.cs b/Server/ServerApp/Predictor/IPredictor.cs
index 8db9f0a..ed7968d 100644
--- a/Server/ServerApp/Predictor/IPredictor.cs
+++ b/Server/ServerApp/Predictor/IPredictor.cs
@@ -11,8 +11,8 @@ namespace ServerApp.Predictor
     interface IPredictor
     {
 
-        void Fit(ModelInput trainInput);
+        void Fit(IEnumerable<ModelInput> trainInput);
 
-        void Predict(ModelInput testInput);
+        ModelOutput Predict(IEnumerable<ModelInput> input);
     }
 }
diff --git a/Server/ServerApp/Predictor/ModelInput.cs b/Server/ServerApp/Predictor/ModelInput.cs
index d281b40..fcb2e69 100644
--- a/Server/ServerApp/Predictor/ModelInput.cs
+++ b/Server/ServerApp/Predictor/ModelInput.cs
@@ -1,12 +1,20 @@
-﻿namespace ServerApp.Predictor
+﻿using Microsoft.ML.Data;
+
+namespace ServerApp.Predictor
 {
     public class ModelInput
     {
-        protected class DataPoint
-        {
-            public uint Label { get; set; }
+        [ColumnName("label"), LoadColumn(0)]
+        public string LabelCol { get; set; }
+
+
+        [ColumnName("temp"), LoadColumn(1)]
+        public double Col1 { get; set; }
+
+        //[ColumnName("date"), LoadColumn(2)]
+        //public string Col2 { get; set; }
 
-            public float[] Features { get; set; }
-        }
+        //[ColumnName("time"), LoadColumn(3)]
+        //public string Col3 { get; set; }
     }
 }
\ No newline at end of file
diff --git a/Server/ServerApp/Predictor/ModelOutput.cs b/Server/ServerApp/Predictor/ModelOutput.cs
new file mode 100644
index 0000000..83983cd
--- /dev/null
+++ b/Server/ServerApp/Predictor/ModelOutput.cs
@@ -0,0 +1,13 @@
+﻿using System;
+using Microsoft.ML.Data;
+
+namespace ServerApp.Predictor
+{
+    public class ModelOutput
+    {
+        [ColumnName("PredictedLabel")]
+        public String Prediction { get; set; }
+        public float[] Score { get; set; }
+
+    }
+}
diff --git a/Server/ServerApp/Predictor/NaiveBayesClassifier.cs b/Server/ServerApp/Predictor/NaiveBayesClassifier.cs
index 218ca58..60ff81e 100644
--- a/Server/ServerApp/Predictor/NaiveBayesClassifier.cs
+++ b/Server/ServerApp/Predictor/NaiveBayesClassifier.cs
@@ -4,6 +4,8 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using Microsoft.ML;
+using Microsoft.ML.Data;
+using ServerApp.Parser.OutputInfo;
 
 namespace ServerApp.Predictor
 {
@@ -11,20 +13,41 @@ namespace ServerApp.Predictor
     {
         private MLContext mlContext;
 
+        private ITransformer model;
+
         public NaiveBayesClassifier()
         {
             mlContext = new MLContext();
 
         }
 
-        public void Fit(ModelInput trainingData)
+        public IEnumerable<ModelInput> ExtractModelInput(List<WeatherInfo> weatherInfos, List<ActivityInfo> activityInfos)
+        {
+            return weatherInfos.Select(e => new ModelInput(){
+                Col1 = e.temp,
+                LabelCol = "Empty",
+            }).ToList();
+        }
+
+        public void Fit(IEnumerable<ModelInput> trainingData)
         {
-            throw new NotImplementedException();
+            IDataView trainingDataView = mlContext.Data.LoadFromEnumerable(trainingData);
+            var dataProcessPipeline = mlContext.Transforms.Conversion.MapValueToKey("label", "label")
+                .Append(mlContext.Transforms.CopyColumns("Features", "temp"))
+                .Append(mlContext.Transforms.NormalizeMinMax("Features", "Features"));
+            var trainer = mlContext.MulticlassClassification.Trainers.NaiveBayes();
+            var traininingPipeline = dataProcessPipeline.Append(trainer);
+
+            this.model = traininingPipeline.Fit(trainingDataView);
+
         }
 
-        public void Predict(ModelInput testData)
+        public ModelOutput Predict(IEnumerable<ModelInput> input)
         {
-            throw new NotImplementedException();
+            var data = mlContext.Data.LoadFromEnumerable(input);
+            var prediction = model.Transform(data);
+            var result = mlContext.Data.CreateEnumerable<ModelOutput>(prediction, reuseRowObject: false);
+            return (ModelOutput)result;
         }
     }
 }
diff --git a/Server/ServerApp/Program.cs b/Server/ServerApp/Program.cs
index ec09327..13c2ac8 100644
--- a/Server/ServerApp/Program.cs
+++ b/Server/ServerApp/Program.cs
@@ -1,5 +1,7 @@
 ﻿using ServerApp.Parser.Parsers;
+using ServerApp.Predictor;
 using System;
+using System.Collections.Generic;
 
 namespace ServerApp
 {
@@ -11,6 +13,19 @@ namespace ServerApp
 
             p.Parse();
 
+            NaiveBayesClassifier naiveBayesClassifier = new NaiveBayesClassifier();
+            IEnumerable<ModelInput> modelInput = naiveBayesClassifier.ExtractModelInput(p.weatherList, p.jisList);
+            naiveBayesClassifier.Fit(modelInput);
+            var testData = new ModelInput()
+            {
+                Col1 = -40,
+            };
+            List<ModelInput> dataList = new List<ModelInput>();
+            dataList.Add(testData);
+            var result = naiveBayesClassifier.Predict(dataList);
+
+            Console.WriteLine($"Prediction: {result.Prediction}");
+
             Console.ReadLine();
         }
     }
diff --git a/Server/ServerApp/ServerApp.csproj b/Server/ServerApp/ServerApp.csproj
index 32aab27..a37967d 100644
--- a/Server/ServerApp/ServerApp.csproj
+++ b/Server/ServerApp/ServerApp.csproj
@@ -1,5 +1,7 @@
 ﻿<?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="..\packages\Microsoft.ML.1.5.5\build\netstandard2.0\Microsoft.ML.props" Condition="Exists('..\packages\Microsoft.ML.1.5.5\build\netstandard2.0\Microsoft.ML.props')" />
+  <Import Project="..\packages\Microsoft.ML.CpuMath.1.5.5\build\netstandard2.0\Microsoft.ML.CpuMath.props" Condition="Exists('..\packages\Microsoft.ML.CpuMath.1.5.5\build\netstandard2.0\Microsoft.ML.CpuMath.props')" />
   <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -12,6 +14,8 @@
     <FileAlignment>512</FileAlignment>
     <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
     <Deterministic>true</Deterministic>
+    <NuGetPackageImportStamp>
+    </NuGetPackageImportStamp>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <PlatformTarget>AnyCPU</PlatformTarget>
@@ -32,7 +36,58 @@
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>bin\x64\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <LangVersion>7.3</LangVersion>
+    <ErrorReport>prompt</ErrorReport>
+    <Prefer32Bit>true</Prefer32Bit>
+	<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
+    <OutputPath>bin\x64\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <LangVersion>7.3</LangVersion>
+    <ErrorReport>prompt</ErrorReport>
+    <Prefer32Bit>true</Prefer32Bit>
+  </PropertyGroup>
   <ItemGroup>
+    <Reference Include="Microsoft.ML, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.ML.1.5.5\lib\netstandard2.0\Microsoft.ML.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.ML.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.ML.1.5.5\lib\netstandard2.0\Microsoft.ML.Core.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.ML.CpuMath, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.ML.CpuMath.1.5.5\lib\netstandard2.0\Microsoft.ML.CpuMath.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.ML.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.ML.1.5.5\lib\netstandard2.0\Microsoft.ML.Data.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.ML.DataView, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.ML.DataView.1.5.5\lib\netstandard2.0\Microsoft.ML.DataView.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.ML.KMeansClustering, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.ML.1.5.5\lib\netstandard2.0\Microsoft.ML.KMeansClustering.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.ML.PCA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.ML.1.5.5\lib\netstandard2.0\Microsoft.ML.PCA.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.ML.StandardTrainers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.ML.1.5.5\lib\netstandard2.0\Microsoft.ML.StandardTrainers.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.ML.Transforms, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.ML.1.5.5\lib\netstandard2.0\Microsoft.ML.Transforms.dll</HintPath>
+    </Reference>
+    <Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+      <HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
     <Reference Include="System.Xml.Linq" />
@@ -45,8 +100,8 @@
   <ItemGroup>
     <Compile Include="Predictor\IPredictor.cs" />
     <Compile Include="Predictor\ModelInput.cs" />
+    <Compile Include="Predictor\ModelOutput.cs" />
     <Compile Include="Predictor\NaiveBayesClassifier.cs" />
-    <Compile Include="obj\Debug\.NETFramework,Version=v4.7.2.AssemblyAttributes.cs" />
     <Compile Include="Parser\InputData\CsvDataLoader.cs" />
     <Compile Include="Parser\InputData\JisInstance.cs" />
     <Compile Include="Parser\InputData\LogInInstance.cs" />
@@ -118,13 +173,17 @@
     <None Include="data\weather\OD_ZCU_POCASI_12_2019.CSV">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>
-    <None Include="obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache" />
-    <None Include="obj\Debug\ServerApp.csprojAssemblyReference.cache" />
-  </ItemGroup>
-  <ItemGroup>
-    <Folder Include="bin\Debug\" />
-    <Folder Include="bin\Release\" />
-    <Folder Include="obj\Debug\TempPE\" />
+    <None Include="packages.config" />
   </ItemGroup>
+  <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+    <PropertyGroup>
+      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
+    </PropertyGroup>
+    <Error Condition="!Exists('..\packages\Microsoft.ML.CpuMath.1.5.5\build\netstandard2.0\Microsoft.ML.CpuMath.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.ML.CpuMath.1.5.5\build\netstandard2.0\Microsoft.ML.CpuMath.props'))" />
+    <Error Condition="!Exists('..\packages\Microsoft.ML.1.5.5\build\netstandard2.0\Microsoft.ML.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.ML.1.5.5\build\netstandard2.0\Microsoft.ML.props'))" />
+    <Error Condition="!Exists('..\packages\Microsoft.ML.1.5.5\build\netstandard2.0\Microsoft.ML.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.ML.1.5.5\build\netstandard2.0\Microsoft.ML.targets'))" />
+  </Target>
+  <Import Project="..\packages\Microsoft.ML.1.5.5\build\netstandard2.0\Microsoft.ML.targets" Condition="Exists('..\packages\Microsoft.ML.1.5.5\build\netstandard2.0\Microsoft.ML.targets')" />
 </Project>
\ No newline at end of file
