# Want neural net example of rules {vector->string}

I am using data samples from a multispectral color sensor for color classification as an exercise in beginning to learn about neural networks.

I have succeeded with Classify for two data formats, {list of 10 integers} -> "color-name"} and {list of 10 integers} -> integer}.

I also succeeded with NetChain for the second, all integer, format. However, I can't seem to get NetChain set up with NetEncode properly so that the color name gets changed to an integer. Classify does this. I would like to know how it is done.

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign Nov 27, 2020 at 6:50
• Can you add some sample data to help others solve your problem? Nov 27, 2020 at 6:51
• Here is a sample: In[97]:= {spd2[[6000 ;; 6010, 1 ;; 2]]} Out[97]= {{{146, 734, 659, 457, 5356, 770, 537, 973, 1321, 1956} -> "Violet", {194, 418, 598, 722, 7470, 964, 1074, 2572, 3542, 2833} -> "Orange", {195, 900, 1238, 1374, 7551, 938, 1558, 1557, 1820, 1875} -> "Gray", {240, 321, 711, 1710, 9970, 1287, 2938, 3723, 4032, 2896} -> "Yellow",..., {287, 604, 639, 581, 12897, 1109, 737, 2233, 7648, 6920} -> "Red"}} Nov 27, 2020 at 15:12
• Sorry about the formatting; I just copied and pasted from the notebook. What format should I select from the Copy As menu to make it look nice in this forum? Nov 27, 2020 at 15:17
• Just FYI, the first eight numbers are from the visible spectrum, the ninth is a full intensity value, and the tenth is the near infrared. Nov 27, 2020 at 15:20

data={{146,734,659,457,5356,770,537,973,1321,1956}->"Violet",{194,418,598,722,7470,964,1074,2572,3542,2833}->"Orange",{195,900,1238,1374,7551,938,1558,1557,1820,1875}->"Gray",{240,321,711,1710,9970,1287,2938,3723,4032,2896}->"Yellow",{287,604,639,581,12897,1109,737,2233,7648,6920}->"Red"};
net = NetChain[
{
LinearLayer[20],
LinearLayer[],
SoftmaxLayer[]
},
"Input" -> Length@data[[1, 1]],
"Output" -> NetDecoder[{"Class", DeleteDuplicates@data[[;; , 2]]}]
]

netT = NetTrain[net, data[[;; , 1]] -> data[[;; , 2]]]

netT@data[[;; , 1]]

{"Violet", "Orange", "Gray", "Yellow", "Red"}

• Many thanks! It works perfectly on the full data set. I will now study your working example. I have a lot to learn, but this has put me back on track. Dec 2, 2020 at 23:09