Skip to main content
Tweeted twitter.com/StackMma/status/1137464505376608262
added 16 characters in body
Source Link
Picaud Vincent
  • 2.5k
  • 14
  • 23

Update: as @AntonAntoniv rightly noticed in his comment the case of DecisionTree is already discussed. Now it would be great to also have an equivalent answer for LogisticRegression.

 

MMA is really convenient to test/check various classiers, like DecisionTree, LogisticRegression, etc.. By example:

iris = ExampleData[{"MachineLearning", "FisherIris"}, "Data"];
data = GroupBy[iris, Last -> First];
c = Classify[data, Method -> "DecisionTree"];
cm = ClassifierMeasurements[c, data];
cm["ConfusionMatrixPlot"] 

enter image description here

Now suppose that I want to reuse the classifier elsewhere (for instance in a C++ code), is there any documentation about how to retrieve the relevant information like: tree structure, thresholds... etc?

I can do

c // InputForm

which prints a lot of information:

ClassifierFunction[<|"ExampleNumber" -> 150, "ClassNumber" -> 3,
"Input" -> <|"Preprocessor" -> MachineLearningMLProcessor["ToMLDataset", <|"Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Length" -> 4|>|>, "Output" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Preprocessor" -> MachineLearningMLProcessor["Sequence", <|"Processors" -> {MachineLearningMLProcessor["List"], MachineLearningMLProcessor["WrapMLDataset", <|"FeatureTypes" -> {"NumericalVector"}, "FeatureKeys" -> {"f1"}, "FeatureWeights" -> Automatic, "ExampleWeights" -> Automatic, "RawExample" -> Missing["KeyAbsent", "RawExample"]|>]}|>], "ScalarFeature" -> True, "Invertibility" -> "Perfect", "Missing" -> "Allowed"|>], "Processor" -> MachineLearningMLProcessor["Sequence", <|"Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Output" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Processors" -> {MachineLearningMLProcessor["ImputeMissing", <|"Invertibility" -> "Perfect", "Missing" -> "Imputed", "Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "VectorLength" -> 4, "Imputer" -> (DimensionReducerFunction[<|"ExampleNumber" -> 150, "Imputer" -> MachineLearningMLProcessor["ImputeMissing", <|"Invertibility" -> "Perfect", "Missing" -> "Imputed", "Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "VectorLength" -> 4, "Naive" -> True, "Fill" -> {5.843333333333335, 3.057333333333334, 3.7580000000000027, 1.199333333333334}, "Output" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Type" -> "NumericalVector"|>], "Preprocessor" -> MachineLearningMLProcessor["ToMLDataset",

....

... a long list ....

....

but AFAIK this structure is not documented.

In short is it possible the do "reverse engineering" of Classify function output? (I am espcially interested by DecitionTree and LogisticRegression).

Update: as @AntonAntoniv rightly noticed in his comment the case of DecisionTree is already discussed. Now it would be great to also have an equivalent answer for LogisticRegression.

MMA is really convenient to test/check various classiers, like DecisionTree, LogisticRegression, etc.. By example:

iris = ExampleData[{"MachineLearning", "FisherIris"}, "Data"];
data = GroupBy[iris, Last -> First];
c = Classify[data, Method -> "DecisionTree"];
cm = ClassifierMeasurements[c, data];
cm["ConfusionMatrixPlot"] 

enter image description here

Now suppose that I want to reuse the classifier elsewhere (for instance in a C++ code), is there any documentation about how to retrieve the relevant information like: tree structure, thresholds... etc?

I can do

c // InputForm

which prints a lot of information:

ClassifierFunction[<|"ExampleNumber" -> 150, "ClassNumber" -> 3,
"Input" -> <|"Preprocessor" -> MachineLearningMLProcessor["ToMLDataset", <|"Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Length" -> 4|>|>, "Output" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Preprocessor" -> MachineLearningMLProcessor["Sequence", <|"Processors" -> {MachineLearningMLProcessor["List"], MachineLearningMLProcessor["WrapMLDataset", <|"FeatureTypes" -> {"NumericalVector"}, "FeatureKeys" -> {"f1"}, "FeatureWeights" -> Automatic, "ExampleWeights" -> Automatic, "RawExample" -> Missing["KeyAbsent", "RawExample"]|>]}|>], "ScalarFeature" -> True, "Invertibility" -> "Perfect", "Missing" -> "Allowed"|>], "Processor" -> MachineLearningMLProcessor["Sequence", <|"Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Output" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Processors" -> {MachineLearningMLProcessor["ImputeMissing", <|"Invertibility" -> "Perfect", "Missing" -> "Imputed", "Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "VectorLength" -> 4, "Imputer" -> (DimensionReducerFunction[<|"ExampleNumber" -> 150, "Imputer" -> MachineLearningMLProcessor["ImputeMissing", <|"Invertibility" -> "Perfect", "Missing" -> "Imputed", "Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "VectorLength" -> 4, "Naive" -> True, "Fill" -> {5.843333333333335, 3.057333333333334, 3.7580000000000027, 1.199333333333334}, "Output" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Type" -> "NumericalVector"|>], "Preprocessor" -> MachineLearningMLProcessor["ToMLDataset",

....

... a long list ....

....

but AFAIK this structure is not documented.

In short is it possible the do "reverse engineering" of Classify function output? (I am espcially interested by DecitionTree and LogisticRegression).

Update: as @AntonAntoniv rightly noticed in his comment the case of DecisionTree is already discussed. Now it would be great to also have an equivalent answer for LogisticRegression.

 

MMA is really convenient to test/check various classiers, like DecisionTree, LogisticRegression, etc.. By example:

iris = ExampleData[{"MachineLearning", "FisherIris"}, "Data"];
data = GroupBy[iris, Last -> First];
c = Classify[data, Method -> "DecisionTree"];
cm = ClassifierMeasurements[c, data];
cm["ConfusionMatrixPlot"] 

enter image description here

Now suppose that I want to reuse the classifier elsewhere (for instance in a C++ code), is there any documentation about how to retrieve the relevant information like: tree structure, thresholds... etc?

I can do

c // InputForm

which prints a lot of information:

ClassifierFunction[<|"ExampleNumber" -> 150, "ClassNumber" -> 3,
"Input" -> <|"Preprocessor" -> MachineLearningMLProcessor["ToMLDataset", <|"Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Length" -> 4|>|>, "Output" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Preprocessor" -> MachineLearningMLProcessor["Sequence", <|"Processors" -> {MachineLearningMLProcessor["List"], MachineLearningMLProcessor["WrapMLDataset", <|"FeatureTypes" -> {"NumericalVector"}, "FeatureKeys" -> {"f1"}, "FeatureWeights" -> Automatic, "ExampleWeights" -> Automatic, "RawExample" -> Missing["KeyAbsent", "RawExample"]|>]}|>], "ScalarFeature" -> True, "Invertibility" -> "Perfect", "Missing" -> "Allowed"|>], "Processor" -> MachineLearningMLProcessor["Sequence", <|"Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Output" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Processors" -> {MachineLearningMLProcessor["ImputeMissing", <|"Invertibility" -> "Perfect", "Missing" -> "Imputed", "Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "VectorLength" -> 4, "Imputer" -> (DimensionReducerFunction[<|"ExampleNumber" -> 150, "Imputer" -> MachineLearningMLProcessor["ImputeMissing", <|"Invertibility" -> "Perfect", "Missing" -> "Imputed", "Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "VectorLength" -> 4, "Naive" -> True, "Fill" -> {5.843333333333335, 3.057333333333334, 3.7580000000000027, 1.199333333333334}, "Output" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Type" -> "NumericalVector"|>], "Preprocessor" -> MachineLearningMLProcessor["ToMLDataset",

....

... a long list ....

....

but AFAIK this structure is not documented.

In short is it possible the do "reverse engineering" of Classify function output? (I am espcially interested by DecitionTree and LogisticRegression).

edited title
Link
user64494
  • 29.1k
  • 4
  • 29
  • 56

Reverse Engineering of MMA `Classify[]` outputOutput?

added 18 characters in body
Source Link
Picaud Vincent
  • 2.5k
  • 14
  • 23

Update: as @AntonAntoniv rightly noticed in his comment the case of DecisionTree is coveredalready discussed. Now it would be great to also have an equivalent answer for LogisticRegression.

MMA is really convenient to test/check various classiers, like DecisionTree, LogisticRegression, etc.. By example:

iris = ExampleData[{"MachineLearning", "FisherIris"}, "Data"];
data = GroupBy[iris, Last -> First];
c = Classify[data, Method -> "DecisionTree"];
cm = ClassifierMeasurements[c, data];
cm["ConfusionMatrixPlot"] 

enter image description here

Now suppose that I want to reuse the classifier elsewhere (for instance in a C++ code), is there any documentation about how to retrieve the relevant information like: tree structure, thresholds... etc?

I can do

c // InputForm

which prints a lot of information:

ClassifierFunction[<|"ExampleNumber" -> 150, "ClassNumber" -> 3,
"Input" -> <|"Preprocessor" -> MachineLearningMLProcessor["ToMLDataset", <|"Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Length" -> 4|>|>, "Output" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Preprocessor" -> MachineLearningMLProcessor["Sequence", <|"Processors" -> {MachineLearningMLProcessor["List"], MachineLearningMLProcessor["WrapMLDataset", <|"FeatureTypes" -> {"NumericalVector"}, "FeatureKeys" -> {"f1"}, "FeatureWeights" -> Automatic, "ExampleWeights" -> Automatic, "RawExample" -> Missing["KeyAbsent", "RawExample"]|>]}|>], "ScalarFeature" -> True, "Invertibility" -> "Perfect", "Missing" -> "Allowed"|>], "Processor" -> MachineLearningMLProcessor["Sequence", <|"Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Output" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Processors" -> {MachineLearningMLProcessor["ImputeMissing", <|"Invertibility" -> "Perfect", "Missing" -> "Imputed", "Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "VectorLength" -> 4, "Imputer" -> (DimensionReducerFunction[<|"ExampleNumber" -> 150, "Imputer" -> MachineLearningMLProcessor["ImputeMissing", <|"Invertibility" -> "Perfect", "Missing" -> "Imputed", "Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "VectorLength" -> 4, "Naive" -> True, "Fill" -> {5.843333333333335, 3.057333333333334, 3.7580000000000027, 1.199333333333334}, "Output" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Type" -> "NumericalVector"|>], "Preprocessor" -> MachineLearningMLProcessor["ToMLDataset",

....

... a long list ....

....

but AFAIK this structure is not documented.

In short is it possible the do "reverse engineering" of Classify function output? (I am espcially interested by DecitionTree and LogisticRegression).

Update: as @AntonAntoniv rightly noticed in his comment the case of DecisionTree is covered. Now would be great to have an equivalent answer for LogisticRegression.

MMA is really convenient to test/check various classiers, like DecisionTree, LogisticRegression, etc.. By example:

iris = ExampleData[{"MachineLearning", "FisherIris"}, "Data"];
data = GroupBy[iris, Last -> First];
c = Classify[data, Method -> "DecisionTree"];
cm = ClassifierMeasurements[c, data];
cm["ConfusionMatrixPlot"] 

enter image description here

Now suppose that I want to reuse the classifier elsewhere (for instance in a C++ code), is there any documentation about how to retrieve the relevant information like: tree structure, thresholds... etc?

I can do

c // InputForm

which prints a lot of information:

ClassifierFunction[<|"ExampleNumber" -> 150, "ClassNumber" -> 3,
"Input" -> <|"Preprocessor" -> MachineLearningMLProcessor["ToMLDataset", <|"Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Length" -> 4|>|>, "Output" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Preprocessor" -> MachineLearningMLProcessor["Sequence", <|"Processors" -> {MachineLearningMLProcessor["List"], MachineLearningMLProcessor["WrapMLDataset", <|"FeatureTypes" -> {"NumericalVector"}, "FeatureKeys" -> {"f1"}, "FeatureWeights" -> Automatic, "ExampleWeights" -> Automatic, "RawExample" -> Missing["KeyAbsent", "RawExample"]|>]}|>], "ScalarFeature" -> True, "Invertibility" -> "Perfect", "Missing" -> "Allowed"|>], "Processor" -> MachineLearningMLProcessor["Sequence", <|"Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Output" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Processors" -> {MachineLearningMLProcessor["ImputeMissing", <|"Invertibility" -> "Perfect", "Missing" -> "Imputed", "Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "VectorLength" -> 4, "Imputer" -> (DimensionReducerFunction[<|"ExampleNumber" -> 150, "Imputer" -> MachineLearningMLProcessor["ImputeMissing", <|"Invertibility" -> "Perfect", "Missing" -> "Imputed", "Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "VectorLength" -> 4, "Naive" -> True, "Fill" -> {5.843333333333335, 3.057333333333334, 3.7580000000000027, 1.199333333333334}, "Output" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Type" -> "NumericalVector"|>], "Preprocessor" -> MachineLearningMLProcessor["ToMLDataset",

....

... a long list ....

....

but AFAIK this structure is not documented.

In short is it possible the do "reverse engineering" of Classify function output? (I am espcially interested by DecitionTree and LogisticRegression).

Update: as @AntonAntoniv rightly noticed in his comment the case of DecisionTree is already discussed. Now it would be great to also have an equivalent answer for LogisticRegression.

MMA is really convenient to test/check various classiers, like DecisionTree, LogisticRegression, etc.. By example:

iris = ExampleData[{"MachineLearning", "FisherIris"}, "Data"];
data = GroupBy[iris, Last -> First];
c = Classify[data, Method -> "DecisionTree"];
cm = ClassifierMeasurements[c, data];
cm["ConfusionMatrixPlot"] 

enter image description here

Now suppose that I want to reuse the classifier elsewhere (for instance in a C++ code), is there any documentation about how to retrieve the relevant information like: tree structure, thresholds... etc?

I can do

c // InputForm

which prints a lot of information:

ClassifierFunction[<|"ExampleNumber" -> 150, "ClassNumber" -> 3,
"Input" -> <|"Preprocessor" -> MachineLearningMLProcessor["ToMLDataset", <|"Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Length" -> 4|>|>, "Output" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Preprocessor" -> MachineLearningMLProcessor["Sequence", <|"Processors" -> {MachineLearningMLProcessor["List"], MachineLearningMLProcessor["WrapMLDataset", <|"FeatureTypes" -> {"NumericalVector"}, "FeatureKeys" -> {"f1"}, "FeatureWeights" -> Automatic, "ExampleWeights" -> Automatic, "RawExample" -> Missing["KeyAbsent", "RawExample"]|>]}|>], "ScalarFeature" -> True, "Invertibility" -> "Perfect", "Missing" -> "Allowed"|>], "Processor" -> MachineLearningMLProcessor["Sequence", <|"Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Output" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Processors" -> {MachineLearningMLProcessor["ImputeMissing", <|"Invertibility" -> "Perfect", "Missing" -> "Imputed", "Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "VectorLength" -> 4, "Imputer" -> (DimensionReducerFunction[<|"ExampleNumber" -> 150, "Imputer" -> MachineLearningMLProcessor["ImputeMissing", <|"Invertibility" -> "Perfect", "Missing" -> "Imputed", "Input" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "VectorLength" -> 4, "Naive" -> True, "Fill" -> {5.843333333333335, 3.057333333333334, 3.7580000000000027, 1.199333333333334}, "Output" -> <|"f1" -> <|"Type" -> "NumericalVector", "Weight" -> 1|>|>, "Type" -> "NumericalVector"|>], "Preprocessor" -> MachineLearningMLProcessor["ToMLDataset",

....

... a long list ....

....

but AFAIK this structure is not documented.

In short is it possible the do "reverse engineering" of Classify function output? (I am espcially interested by DecitionTree and LogisticRegression).

added 129 characters in body
Source Link
Picaud Vincent
  • 2.5k
  • 14
  • 23
Loading
added 163 characters in body
Source Link
Picaud Vincent
  • 2.5k
  • 14
  • 23
Loading
Source Link
Picaud Vincent
  • 2.5k
  • 14
  • 23
Loading