Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform transform on test set #17

Open
shaygeller opened this issue Dec 31, 2018 · 2 comments
Open

Perform transform on test set #17

shaygeller opened this issue Dec 31, 2018 · 2 comments

Comments

@shaygeller
Copy link

shaygeller commented Dec 31, 2018

Hi,
This project looks really cool and important.
A good methodology of any data transformation and especially feature extraction is to do it on the train set and then transform the test set accordingly. That's because the test set should pretend to be the "real world" data and should remain unknown for decisions regarding any transformation.
At the moment, you don't have such an option in your code, but it would be really good to have one.

I know that some one-hot encoding can be a problem because the train and test can have different values. You can just create an "other" column for each categorical column and randomly assign some rows into it (from the train). That way, the classifier that gets the most relevant features will not skip this "other" column due to not having enough information in it.

@WillKoehrsen
Copy link
Owner

WillKoehrsen commented Jan 6, 2019

You should be able to transform the testing set after doing the feature selection on the training data. Assuming train is the training data after selection, you could do this using pandas align

test = pd.get_dummies(test)
train, test = train.align(test, axis=1, join='inner')

This will make sure both dataframes have the same exact columns. axis=1 refers to the columns, and join='inner' keeps only columns in both dataframes.

@wbgreen0405
Copy link

@WillKoehrsen Thank you this works.

How do I add the target variable back into the dataframe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants