Buenas!
El cambio en la forma en la que las Pipelines trabajan en la version 0.6.0 de Machine Learning.Net, también requiere que el código se modifique un poco si queremos ver como se procesan los datos durante cada uno de los pasos de la Pipeline.
Retomando el ejemplo del post anterior, voy a trabajar con la siguiente estructura de datos.
En la línea 21, créate una vista temporal de datos con el siguiente código
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
var dataPath = "AgeRangeData.csv"; | |
var env = new LocalEnvironment(); | |
var reader = TextLoader.CreateReader(env, ctx => ( | |
Name: ctx.LoadText(0), | |
Age: ctx.LoadFloat(1), | |
Gender: ctx.LoadText(2), | |
Label: ctx.LoadText(3)), | |
separator: ',', hasHeader: true); | |
var trainData = reader.Read(new MultiFileSource(dataPath)); | |
var classification = new MulticlassClassificationContext(env); | |
var learningPipeline = reader.MakeNewEstimator() | |
.Append(r => ( | |
r.Label, | |
Predictions: classification.Trainers.Sdca | |
(label: r.Label.ToKey(), | |
features: r.Age.AsVector()))); | |
// create temp view of data | |
var data = reader.Read(new MultiFileSource(dataPath)); | |
var tempData = learningPipeline.Fit(data).Transform(data); | |
var tempRows = tempData.AsDynamic | |
.AsEnumerable<AgeRange>(env, reuseRowObject: false).ToArray(); | |
learningPipeline.Append(r => r.Predictions.predictedLabel.ToValue()); |
que me permitirá analizar los mismos directamente en el IDE en modo de depuración, o inclusive guardarlos en archivos temporales para estudiar los mismos
Esto puede ser suficiente, sin embargo, al trabajar con una clase tipada con los 4 campos de mi set de datos, estoy obligando a mi App a cargar y mapear todos los datos en cada columna. En este ejemplo, el modelo generado permite generar una predicción del Label a partir del campo Age. De esta forma, podemos obviar la definición de las columnas Name y Gender en la carga.
Eso sí, nos encontraremos con el siguiente error
System.InvalidOperationException
HResult=0x80131509
Message=Column ‘Name’ not found in the data view
Source=Microsoft.ML.Api
Ya que, por defecto, la carga de datos intenta mapear todas las columnas. La solución es habilitar la opción para ignorar las columnas faltantes, como muestra el siguiente ejemplo.
Finalmente, si trabajamos con muchos datos, también podemos sacar provecho de Linq para solo analizar un subgrupo de filas
Happy coding!
Saludos @ Toronto
El Bruno
References
My Posts
- API improvements in the new 0.6.0 version
- Fix the error [System. InvalidOperationException, Entry Point ‘ Not found] when you train a pipeline
- Adding NuGet Packages in Preview mode from MyGet, ie: Microsoft.ML-0.6.0 Version
- ML.Net 0.5 initial support for TensorFlow
- New version 0.4, news Improvements in Text analysis using Word Embedding
- Error ‘Entry point ‘Trainers.LightGbmClassifier’ not found’ and how to fix it
- Machine Learning Glossary of terms
- Export Machine Learning.Net models to ONNX format
- Loading Data In our Learning Pipeline With List (Lists for ever!)
- What’s new in version 0.2.0
- What’s a Machine Learning model? A 7 minute video as the best possible explanation
- Write and Load models using Machine Learning .Net
- Understanding the step by step of Hello World
- Hello World in ML.Net, Machine Learning for .Net !