Assume I have this sample data:
Sample.csv:
Dog,25
Cat,23
Cat,20
Dog,0
And I want to load it to the IDataView, the transform it to be ready for ML (without strings and so), then save it again as .csv, say to analyze it with another tool or languages.
// Load data:
var sampleCsv = Path.Combine("Data", "Sample.csv");
var columns = new[]
{
new TextLoader.Column("type", DataKind.String, 0),
new TextLoader.Column("age", DataKind.Int16, 1),
};
var mlContext = new MLContext(seed: 0);
var dataView = mlContext.Data.LoadFromTextFile(sampleCsv, columns,',');
// Transform
var pipeline =
mlContext.Transforms.Categorical.OneHotEncoding("type",
// This outputKind will add just one column, while others will add some:
outputKind: OneHotEncodingEstimator.OutputKind.Key);
var transformedDataView = pipeline.Fit(dataView).Transform(dataView);
// transformedDataView:
// Dog,1,25
// Cat,2,23
// Cat,2,20
// Dog,1,0
How to get the two numbers columns and write them to the .csv file?