Upload app.py
Browse files
app.py
CHANGED
|
@@ -49,24 +49,18 @@ app = FastAPI(title="Medicare Fraud Prediction API")
|
|
| 49 |
|
| 50 |
@app.post("/predict")
|
| 51 |
def predict_fraud(data: ClaimData):
|
|
|
|
| 52 |
df = pd.DataFrame([data.dict()])
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
# build a fresh DataFrame with ONLY these columns & names
|
| 59 |
-
scaled = pd.DataFrame(
|
| 60 |
-
scaler.transform(df[cols].to_numpy()),
|
| 61 |
-
columns=cols
|
| 62 |
-
)
|
| 63 |
-
|
| 64 |
-
# replace the three columns with their scaled versions
|
| 65 |
-
for c in cols:
|
| 66 |
-
df[c] = scaled[c]
|
| 67 |
|
|
|
|
| 68 |
pred = model.predict(df)[0]
|
| 69 |
-
|
|
|
|
|
|
|
| 70 |
|
| 71 |
@app.get("/")
|
| 72 |
def root():
|
|
|
|
| 49 |
|
| 50 |
@app.post("/predict")
|
| 51 |
def predict_fraud(data: ClaimData):
|
| 52 |
+
# Convert input to DataFrame
|
| 53 |
df = pd.DataFrame([data.dict()])
|
| 54 |
|
| 55 |
+
# Scale only the relevant columns
|
| 56 |
+
columns_to_scale = ['OPAnnualReimbursementAmt','OPAnnualDeductibleAmt','DeductibleAmtPaid']
|
| 57 |
+
df[columns_to_scale] = scaler.transform(df[columns_to_scale])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
# Predict
|
| 60 |
pred = model.predict(df)[0]
|
| 61 |
+
result = "Fraud" if pred == 1 else "Not Fraud"
|
| 62 |
+
|
| 63 |
+
return {"prediction": result}
|
| 64 |
|
| 65 |
@app.get("/")
|
| 66 |
def root():
|