-
-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b9948d
commit 2c19720
Showing
6 changed files
with
630 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
.env | ||
delta_lake* | ||
employees | ||
mlruns | ||
mlruns | ||
*.joblib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from fastapi import FastAPI | ||
import joblib | ||
import pandas as pd | ||
|
||
# Create a FastAPI application instance | ||
app = FastAPI() | ||
|
||
# Load the pre-trained machine learning model | ||
model = joblib.load("lr.joblib") | ||
|
||
# Define a POST endpoint for making predictions | ||
@app.post("/predict/") | ||
def predict(data: list[float]): | ||
# Define the column names for the input features | ||
columns = [ | ||
"MedInc", | ||
"HouseAge", | ||
"AveRooms", | ||
"AveBedrms", | ||
"Population", | ||
"AveOccup", | ||
"Latitude", | ||
"Longitude", | ||
] | ||
|
||
# Create a pandas DataFrame from the input data | ||
features = pd.DataFrame([data], columns=columns) | ||
|
||
# Use the model to make a prediction | ||
prediction = model.predict(features)[0] | ||
|
||
# Return the prediction as a JSON object, rounding to 2 decimal places | ||
return {"price": round(prediction, 2)} |
Oops, something went wrong.