Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

For example, we have data:

SeedRandom[0];
n = 1000;
X = RandomReal[{-1, 1}, {n, 10}];
Y = RandomInteger[1, n];
c = Classify[X -> Y, Method -> "NeuralNetwork"]

Let's see the options:

Options[c]

We can see neuron types: enter image description here

Let's reconstruct this network:

net = NetChain[
  {LinearLayer[30], Ramp, LinearLayer[30], Ramp, 2, SoftmaxLayer[]},
  "Input" -> 10,
  "Output" -> NetDecoder[{"Class", {0, 1}}]
  ]

enter image description here

But weights are uninitialized. Let's initialize them with NetReplacePart. This is the new function in V11.1. As I see you are using V11.0. But you can experiment with V11.1 in the Wolfram Open Cloud for free.

weights = Options[c][[1]]["Models"][[1]]["NeuralNetwork"]["Weights"];
biases = Options[c][[1]]["Models"][[1]]["NeuralNetwork"]["Biases"];

net = NetReplacePart[net,
  {
   {1, "Weights"} -> weights[[1]],
   {1, "Biases"} -> biases[[1]],
   {3, "Weights"} -> weights[[2]],
   {3, "Biases"} -> biases[[2]],
   {5, "Weights"} -> weights[[3]],
   {5, "Biases"} -> biases[[3]]
   }
  ]

Let's compare our classifiers:

ClassifierMeasurements[c, X -> Y, "ConfusionMatrixPlot"]

enter image description here

In V11.1 network can be converted into a ClassifierFunction.

ClassifierMeasurements[Classify[net], Standardize[X] -> Y, "ConfusionMatrixPlot"]

enter image description here

Result is the same!

Additional links:

  1. Wolfram Open Cloud: https://www.open.wolframcloud.com

  2. How to change weights of a neural network: http://mathematica.stackexchange.com/a/141291/23402https://mathematica.stackexchange.com/a/141291/23402

  3. "Is it possible to convert the result of NetTrain to a PredictorFunction?": http://mathematica.stackexchange.com/a/140095/23402https://mathematica.stackexchange.com/a/140095/23402

For example, we have data:

SeedRandom[0];
n = 1000;
X = RandomReal[{-1, 1}, {n, 10}];
Y = RandomInteger[1, n];
c = Classify[X -> Y, Method -> "NeuralNetwork"]

Let's see the options:

Options[c]

We can see neuron types: enter image description here

Let's reconstruct this network:

net = NetChain[
  {LinearLayer[30], Ramp, LinearLayer[30], Ramp, 2, SoftmaxLayer[]},
  "Input" -> 10,
  "Output" -> NetDecoder[{"Class", {0, 1}}]
  ]

enter image description here

But weights are uninitialized. Let's initialize them with NetReplacePart. This is the new function in V11.1. As I see you are using V11.0. But you can experiment with V11.1 in the Wolfram Open Cloud for free.

weights = Options[c][[1]]["Models"][[1]]["NeuralNetwork"]["Weights"];
biases = Options[c][[1]]["Models"][[1]]["NeuralNetwork"]["Biases"];

net = NetReplacePart[net,
  {
   {1, "Weights"} -> weights[[1]],
   {1, "Biases"} -> biases[[1]],
   {3, "Weights"} -> weights[[2]],
   {3, "Biases"} -> biases[[2]],
   {5, "Weights"} -> weights[[3]],
   {5, "Biases"} -> biases[[3]]
   }
  ]

Let's compare our classifiers:

ClassifierMeasurements[c, X -> Y, "ConfusionMatrixPlot"]

enter image description here

In V11.1 network can be converted into a ClassifierFunction.

ClassifierMeasurements[Classify[net], Standardize[X] -> Y, "ConfusionMatrixPlot"]

enter image description here

Result is the same!

Additional links:

  1. Wolfram Open Cloud: https://www.open.wolframcloud.com

  2. How to change weights of a neural network: http://mathematica.stackexchange.com/a/141291/23402

  3. "Is it possible to convert the result of NetTrain to a PredictorFunction?": http://mathematica.stackexchange.com/a/140095/23402

