-
Notifications
You must be signed in to change notification settings - Fork 75
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
ValueError: could not convert string to float: 'Rural Adj' #128
Comments
Hi @sbpatel2009, sorry for the late reply and thanks for contributing to auton-survival 🙂 You may already have figured it out by yourself, but the reason for that error lies in this bit of code: auton-survival/auton_survival/preprocessing.py Lines 209 to 212 in 5dde465
As you can see from the code, the preprocessor assumes that if no A workaround can be to add a dummy numerical column to the input DataFrame: from auton_survival.preprocessing import Preprocessor
import pandas as pd
cat_feats = ['Rural']
num_feats = ['Dummy']
X = pd.DataFrame({'Rural': ['yes', 'no', 'maybe'], 'Dummy': [0, 0, 0]})
preprocessor = Preprocessor()
X = preprocessor.fit_transform(data=X, cat_feats=cat_feats, num_feats=num_feats)
X = X.drop(columns=['Dummy'])
print(X) |
Thank you, Matteo! That is a clever workaround! I just used the one hot
encoder in scikit learn.
Best,
Snehal
…On Thu, Nov 9, 2023 at 9:41 AM Matteo Fordiani ***@***.***> wrote:
Hi @sbpatel2009 <https://github.com/sbpatel2009>, sorry for the late
reply and thanks for contributing to auton-survival 🙂
You may already have figured it out by yourself, but the reason for that
error lies in this bit of code:
https://github.com/autonlab/auton-survival/blob/5dde465f7223601717abddc1d075e837707c403b/auton_survival/preprocessing.py#L209-L212
As you can see from the code, the preprocessor assumes that if no
num_feats are provided, all feats are num_feats.
A workaround can be to add a dummy numerical column to the input
DataFrame, although while experimenting with this example I found another
bug that I detailed here #133
<#133>
from auton_survival.preprocessing import Preprocessorimport pandas as pd
cat_feats = ['Rural']num_feats = ['Dummy']
X = pd.DataFrame({'Rural': ['yes', 'no', 'maybe'], 'Dummy': [0, 0, 0]})
preprocessor = Preprocessor()X = preprocessor.fit_transform(data=X, cat_feats=cat_feats, num_feats=num_feats)
print(X)
—
Reply to this email directly, view it on GitHub
<#128 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGAPI626SXUOM66H3NLPCYDYDT2RHAVCNFSM6AAAAAA3RVXYOGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBUGA3TAOJTGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I am attempting to fit the
Preprocessor
on training data that only includes categorical variables. It appears that when I pass an empty list to the num_feats parameter, thePreprocessor
attempts to convert all columns to floats and returns an error.This code:
...returns this error:
I may be missing it, but I don't see how to handle this issue in the documentation. Does this class require there to be numerical features?
The text was updated successfully, but these errors were encountered: