I am currently building an API using FastAPI to deploy my logistic regression model. For some reason, I am getting the above error in the server docs when I test the model.
My code below:
app = FastAPI()
class PatientAttendance(BaseModel):
apptslotduration: int
patientage: int
log_distance: float
pct_appts_missed: float
doc_no_show_rate: float
zip_no_show_rate: float
note_no_show_rate: float
type_no_show_rate: float
spec_type_no_show_rate: float
monthly_no_show_rate: float
seasonal_no_show_rate: float
dow_no_show_rate: float
clinic_no_show_rate: float
lead_time_in_days: int
groupedstarttime: int
priminsurance_no_show_rate: float
secondinsurance_no_show_rate: float
@app.post('/predict/')
def predict(features: PatientAttendance):
data = features
prediction = model.predict([[data]])
if prediction[0] == 0:
result = "Patient Show"
else:
result = "No-Show"
probability = model.predict_proba([[data]])
return {
'prediction': prediction,
'probability': probability
}
if __name__ == '__main__':
uvicorn.run(app, host="127.0.0.1", port=8000)
The error:
TypeError: float() argument must be a string or a number, not 'PatientAttendance'
I am using a Pydantic BaseModel and I have no idea why I am receiving this error. I believe I have the app pointing in the right direction with respect to the server. I've tried utilizing GET
& POST
. features
is the array of features in my dataset that I standardized and turned into a dictionary. All the features have been vectorized. I always seem to get some type of error whenever I test my API in the server docs.