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">
        $("#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
                type: "POST",
                url: "",
                data: JSON.stringify(fetur),
                contentType: "application/json",
                dataType: "json",
                success: function(response) {
                failure: function(error){

this is my flask app server

app = fl.Flask(__name__)
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)
    new = vector.transform(conve1)
    #conve2 = vector.transform(conve1)
    #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__':

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

prediksi: [{"predikisi":{"predictions":["","","","",""]}}]

0 Answers