1 |
4977ce53
|
Roman Kalivoda
|
//
|
2 |
|
|
// Author: Roman Kalivoda
|
3 |
|
|
//
|
4 |
|
|
|
5 |
|
|
using System;
|
6 |
abfd9c7c
|
Roman Kalivoda
|
using System.Collections.Generic;
|
7 |
|
|
using System.Linq;
|
8 |
|
|
using System.Text;
|
9 |
|
|
using System.Threading.Tasks;
|
10 |
|
|
using Microsoft.ML;
|
11 |
|
|
using Microsoft.ML.Data;
|
12 |
|
|
|
13 |
4977ce53
|
Roman Kalivoda
|
|
14 |
abfd9c7c
|
Roman Kalivoda
|
namespace ServerApp.Predictor
|
15 |
|
|
{
|
16 |
4977ce53
|
Roman Kalivoda
|
/// <summary>
|
17 |
|
|
/// A predictor interface.
|
18 |
|
|
/// </summary>
|
19 |
ebe96ca4
|
Roman Kalivoda
|
public interface IPredictor
|
20 |
abfd9c7c
|
Roman Kalivoda
|
{
|
21 |
4977ce53
|
Roman Kalivoda
|
/// <summary>
|
22 |
|
|
/// Trains the predictor with the given training data input.
|
23 |
|
|
/// </summary>
|
24 |
|
|
/// <param name="trainInput">A collection of <c>ModelInput</c> instances. The objects contain both feature vector inputs and corresponding labels.</param>
|
25 |
9fc5fa93
|
Roman Kalivoda
|
void Fit(IEnumerable<ModelInput> trainInput);
|
26 |
abfd9c7c
|
Roman Kalivoda
|
|
27 |
4977ce53
|
Roman Kalivoda
|
/// <summary>
|
28 |
d358b79e
|
Roman Kalivoda
|
/// Predicts class to the given feature vector.
|
29 |
4977ce53
|
Roman Kalivoda
|
/// </summary>
|
30 |
d358b79e
|
Roman Kalivoda
|
/// <param name="input">A feature vector in <c>ModelInput</c> instance.</param>
|
31 |
|
|
/// <returns>A predicted label.</returns>
|
32 |
|
|
string Predict(ModelInput input);
|
33 |
|
|
|
34 |
|
|
/// <summary>
|
35 |
|
|
/// Evaluates the model on <paramref name="modelInputs"/> and prints metrics to console.
|
36 |
|
|
/// </summary>
|
37 |
|
|
/// <param name="modelInputs">Input data used to evaluate the predictor.</param>
|
38 |
|
|
void Evaluate(IEnumerable<ModelInput> modelInputs);
|
39 |
662b2404
|
Roman Kalivoda
|
|
40 |
3c4b53fe
|
Roman Kalivoda
|
/// <summary>
|
41 |
|
|
/// Saves the trained model under given filename.
|
42 |
|
|
/// </summary>
|
43 |
|
|
/// <param name="filename">Path of the file.</param>
|
44 |
|
|
public void Save(string filename);
|
45 |
76072df0
|
Roman Kalivoda
|
|
46 |
|
|
/// <summary>
|
47 |
|
|
/// Loads an IPredictor model from file
|
48 |
|
|
/// </summary>
|
49 |
|
|
/// <param name="filename">Path to the model file.</param>
|
50 |
|
|
/// <returns>A prediction model.</returns>
|
51 |
|
|
public void Load(string filename);
|
52 |
abfd9c7c
|
Roman Kalivoda
|
}
|
53 |
|
|
}
|