forked from dotnet/machinelearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPredictProgram.tt
More file actions
67 lines (63 loc) · 2.67 KB
/
PredictProgram.tt
File metadata and controls
67 lines (63 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<#@ template language="C#" linePragmas="false" visibility="internal" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="Microsoft.ML.CodeGenerator.Utilities" #>
<#@ include file="Annotation.ttinclude" #><#if(Target == CSharp.GenerateTarget.Cli){ #>
<#CLI_Annotation();#>
<# } else if(Target == CSharp.GenerateTarget.ModelBuilder){ #>
<#MB_Annotation();#>
<# } #>
using System;
using <#= Namespace #>.Model;
namespace <#= Namespace #>.ConsoleApp
{
class Program
{
static void Main(string[] args)
{
// Create single instance of sample data from first line of dataset for model input
<# if(SampleData != null) {#>
ModelInput sampleData = new ModelInput()
{
<# foreach(var kv in SampleData){ #>
<#= kv.Key #>=<#= kv.Value #>,
<#}#>
};
<#}else{#>
ModelInput sampleData = new ModelInput();
<#}#>
// Make a single prediction on the sample data and print results
var predictionResult = ConsumeModel.Predict(sampleData);
Console.WriteLine("Using model to make single prediction -- Comparing actual <#= Utils.Normalize(LabelName) #> with predicted <#= Utils.Normalize(LabelName) #> from sample data...\n\n");
<# if(SampleData != null) {#>
<#foreach(var kv in SampleData){#>
Console.WriteLine($"<#= kv.Key #>: {sampleData.<#= kv.Key #>}");
<#}#>
<#}#>
<#if("BinaryClassification".Equals(TaskType) ){ #>
Console.WriteLine($"\n\nPredicted <#= Utils.Normalize(LabelName) #>: {predictionResult.Prediction}\n\n");
<#} else if("Regression".Equals(TaskType) || "Recommendation".Equals(TaskType)){#>
Console.WriteLine($"\n\nPredicted <#= Utils.Normalize(LabelName) #>: {predictionResult.Score}\n\n");
<#} else if("MulticlassClassification".Equals(TaskType)){#>
Console.WriteLine($"\n\nPredicted <#= Utils.Normalize(LabelName) #> value {predictionResult.Prediction} \nPredicted <#= Utils.Normalize(LabelName) #> scores: [{String.Join(",", predictionResult.Score)}]\n\n");
<#} #>
Console.WriteLine("=============== End of process, hit any key to finish ===============");
Console.ReadKey();
}
}
}
<#+
public string TaskType {get;set;}
public string Namespace {get;set;}
public string LabelName {get;set;}
public char Separator {get;set;}
public bool AllowQuoting {get;set;}
public bool AllowSparse {get;set;}
public bool HasHeader {get;set;}
public IList<string> Features {get;set;}
internal CSharp.GenerateTarget Target {get;set;}
public IDictionary<string, string> SampleData {get;set;}
#>