I'm having trouble with a Flask app that uses Postman to send a JSON. The app runs, but when I try to use Postman to send a sample JSON, I get a reshaping error: "Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample." Typically I know how to solve this in, say, a model, but I'm not sure how this applies to a sample JSON. How can I fix this?
Flask code:
app = Flask(__name__)
@app.route("/")
def index():
return '<h1>Flask Running</h>'
college_model = joblib.load("college_model.pkl")
column_trans = make_column_transformer(
(OneHotEncoder(), ['type_school','school_accreditation',
'gender','interest','residence','parent_was_in_college']),
remainder='passthrough')
@app.route('/college', methods=['POST'])
def prediction():
content = request.json
encode = column_trans.fit_transform(content)
pred = college_model.predict(encode)
pred = pred.tolist()
return jsonify(pred)
if __name__=='__main__':
app.run()
Sample JSON sent via Postman:
{"type_school": "Academic",
"school_accreditation": "A",
"gender": "Male",
"interest": "Less Interested",
"residence": "Urban",
"parent_age": 56,
"parent_salary": 76000,
"house_area": 83.09,
"average_grades": 85,
"parent_was_in_college": false
}