Enyonam commited on
Commit
0349011
·
1 Parent(s): 731df44

Upload 3 files

Browse files
Files changed (3) hide show
  1. main.py +61 -0
  2. pipeline.joblib +3 -0
  3. requirements.txt +8 -0
main.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ import joblib
4
+ import pandas as pd
5
+ import numpy as np
6
+ from sklearn.preprocessing import StandardScaler
7
+ from sklearn.impute import SimpleImputer
8
+ from sklearn.compose import ColumnTransformer
9
+ from sklearn.pipeline import Pipeline
10
+ from sklearn.linear_model import LogisticRegression
11
+
12
+ app = FastAPI()
13
+
14
+ # Load the entire pipeline
15
+ pipeline_filepath = "pipeline.joblib"
16
+ pipeline = joblib.load(pipeline_filepath)
17
+
18
+ class PatientData(BaseModel):
19
+ Plasma_glucose : float
20
+ Blood_Work_Result_1: float
21
+ Blood_Pressure : float
22
+ Blood_Work_Result_2 : float
23
+ Blood_Work_Result_3 : float
24
+ Body_mass_index : float
25
+ Blood_Work_Result_4: float
26
+ Age: float
27
+ Insurance: int
28
+
29
+ @app.get("/")
30
+ def read_root():
31
+ explanation = {
32
+ 'message': "Welcome to the Sepsis Prediction App",
33
+ 'description': "This API allows you to predict sepsis based on patient data.",
34
+ 'usage': "Submit a POST request to /predict with patient data to make predictions.",
35
+
36
+ }
37
+ return explanation
38
+
39
+ @app.post("/predict")
40
+ def get_data_from_user(data: PatientData):
41
+ user_input = data.dict()
42
+
43
+ input_df = pd.DataFrame([user_input])
44
+
45
+ # Make predictions using the loaded pipeline
46
+ prediction = pipeline.predict(input_df)
47
+ probabilities = pipeline.predict_proba(input_df)
48
+
49
+
50
+ probability_of_positive_class = probabilities[0][1]
51
+
52
+ # Calculate the prediction
53
+ sepsis_status = "Positive" if prediction[0] == 1 else "Negative"
54
+ sepsis_explanation = "A positive prediction suggests that the patient might be exhibiting sepsis symptoms and requires immediate medical attention." if prediction[0] == 1 else "A negative prediction suggests that the patient is not currently exhibiting sepsis symptoms."
55
+
56
+ result = {
57
+ 'predicted_sepsis': sepsis_status,
58
+ 'probability': probability_of_positive_class,
59
+ 'sepsis_explanation': sepsis_explanation
60
+ }
61
+ return result
pipeline.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:74f69ea3c16f9dfa66dd5738523b19ebb4db2c17f0af741730f7a5b24e16a0be
3
+ size 27955
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ pytest
2
+ scikit-learn
3
+ fastapi[all]
4
+ pydantic
5
+ uvicorn
6
+ pandas
7
+ numpy
8
+ joblib