Skip to content
Advertisement

How can we make a prediction using Scikit-Learn Classifiers?

I can easily train and test a classifier using the code below.

JavaScript

Now, how can I make a prediction of the target variable (dependent variable) based on the independent variables?

Something like this should work, I think, but it doesn’t…

JavaScript

If we leave numerics as numerics, and put quotes around labels, I would like to predict the dependent variable, but I can’t, because of the labeled data. If the data was all numerics, and this was a regression problem, it would work!! My question is…how can we feed in numbers and labels, like a real person would understand, rather than using the the numerics that the labels are converted into. I’ve gotta believe, labels are converted into numerics (one hot encoding, catagorical codes, or whatever) before the training and testing is done, right.

Here is the error message that I’m getting.

JavaScript

Advertisement

Answer

You can create a map of your columns values with the corresponding categorical values:

JavaScript

obtaining:

JavaScript

And then use this map to convert the array you want to predict:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement