MCPcopy Create free account
hub / github.com/DanilZherebtsov/ml-docker-flask-api / predict

Function predict

app/server.py:16–30  ·  view source on GitHub ↗

Predicts the class of a given set of features. Args: data (dict): A dictionary containing the features to predict. e.g. {"features": [1, 2, 3, 4]} Returns: dict: A dictionary containing the predicted class.

(data: dict)

Source from the content-addressed store, hash-verified

14
15@app.post('/predict')
16def predict(data: dict):
17 """
18 Predicts the class of a given set of features.
19
20 Args:
21 data (dict): A dictionary containing the features to predict.
22 e.g. {"features": [1, 2, 3, 4]}
23
24 Returns:
25 dict: A dictionary containing the predicted class.
26 """
27 features = np.array(data['features']).reshape(1, -1)
28 prediction = model.predict(features)
29 class_name = class_names[prediction][0]
30 return {'predicted_class': class_name}
31

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected