Buenas!
No puedo esperar a empezar a escribir un poco mas al respecto sobre ML.Net. Por ahora solo un par de code snippets para demostrar lo simple y rápido que puede ser
Comenzando con un set de datos con edades para clasificar babies y kids, en un archivo CSV. Todo basado en mi criterio personal
0 | 3 | baby | |
---|---|---|---|
1 | 3 | baby | |
3 | 3 | baby | |
4 | 6 | kid | |
6 | 8 | kid | |
5 | 9 | kid | |
6 | 10 | kid | |
9 | 10 | kid |
Y ahora un poco de magia con ML. Una aplicación de Consola en donde creamos un LEarningPipeline y lo entrenamos con la información de CSV
using System; | |
using Microsoft.ML; | |
using Microsoft.ML.Runtime.Api; | |
using Microsoft.ML.Trainers; | |
using Microsoft.ML.Transforms; | |
namespace MlNetConsole01 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var agesRangesCsv = "AgeRangeData.csv"; | |
var pipeline = new LearningPipeline | |
{ | |
new TextLoader<AgeRangeData>(agesRangesCsv, separator: ","), | |
new Dictionarizer("Label"), | |
new ColumnConcatenator("Features", "AgeStart", "AgeEnd"), | |
new StochasticDualCoordinateAscentClassifier(), | |
new PredictedLabelColumnOriginalValueConverter {PredictedLabelColumn = "PredictedLabel"} | |
}; | |
var model = pipeline.Train<AgeRangeData, AgeRangePrediction>(); | |
var prediction = model.Predict(new AgeRangeData() | |
{ | |
AgeStart = 1, | |
AgeEnd = 2 | |
}); | |
Console.WriteLine($"Predicted age range is: {prediction.PredictedLabels}"); | |
prediction = model.Predict(new AgeRangeData() | |
{ | |
AgeStart = 7, | |
AgeEnd = 7 | |
}); | |
Console.WriteLine($"Predicted age range is: {prediction.PredictedLabels}"); | |
Console.ReadLine(); | |
} | |
} | |
public class AgeRangeData | |
{ | |
[Column(ordinal: "0")] | |
public float AgeStart; | |
[Column(ordinal: "1")] | |
public float AgeEnd; | |
[Column(ordinal: "2", name: "Label")] | |
public string Label; | |
} | |
public class AgeRangePrediction | |
{ | |
[ColumnName("PredictedLabel")] | |
public string PredictedLabels; | |
} | |
} |
A continuación verificamos un par de predicciones con Age Ranges que no son parte del CSV original
Happy coding!
Saludos @ Burlington
El Bruno
References