BookmarkSubscribeRSS Feed
Obsidian | Level 7

I have a dataset that looks like this: for every ID, they have a list of products and features related to that product. I want to input that into my model, so I have to encode the categorical variables. How would go about encoding them into integer labels or one-hot? I've seen macros for these but they seem impractical as I have to do it for every column separately from what I've seen and similar columns (ex: prod_1 and prod_2) might have different encodings. 


Is there an action set or anything that when given a dataset, does the encoding for you? Similarly for normalizing continuous variables. 


Tourmaline | Level 20

Why do your want to do this?


Most SAS procedures that support the Class Statement does not require integer representation of class variables.

Obsidian | Level 7
I'm using the deeplearn action set in a proc cas, so this also supports class variables as input?

This is the documentation I'm following:

All my inputs are the columns (and the sequence parameter for tokenSize). Can I just use the categorical features as-is as inputs? LSTM models, as far as I know, require you to have your features encoded. That's at least what I did in python.
Diamond | Level 26

I have a dataset that looks like this: for every ID, they have a list of products and features related to that product. I want to input that into my model, so I have to encode the categorical variables.


I think this is incorrect in general. SAS has created a method to include categorical variables in a model, so you don't have to do this encoding. This method is the CLASS statement. See, for example, PROC GLM documentation, but this applies to all modeling procedures I know of.

Paige Miller
Obsidian | Level 7
I'm using the deeplearn action set to train my model (LSTM), and I assumed you have to encode categorical variables. My inputs will be the columns (features), and a target variable (which I forgot to add but it's just one column of products).

Can I just include categorical features in this as well? Still new to this one.
SAS Employee
Yes I think you can use the nominals= argument in the dlTrain action to indicate which inputs/target are categorical.
Obsidian | Level 7

Thanks for the reply. I'll try it. I remember getting a warning on how only the target variable (or was it inputs?) can be a categorical variable when trying to train a LSTM model. Maybe I didn't add it/the inputs in the nominals. 

The target which is also a categorical variable has to be specified in the nominals argument and as the target argument, right?

SAS Employee
I think so - I know that's true for other actions.
Obsidian | Level 7

Great, I will test it out.

A simple follow-up to this: if customers can have different number of products in the sequence, I would have to pad until the sequences are of the same length (similar to pad_sequences from tensorflow). Should I be doing this before training or is there a way to have it train/learn from variable length sequences? There's a missing argument, but only applicable for regression models apparently.  And a forceEqualPadding argument but only for convolutional layers?

SAS Employee

There are some graphs on this documentation page showing the how tokens are concatenated. I think the padding would need to be done before training. 

Obsidian | Level 7
If I pad with zeros for example, how would the model training know to 'ignore' the padding? In tensorflow, you had a masking layer, or I think the model would implicitly ignore zeros (not positive).

I wish there way a way to just input variable length sequences.

@WendyCzika if you have any ideas on how to do this, please share. Thanks.

Obsidian | Level 7
A quick follow-up.

I tried inputting categorical variables into my LSTM model, and it errored out saying only target variables can be nominals. Encoding the products into integers gave me terrible results. Not sure what can be done in this case.


Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.


Register now!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 11 replies
  • 5 in conversation