I would like to do the following:

  1. Load data from a single tab of an Excel workbook into a Mathematica table.
  2. Prepare the data for use with the Mathematica Classify function.

The training set that I want to pass into Classify would be:

 xlData = Import["TrainingData.xlsx"];

I am using a Table function to generate the list of associations to pass to the Classify function.

               {row, 1, 5}];

Several things I have noticed here.

  • If I dump cfList by just typing it on an input line, Mathematica gets very bogged down. After 30 to 50 seconds some output finally appears.
  • If I execute Classify[cfList];, it take at least 2 minutes on as few as 10 items in cfList.

My primary question is: what is the best way to build a list of associations from Excel data for use with the Classify function?

  • $\begingroup$ Data from excel, when imported, appears as lists of lists. Have you just tried making a simple excel file and then working out what depth of list you are seeing? $\endgroup$
    – Hugh
    Nov 12, 2018 at 21:51
  • $\begingroup$ Sorry Hugh, I am working with a simple Excel file. The depth of the list is not the question. I am asking how I would prepare data from an Excel sheet for use with the Classify function. $\endgroup$ Nov 12, 2018 at 21:55
  • $\begingroup$ Does it work for you? {#, #2, #3} -> #7 & @@@ Rest(*dropheaders*)@First(*sheet*)@Import[pathToXLSX] $\endgroup$
    – Kuba
    Nov 12, 2018 at 23:19

1 Answer 1


I created an excel file to try and replicate your inputs. Row 1 is comprised of headers. In columns A through C I have trial data. In Column G, I have an "Answer" that the data should be pointing to.

First, Import your data:

data = Import["TrainingData.xlsx"]

Then separate out your inputs from your answers:

inputs = data[[1, All, 1 ;; 3]] // Rest
answers = data[[1, All, 7]] // Rest

Then thread the two together for your classify function:

thread = Thread[inputs -> answers]

Now you can run the Classify function on it:

classify = Classify[thread]

And pull the results based on new inputs:

classify[{7, 62, 52}]

NOTE: The above assumes that columns A, B, and C are numbers, but this should work with anything.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.