A Flask API for serving scikit-learn models
Amir Ziai
37019

Hi Amir,

I’m attempting to wrap my binary classifier in an API using the steps shown here.

My input to the API is a single string, and the output should be 0 or 1.

When I attempt to run this code:

query_df = pd.DataFrame(np.array([‘my string’]))

query = pd.get_dummies(query_df)
result = loaded_model.predict(query)

I get the error:

ValueError: Number of features of the model must match the input. Model n_features is 16413 and input n_features is 1

Are there additional steps I must take in shaping the input data into loaded_model.predict()?

My classifier is trained on single string features and binary labels (0 or 1).

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.