0
$\begingroup$

Lets say i have a categorical feature having a set of values equal to ['Single','Married','Divorced','Unknown']. Okay, so with the help of the other features, i create my model, i test it, all is fine and i deploy it.

Now , some user using my model as a webservice, types in 'Widow' for that feature value.

What's the proper way of dealing with it? Is there a way to ignore it? and predict based on the rest of the features only? or do i have to handle unknown feature values by assigning Unknown to them too? or worst case scenario, i handle the exception, return a message saying : hey man (or woman) use one of the available values on that feature! ??

Note : I'm trying to avoid assigning Unknown to it, because 'Unknown' has its weight. ( My real question is : if there is a way to set a feature's weight to 0 when doing inference )

$\endgroup$
1
$\begingroup$

Depending on the implementation, that variable could have been one-hot-encoded and in that way, the "widow" value could be assigned to "zero" in all the encoded variables (maybe equal to unknown) and the path designed to that 0 will be followed.

$\endgroup$
  • $\begingroup$ it is OneHot encoded. How do i get a full 0 one-hot vector for that value? $\endgroup$ – Blenz Apr 25 at 16:16
  • $\begingroup$ Remember that every set of dummies has m-1 columns so there is a column left where all the values are 0 $\endgroup$ – Juan Esteban de la Calle Apr 25 at 16:23
1
$\begingroup$

You could include a category of Other into which you can bin all non-valid responses. This person's response means that they are not single, married, or divorced - it does not represent Unknown, and neither does it represent a missing value. You will lose some information if you just ignore it (which some classification methods can do), since you at least know it's not the other values of single, married, or divorced.

The better option, though, it to have a drop-down menu of valid selections. Don't give people free-text entry and expect to get categorical values. It's not clear why you have a category of Unknown, either - in what cases will someone literally not know their marital status? Perhaps you are using this to capture missing data, in which case it should be labeled as such.

$\endgroup$
  • $\begingroup$ Yes , drop-down menu is used. The user typing widow was just for the sake of giving an example. New values , realistically , could arise from updating the database while my model isn't updated yet and might encounter a new value that he hasn't been trained on. and yes, Unknown is a must-have value because a lot of people withhold parts of their personal information ( Business of telephone prospecting ). Thanks for the info anyway, i'll just assign unknown to it until my model is updated. $\endgroup$ – Blenz Apr 25 at 16:32
  • $\begingroup$ can you give me a link for a way to ignore the invalid (unseen feature values) ( I'm using logistic regression for this classification ) $\endgroup$ – Blenz Apr 25 at 16:40
  • $\begingroup$ @Blenzus Logistic regression doesn't handle missing values, so you'd have to pick a different method, or you could impute the value, or throw out samples with missing data. Also, note that "Prefer not to answer" and "Unknown" are also not the same thing - the fact that someone is a private person and doesn't want to provide their marital status could actually be a useful feature, depending on what you're trying to predict. "Other", "missing", "unknown", and "prefer not to answer" are all distinct categories! $\endgroup$ – Nuclear Wang Apr 25 at 16:45
  • $\begingroup$ For what i'm trying to accomplish , it's the same thing, being private or not is not a good predictor on what i'm trying to predict. Maybe for some other context, yes you're absolutely right, that's a valuable information that could have some influence on the output. $\endgroup$ – Blenz Apr 25 at 16:48
0
$\begingroup$

Actually, the solution i'm going with, which is the most that made sense to me was to assign 'Unknown' temporarily to not-known-yet feature values. I cannot assign zeros to all my one-hot columns ( basically a NaN and throws in an error ). My model is supposed to be updated after a certain amount of time anyway, this is possible because my training data is not much compared to datasets with millions of records and hundreds of features. So yeah, until my features are updated by retraining the model with a more comprehensive dataset, i'll just assign 'Unknown' to unknown feature values.

$\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.