-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPriceForecastModel.consumption.cs
More file actions
71 lines (57 loc) · 2.15 KB
/
PriceForecastModel.consumption.cs
File metadata and controls
71 lines (57 loc) · 2.15 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
68
69
70
// This file was auto-generated by ML.NET Model Builder.
using Microsoft.ML;
using Microsoft.ML.Data;
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using Microsoft.ML.Transforms.TimeSeries;
namespace NodeBlock_Plugin_MachineLearning
{
public partial class PriceForecastModel
{
/// <summary>
/// model input class for PriceForecastModel.
/// </summary>
#region model input class
public class ModelInput
{
[LoadColumn(0)]
[ColumnName(@"Price")]
public float Price { get; set; }
}
#endregion
/// <summary>
/// model output class for PriceForecastModel.
/// </summary>
#region model output class
public class ModelOutput
{
[ColumnName(@"Price")]
public float[] Price { get; set; }
[ColumnName(@"Price_LB")]
public float[] Price_LB { get; set; }
[ColumnName(@"Price_UB")]
public float[] Price_UB { get; set; }
}
#endregion
private static string MLNetModelPath = Path.GetFullPath("PriceForecastModel.zip");
public static readonly Lazy<TimeSeriesPredictionEngine<ModelInput, ModelOutput>> PredictEngine = new Lazy<TimeSeriesPredictionEngine<ModelInput, ModelOutput>>(() => CreatePredictEngine(), true);
/// <summary>
/// Use this method to predict on <see cref="ModelInput"/>.
/// </summary>
/// <param name="input">model input.</param>
/// <returns><seealso cref=" ModelOutput"/></returns>
public static ModelOutput Predict(ModelInput? input = null, int? horizon = null)
{
var predEngine = PredictEngine.Value;
return predEngine.Predict(input, horizon);
}
private static TimeSeriesPredictionEngine<ModelInput, ModelOutput> CreatePredictEngine()
{
var mlContext = new MLContext();
ITransformer mlModel = mlContext.Model.Load(MLNetModelPath, out var schema);
return mlModel.CreateTimeSeriesEngine<ModelInput, ModelOutput>(mlContext);
}
}
}