i'm implementing my ML model on flask, it takes 5 features on one prediction but my model seems to predict it one by one.

this my script to send features from html page to flask app

<script type="text/javascript">
    $(document).ready(function(){
        $("#submit").on("click", function(event){
            var merk = $("#merk").val();
            var ukuran = $("#ukuran").val();
            var bahan = $("#bahan").val();
            var harga = $("#harga").val();
            var keterangan = $("#keterangan").val();
            var fetur = {
                merk : merk,
                ukuran : ukuran,
                bahan : bahan,
                harga : harga,
                keterangan : keterangan
            };
            $.ajax({
                type: "POST",
                url: "http://127.0.0.1:5000/predict",
                data: JSON.stringify(fetur),
                contentType: "application/json",
                dataType: "json",
                success: function(response) {
                    $("#response").html(JSON.stringify(response));
                },
                failure: function(error){
                    $("#response").html(error);
                }
            });
            $("#response").val("");
        });
    });
</script>

this is my flask app server

app = fl.Flask(__name__)
CORS(app)
model = pickle.load(open("../PA_model_final/model_pa.pkl","rb"))
vector = pickle.load(open("../PA_model_final/vector_pa.pkl","rb"))

@app.route('/predict', methods=['POST'])
def predict():
    conve = fl.request.get_json()
    conve1 = [str(conve['merk']),str(conve['ukuran']),str(conve['bahan']),str(conve['harga']),str(conve['keterangan'])]
    #conve2 = pd.DataFrame([conve],columns=conve.keys())
    #conve2 = conve2.apply(lambda row: '-_-'.join(row.values.astype(str)), axis=1)
    print(conve1)
    new = vector.transform(conve1)
    #conve2 = vector.transform(conve1)
    print(new)
    #our model rates the wine based on the input array
    #prediction = print(new)
    prediction = model.predict(new)
    #preparing a response object and storing the model's predictions
    response = {}
    response['predictions'] = prediction.tolist()

    #sending our response object back as json
    return fl.jsonify([{'predikisi': response}])



if __name__ == '__main__':
    app.run(debug=True)

i expect the model have only one output, but the output have five prediction

prediksi: [{"predikisi":{"predictions":["02.03.01.04.001.","02.09.06.03.033.","02.06.01.04.001.","02.09.06.03.033.","02.09.06.03.033."]}}]

0 Answers