1
0

Añadido algo para cambiar el tipo del Label

This commit is contained in:
2023-01-17 15:03:44 +01:00
parent 4ad973b516
commit fe96cd41a4
2 changed files with 41 additions and 12 deletions

View File

@@ -16,7 +16,7 @@ namespace testML
{
public static class DictionaryToObjectConverter
{
public static IEnumerable<object> Convert(List<Dictionary<string, object>> data, out Type classType, out DataViewSchema schema)
public static IEnumerable<object> Convert(List<Dictionary<string, object>> data, string toPredict, out Type classType, out DataViewSchema schema)
{
var schemaBuilder = new DataViewSchema.Builder();
@@ -32,6 +32,12 @@ namespace testML
if (sampleValue != null)
{
var keyType = sampleValue.GetType();
if (key == toPredict)
{
keyType = typeof(float);
}
definition.Add(key, keyType);
if (keyType == typeof(string))
@@ -61,6 +67,7 @@ namespace testML
var converter = new DictionaryToObjectConverterClass()
{
ClassName = "OBJ" + Guid.NewGuid().ToString("N").ToUpper(),
ToPredict = toPredict,
Definition = definition
};
@@ -99,15 +106,37 @@ namespace testML
Type genericType = listType.MakeGenericType(classType);
var result =(IList) Activator.CreateInstance(genericType) ;
Dictionary<string, float> translate = new Dictionary<string, float>();
translate.Add(string.Empty, 0);
foreach (var inputData in data)
{
if (inputData.ContainsKey(toPredict) && inputData[toPredict] != null)
{
if (!translate.ContainsKey(inputData[toPredict] as string))
{
var max = translate.Values.Max()+1;
translate.Add(inputData[toPredict] as string, max);
}
}
}
foreach (var inputData in data)
{
var outputData = (IDictionaryToObjectConverter)Activator.CreateInstance(classType);
result.Add(outputData);
foreach (var key in inputData.Keys)
{
outputData[key] = inputData[key];
if (key == toPredict)
{
outputData[key] = translate[inputData[key] as string ?? string.Empty];
}
else
{
outputData[key] = inputData[key];
}
}
}