I am creating a CLI tool for ML.NET and I need to make a merge function, to merge two datasets of the same type. But it needs to be as generic as possible because the tool contains different dataset types.
I managed to make a method that converts a IDataview to a generic IEnumerable with a given dataset type:
private IEnumerable<object> GetDataEnumerable(MLContext mlContext, IDataView dataView, Type dataViewType) {
var createEnumerableMethod = typeof(DataOperationsCatalog).GetMethod(nameof(MLContext.Data.CreateEnumerable));
var generic = createEnumerableMethod.MakeGenericMethod(dataViewType);
return (IEnumerable<object>)generic.Invoke(mlContext.Data, new object[] { dataView, false, null, null });
}
Aucun commentaire:
Enregistrer un commentaire