1
0

Ya hace predicciones y crea el ZIP

This commit is contained in:
2023-01-18 14:20:53 +01:00
parent fe96cd41a4
commit 7f68e262f4
4 changed files with 281 additions and 117 deletions

View File

@@ -16,9 +16,9 @@ namespace testML
{
public static class DictionaryToObjectConverter
{
public static IEnumerable<object> Convert(List<Dictionary<string, object>> data, string toPredict, out Type classType, out DataViewSchema schema)
public static IEnumerable<object> Convert(List<Dictionary<string, object>> data, string toPredict, out Type classType, out Type classPredictionType, out DataViewSchema schema)
{
var schemaBuilder = new DataViewSchema.Builder();
var schemaBuilder = new DataViewSchema.Builder();
var definition = new Dictionary<string, Type>();
@@ -32,12 +32,6 @@ namespace testML
if (sampleValue != null)
{
var keyType = sampleValue.GetType();
if (key == toPredict)
{
keyType = typeof(float);
}
definition.Add(key, keyType);
if (keyType == typeof(string))
@@ -101,42 +95,22 @@ namespace testML
var dllAssembly = compilerResults.CompiledAssembly;
classType = dllAssembly.GetType("DictionaryToObjectConverterNamespace." + converter.ClassName);
classPredictionType = dllAssembly.GetType("DictionaryToObjectConverterNamespace." + converter.ClassName + "Prediction");
Type listType = typeof(List<>);
Type genericType = listType.MakeGenericType(classType);
var result =(IList) Activator.CreateInstance(genericType) ;
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)
{
if (key == toPredict)
{
outputData[key] = translate[inputData[key] as string ?? string.Empty];
}
else
{
outputData[key] = inputData[key];
}
outputData[key] = inputData[key];
}
}