Ya hace predicciones y crea el ZIP
This commit is contained in:
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user