Añadido algo para cambiar el tipo del Label
This commit is contained in:
@@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user