Spaces:
Sleeping
Sleeping
Commit
•
5d0ffab
1
Parent(s):
9fd673d
Upload 5 files
Browse files- Dockerfile +9 -0
- best_rf_mobel.joblib +3 -0
- main.py +46 -0
- requirements.txt +43 -0
- transform_encode.joblib +3 -0
Dockerfile
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.10
|
2 |
+
|
3 |
+
WORKDIR /app
|
4 |
+
|
5 |
+
COPY . /app
|
6 |
+
|
7 |
+
RUN pip install -r requirements.txt
|
8 |
+
|
9 |
+
CMD [ "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
|
best_rf_mobel.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b574aecf20cb4daf5ce0e1aa144a826e3d53658bbda82fcc1f3733b014fd9fa4
|
3 |
+
size 248982025
|
main.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, Query, HTTPException
|
2 |
+
import joblib
|
3 |
+
from pydantic import BaseModel
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
|
7 |
+
|
8 |
+
encoder = joblib.load('./transform_encode.joblib')
|
9 |
+
model = joblib.load('./best_rf_mobel.joblib')
|
10 |
+
|
11 |
+
app = FastAPI()
|
12 |
+
|
13 |
+
|
14 |
+
class features(BaseModel):
|
15 |
+
tenure:str
|
16 |
+
montant: float
|
17 |
+
frequence_rech: float
|
18 |
+
revenue: float
|
19 |
+
arpu_segment: float
|
20 |
+
frequence: float
|
21 |
+
data_volume: float
|
22 |
+
on_net: float
|
23 |
+
orange: float
|
24 |
+
tigo: float
|
25 |
+
regularity: int
|
26 |
+
|
27 |
+
|
28 |
+
@app.post("/predict")
|
29 |
+
async def predict_sepsis(item: features):
|
30 |
+
try:
|
31 |
+
# Convert input data to DataFrame
|
32 |
+
input_data = pd.DataFrame([item.dict()])
|
33 |
+
|
34 |
+
input_data = encoder.transform(input_data)
|
35 |
+
|
36 |
+
# Make predictions using the model
|
37 |
+
predictions = model.predict(input_data)
|
38 |
+
|
39 |
+
# Determine churn likelihood message
|
40 |
+
churn_likelihood = "Customer is more likely to churn." if predictions[0] == 1 else "Customer is less likely to churn."
|
41 |
+
|
42 |
+
return {"prediction": f'Churn is {predictions[0]}. {churn_likelihood}'}
|
43 |
+
|
44 |
+
|
45 |
+
except Exception as e:
|
46 |
+
raise HTTPException(status_code=500, detail=str(e))
|
requirements.txt
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
annotated-types==0.6.0
|
2 |
+
anyio==3.7.1
|
3 |
+
certifi==2023.11.17
|
4 |
+
click==8.1.7
|
5 |
+
colorama==0.4.6
|
6 |
+
dnspython==2.4.2
|
7 |
+
email-validator==2.1.0.post1
|
8 |
+
fastapi==0.104.1
|
9 |
+
h11==0.14.0
|
10 |
+
httpcore==1.0.2
|
11 |
+
httptools==0.6.1
|
12 |
+
httpx==0.25.2
|
13 |
+
idna==3.6
|
14 |
+
install==1.3.5
|
15 |
+
itsdangerous==2.1.2
|
16 |
+
Jinja2==3.1.2
|
17 |
+
joblib==1.3.2
|
18 |
+
MarkupSafe==2.1.3
|
19 |
+
numpy==1.26.2
|
20 |
+
orjson==3.9.10
|
21 |
+
pandas==2.1.3
|
22 |
+
pydantic==2.5.2
|
23 |
+
pydantic-extra-types==2.1.0
|
24 |
+
pydantic-settings==2.1.0
|
25 |
+
pydantic_core==2.14.5
|
26 |
+
python-dateutil==2.8.2
|
27 |
+
python-dotenv==1.0.0
|
28 |
+
python-multipart==0.0.6
|
29 |
+
pytz==2023.3.post1
|
30 |
+
PyYAML==6.0.1
|
31 |
+
scikit-learn==1.3.0
|
32 |
+
scipy==1.11.4
|
33 |
+
six==1.16.0
|
34 |
+
sniffio==1.3.0
|
35 |
+
starlette==0.27.0
|
36 |
+
threadpoolctl==3.2.0
|
37 |
+
typing_extensions==4.8.0
|
38 |
+
tzdata==2023.3
|
39 |
+
ujson==5.8.0
|
40 |
+
uvicorn==0.24.0.post1
|
41 |
+
watchfiles==0.21.0
|
42 |
+
websockets==12.0
|
43 |
+
xgboost==2.0.2
|
transform_encode.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:da76ecd15063d4c0dea09e843d2b5112f250a1fa6e03bac4d47a5db81e44fbbf
|
3 |
+
size 4104
|