-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Get the cross validation macro to work with non-default column names #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
52aba23
Add label/grou/weight column name arguments to CV and train-test macros
yaeldMS 7826c71
Fix unit test.
yaeldMS 235ff2d
Merge branch 'master' of https://github.com/dotnet/machinelearning in…
yaeldMS 43a8bbe
Merge.
yaeldMS 40ae3c2
Update CSharp API.
yaeldMS 4e62e14
Fix EntryPointCatalog test.
yaeldMS c862d36
Address PR comments.
yaeldMS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,11 @@ | |
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Microsoft.ML.Runtime.CommandLine; | ||
using Microsoft.ML.Runtime.Internal.Utilities; | ||
using Microsoft.ML.Runtime.Data; | ||
using Microsoft.ML.Runtime.Internal.Utilities; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Microsoft.ML.Runtime.EntryPoints.JsonUtils | ||
|
@@ -405,7 +404,11 @@ private static object ParseJsonValue(IExceptionContext ectx, Type type, Attribut | |
return null; | ||
|
||
if (type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(Optional<>) || type.GetGenericTypeDefinition() == typeof(Nullable<>))) | ||
{ | ||
if (type.GetGenericTypeDefinition() == typeof(Optional<>) && value.HasValues) | ||
value = value.Values().FirstOrDefault(); | ||
type = type.GetGenericArguments()[0]; | ||
} | ||
|
||
if (type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(Var<>))) | ||
{ | ||
|
@@ -426,81 +429,81 @@ private static object ParseJsonValue(IExceptionContext ectx, Type type, Attribut | |
{ | ||
switch (dt) | ||
{ | ||
case TlcModule.DataKind.Bool: | ||
return value.Value<bool>(); | ||
case TlcModule.DataKind.String: | ||
return value.Value<string>(); | ||
case TlcModule.DataKind.Char: | ||
return value.Value<char>(); | ||
case TlcModule.DataKind.Enum: | ||
if (!Enum.IsDefined(type, value.Value<string>())) | ||
throw ectx.Except($"Requested value '{value.Value<string>()}' is not a member of the Enum type '{type.Name}'"); | ||
return Enum.Parse(type, value.Value<string>()); | ||
case TlcModule.DataKind.Float: | ||
if (type == typeof(double)) | ||
return value.Value<double>(); | ||
else if (type == typeof(float)) | ||
return value.Value<float>(); | ||
else | ||
{ | ||
ectx.Assert(false); | ||
throw ectx.ExceptNotSupp(); | ||
} | ||
case TlcModule.DataKind.Array: | ||
var ja = value as JArray; | ||
ectx.Check(ja != null, "Expected array value"); | ||
Func<IExceptionContext, JArray, Attributes, ModuleCatalog, object> makeArray = MakeArray<int>; | ||
return Utils.MarshalInvoke(makeArray, type.GetElementType(), ectx, ja, attributes, catalog); | ||
case TlcModule.DataKind.Int: | ||
if (type == typeof(long)) | ||
return value.Value<long>(); | ||
if (type == typeof(int)) | ||
return value.Value<int>(); | ||
ectx.Assert(false); | ||
throw ectx.ExceptNotSupp(); | ||
case TlcModule.DataKind.UInt: | ||
if (type == typeof(ulong)) | ||
return value.Value<ulong>(); | ||
if (type == typeof(uint)) | ||
return value.Value<uint>(); | ||
case TlcModule.DataKind.Bool: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
can you return old indentation? it's really hard to read changes #Closed |
||
return value.Value<bool>(); | ||
case TlcModule.DataKind.String: | ||
return value.Value<string>(); | ||
case TlcModule.DataKind.Char: | ||
return value.Value<char>(); | ||
case TlcModule.DataKind.Enum: | ||
if (!Enum.IsDefined(type, value.Value<string>())) | ||
throw ectx.Except($"Requested value '{value.Value<string>()}' is not a member of the Enum type '{type.Name}'"); | ||
return Enum.Parse(type, value.Value<string>()); | ||
case TlcModule.DataKind.Float: | ||
if (type == typeof(double)) | ||
return value.Value<double>(); | ||
else if (type == typeof(float)) | ||
return value.Value<float>(); | ||
else | ||
{ | ||
ectx.Assert(false); | ||
throw ectx.ExceptNotSupp(); | ||
case TlcModule.DataKind.Dictionary: | ||
ectx.Check(value is JObject, "Expected object value"); | ||
Func<IExceptionContext, JObject, Attributes, ModuleCatalog, object> makeDict = MakeDictionary<int>; | ||
return Utils.MarshalInvoke(makeDict, type.GetGenericArguments()[1], ectx, (JObject)value, attributes, catalog); | ||
case TlcModule.DataKind.Component: | ||
var jo = value as JObject; | ||
ectx.Check(jo != null, "Expected object value"); | ||
// REVIEW: consider accepting strings alone. | ||
var jName = jo[FieldNames.Name]; | ||
ectx.Check(jName != null, "Field '" + FieldNames.Name + "' is required for component."); | ||
ectx.Check(jName is JValue, "Expected '" + FieldNames.Name + "' field to be a string."); | ||
var name = jName.Value<string>(); | ||
ectx.Check(jo[FieldNames.Settings] == null || jo[FieldNames.Settings] is JObject, | ||
"Expected '" + FieldNames.Settings + "' field to be an object"); | ||
return GetComponentJson(ectx, type, name, jo[FieldNames.Settings] as JObject, catalog); | ||
default: | ||
var settings = value as JObject; | ||
ectx.Check(settings != null, "Expected object value"); | ||
var inputBuilder = new InputBuilder(ectx, type, catalog); | ||
|
||
if (inputBuilder._fields.Length == 0) | ||
throw ectx.Except($"Unsupported input type: {dt}"); | ||
|
||
if (settings != null) | ||
} | ||
case TlcModule.DataKind.Array: | ||
var ja = value as JArray; | ||
ectx.Check(ja != null, "Expected array value"); | ||
Func<IExceptionContext, JArray, Attributes, ModuleCatalog, object> makeArray = MakeArray<int>; | ||
return Utils.MarshalInvoke(makeArray, type.GetElementType(), ectx, ja, attributes, catalog); | ||
case TlcModule.DataKind.Int: | ||
if (type == typeof(long)) | ||
return value.Value<long>(); | ||
if (type == typeof(int)) | ||
return value.Value<int>(); | ||
ectx.Assert(false); | ||
throw ectx.ExceptNotSupp(); | ||
case TlcModule.DataKind.UInt: | ||
if (type == typeof(ulong)) | ||
return value.Value<ulong>(); | ||
if (type == typeof(uint)) | ||
return value.Value<uint>(); | ||
ectx.Assert(false); | ||
throw ectx.ExceptNotSupp(); | ||
case TlcModule.DataKind.Dictionary: | ||
ectx.Check(value is JObject, "Expected object value"); | ||
Func<IExceptionContext, JObject, Attributes, ModuleCatalog, object> makeDict = MakeDictionary<int>; | ||
return Utils.MarshalInvoke(makeDict, type.GetGenericArguments()[1], ectx, (JObject)value, attributes, catalog); | ||
case TlcModule.DataKind.Component: | ||
var jo = value as JObject; | ||
ectx.Check(jo != null, "Expected object value"); | ||
// REVIEW: consider accepting strings alone. | ||
var jName = jo[FieldNames.Name]; | ||
ectx.Check(jName != null, "Field '" + FieldNames.Name + "' is required for component."); | ||
ectx.Check(jName is JValue, "Expected '" + FieldNames.Name + "' field to be a string."); | ||
var name = jName.Value<string>(); | ||
ectx.Check(jo[FieldNames.Settings] == null || jo[FieldNames.Settings] is JObject, | ||
"Expected '" + FieldNames.Settings + "' field to be an object"); | ||
return GetComponentJson(ectx, type, name, jo[FieldNames.Settings] as JObject, catalog); | ||
default: | ||
var settings = value as JObject; | ||
ectx.Check(settings != null, "Expected object value"); | ||
var inputBuilder = new InputBuilder(ectx, type, catalog); | ||
|
||
if (inputBuilder._fields.Length == 0) | ||
throw ectx.Except($"Unsupported input type: {dt}"); | ||
|
||
if (settings != null) | ||
{ | ||
foreach (var pair in settings) | ||
{ | ||
foreach (var pair in settings) | ||
{ | ||
if (!inputBuilder.TrySetValueJson(pair.Key, pair.Value)) | ||
throw ectx.Except($"Unexpected value for component '{type}', field '{pair.Key}': '{pair.Value}'"); | ||
} | ||
if (!inputBuilder.TrySetValueJson(pair.Key, pair.Value)) | ||
throw ectx.Except($"Unexpected value for component '{type}', field '{pair.Key}': '{pair.Value}'"); | ||
} | ||
} | ||
|
||
var missing = inputBuilder.GetMissingValues().ToArray(); | ||
if (missing.Length > 0) | ||
throw ectx.Except($"The following required inputs were not provided for component '{type}': {string.Join(", ", missing)}"); | ||
return inputBuilder.GetInstance(); | ||
var missing = inputBuilder.GetMissingValues().ToArray(); | ||
if (missing.Length > 0) | ||
throw ectx.Except($"The following required inputs were not provided for component '{type}': {string.Join(", ", missing)}"); | ||
return inputBuilder.GetInstance(); | ||
} | ||
} | ||
catch (FormatException ex) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to refactor it into IHaveLabelColumn, IHaveWeightColum, IHaveGroupColumn? And check for interface instead of abstract class? #Resolved