For example, we have data:

SeedRandom[0];
n = 1000;
X = RandomReal[{-1, 1}, {n, 10}];
Y = RandomInteger[1, n];
c = Classify[X -> Y, Method -> "NeuralNetwork"]

Let's see the options:

Options[c]

We can see neuron types: enter image description here

Let's reconstruct this network:

net = NetChain[
  {LinearLayer[30], Ramp, LinearLayer[30], Ramp, 2, SoftmaxLayer[]},
  "Input" -> 10,
  "Output" -> NetDecoder[{"Class", {0, 1}}]
  ]

enter image description here

But weights are uninitialized. Let's initialize them with NetReplacePart. This is the new function in V11.1. As I see you are using V11.0. But you can experiment with V11.1 in the Wolfram Open Cloud for free.

weights = Options[c][[1]]["Models"][[1]]["NeuralNetwork"]["Weights"];
biases = Options[c][[1]]["Models"][[1]]["NeuralNetwork"]["Biases"];

net = NetReplacePart[net,
  {
   {1, "Weights"} -> weights[[1]],
   {1, "Biases"} -> biases[[1]],
   {3, "Weights"} -> weights[[2]],
   {3, "Biases"} -> biases[[2]],
   {5, "Weights"} -> weights[[3]],
   {5, "Biases"} -> biases[[3]]
   }
  ]

Let's compare our classifiers:

ClassifierMeasurements[c, X -> Y, "ConfusionMatrixPlot"]

enter image description here

In V11.1 network can be converted into a ClassifierFunction.

ClassifierMeasurements[Classify[net], Standardize[X] -> Y, "ConfusionMatrixPlot"]

enter image description here

Result is the same!

Additional links:

  1. Wolfram Open Cloud: https://www.open.wolframcloud.com

  2. How to change weights of a neural network: https://mathematica.stackexchange.com/a/141291/23402

  3. "Is it possible to convert the result of NetTrain to a PredictorFunction?": https://mathematica.stackexchange.com/a/140095/23402

Source Link
Alexey Golyshev
  • 9.6k
  • 2
  • 27
  • 58

For example, we have data:

SeedRandom[0];
n = 1000;
X = RandomReal[{-1, 1}, {n, 10}];
Y = RandomInteger[1, n];
c = Classify[X -> Y, Method -> "NeuralNetwork"]

Let's see the options:

Options[c]

We can see neuron types: enter image description here

Let's reconstruct this network:

net = NetChain[
  {LinearLayer[30], Ramp, LinearLayer[30], Ramp, 2, SoftmaxLayer[]},
  "Input" -> 10,
  "Output" -> NetDecoder[{"Class", {0, 1}}]
  ]

enter image description here

But weights are uninitialized. Let's initialize them with NetReplacePart. This is the new function in V11.1. As I see you are using V11.0. But you can experiment with V11.1 in the Wolfram Open Cloud for free.

weights = Options[c][[1]]["Models"][[1]]["NeuralNetwork"]["Weights"];
biases = Options[c][[1]]["Models"][[1]]["NeuralNetwork"]["Biases"];

net = NetReplacePart[net,
  {
   {1, "Weights"} -> weights[[1]],
   {1, "Biases"} -> biases[[1]],
   {3, "Weights"} -> weights[[2]],
   {3, "Biases"} -> biases[[2]],
   {5, "Weights"} -> weights[[3]],
   {5, "Biases"} -> biases[[3]]
   }
  ]

Let's compare our classifiers:

ClassifierMeasurements[c, X -> Y, "ConfusionMatrixPlot"]

enter image description here

In V11.1 network can be converted into a ClassifierFunction.

ClassifierMeasurements[Classify[net], Standardize[X] -> Y, "ConfusionMatrixPlot"]

enter image description here

Result is the same!

Additional links:

  1. Wolfram Open Cloud: https://www.open.wolframcloud.com

  2. How to change weights of a neural network: http://mathematica.stackexchange.com/a/141291/23402

  3. "Is it possible to convert the result of NetTrain to a PredictorFunction?": http://mathematica.stackexchange.com/a/140095/23402