1
$\begingroup$

I would like to create a List of Rules data structure to be used in the Classify function.

I have sample input data stored in one .csv file and target output values in another. There are four columns in the data file and one column in the target file. The information in one row of the four columns in the data file map to one row in the one column in the target file.

I can import the data and get it into a Data structure with:

X = Dataset[Import["x_data.csv"]];
Y = Dataset[Import["y_data.csv"]];

How would I construct a List of Rules mapping the four entries in each row in X to the entry in the one column in Y?

The required structure should look something like:

{x1,x2,x3,x4}->y

Note: This is a standard way to set up Machine Learning data in Scikit-learn in Python (the tool I have been using), if there is another better way in Mathematica, I would be interested in knowing.

This is what the input data looks like:

enter image description here

This is the target data (note that this is category data and further on there is non-zero data):

enter image description here

$\endgroup$
  • $\begingroup$ Can you give an example of what you expect? Does each row in X correspond to the same row in Y? Do you expect to see a rule of the form {x1,x2,x3,x4}->y, or something else? $\endgroup$ – rogerl Mar 5 '17 at 3:48
  • $\begingroup$ Hi, I expanded the question, hope its more clear now. {x1,x2,x3,x4}->y is basically what I want, (I think). $\endgroup$ – Mike Mar 5 '17 at 4:05
5
$\begingroup$

Forget datasets. Import your x data as table and your y data a list.

xdata = Import[FileNameJoin[{$HomeDirectory, "Desktop", "x_data.csv"}]]

{{5.1, 3.5, 1.4, 0.2}, {4.9, 3., 1.4, 0.3}}

ydata = 
  Import[FileNameJoin[{$HomeDirectory, "Desktop", "y_data.csv"}]] // Flatten

{1, 2}

Thread[Rule[xdata, ydata]]

{{5.1, 3.5, 1.4, 0.2} -> 1, {4.9, 3., 1.4, 0.3} -> 2}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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