Function Repository Resource:

TableToTrainingSet

Source Notebook

Prepare rectangular data for use in the machine learning functions Classify, Predict and NetTrain

Contributed by: Jon McLoone

ResourceFunction["TableToTrainingSet"][data,n]

converts a matrix to a list of exampleoutput pairs where the output is taken from column n.

ResourceFunction["TableToTrainingSet"][assocs,key]

converts associations to a list of exampleoutput pairs where the output is labeled with key.

Details and Options

The data can be lists, associations or a Dataset.

Examples

Basic Examples (2) 

Prepare a matrix so that Classify can learn to predict column 3:

In[1]:=
data =
  {{"input1a", "input1b", "output1"},
   {"input2a", "input2b", "output2"}};
ResourceFunction["TableToTrainingSet"][data, 3]
Out[2]=
In[3]:=
Classify[%]
Out[3]=

Prepare an Association so that Predict can learn to predict the "output" values:

In[4]:=
data =
  {<|"inputa" -> 11, "inputb" -> 12, "output" -> 13|>,
   <|"inputa" -> 21, "inputb" -> 22, "output" -> 23|>};
ResourceFunction["TableToTrainingSet"][data, "output"]
Out[5]=
In[6]:=
Predict[%]
Out[6]=

Publisher

Jon McLoone

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 2.0.0 – 16 June 2020
  • 1.0.0 – 07 March 2019

License Information