File size: 481 Bytes
6664106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import joblib
import numpy as np

model = joblib.load("model.joblib")
labels = ["setosa", "versicolor", "virginica"]

def predict(inputs):
    features = np.array([[
        inputs["sepal_length"],
        inputs["sepal_width"],
        inputs["petal_length"],
        inputs["petal_width"]
    ]])

    probs = model.predict_proba(features)[0]
    idx = probs.argmax()

    return {
        "class": labels[idx],
        "confidence": float(probs[idx])
    }