Reputation: 1246
This is a newb question but I'm a newb. So I can follow along ok with this example on building a predictive model:
https://machinelearningmastery.com/machine-learning-in-python-step-by-step/
My question is, now that I have this model built, how could I manually pass in these values to see what kind of Iris this is: [5.1,3.5,1.4,0.2].
I know I need to use the model.predict(), but I can't seem to get the data in the right format/fit.
I am just trying to learn by dissecting the example. Thank you.
Upvotes: 2
Views: 3113
Reputation: 2164
In the Make Predictions section, the author has the line
predictions = knn.predict(X_validation)
The argument that you pass to the predict method does not need to be a whole table. You can also pass a single row to it. Just make sure the orientation of the row you pass in is the same as the data you trained on.
If you're using a dataframe as input, for example, you probably did something like:
pd.DataFrame({"x1": [1,4,2,1,4,1], "x2": [7,9,7,7,6,8], ...})
So then, you could do
datapoint = pd.DataFrame({"x1": [1], "x2": [8], ...})
Pass the datapont object through all the prep you did to get your training data ready (eg scaler, onehot, etc), then pass it into the model's predict method:
datapoint_predict = knn.predict(datapoint)
Upvotes: 3