Wolfram Research

Function Repository Resource:

TableToTrainingSet

Source Notebook

Prepare rectangular data for use in 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.

Examples

Basic Examples

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]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

License Information