Skip to content
Snippets Groups Projects
Commit 3315ccd8 authored by Christian Marius Lillelund's avatar Christian Marius Lillelund
Browse files

added arguments to api response

parent e082ec9a
No related branches found
No related tags found
No related merge requests found
Pipeline #77117 passed
......@@ -94,6 +94,7 @@ class OutputData(pydantic.BaseModel):
FallShapValues: dict
ClusterId: int
ClusterValues: List
Arguments: List
@app.get('/')
def index():
......@@ -173,6 +174,7 @@ def predict(incoming_data: InputData):
raise HTTPException(status_code=400, detail="Ats not found, check ats list")
df = prepare_data(data)
arguments = generate_arguments(df)
complete_model = read_joblib(f'complete_xgboost.joblib')
compliance_model = read_joblib(f'compliance_xgboost.joblib')
......@@ -205,6 +207,7 @@ def predict(incoming_data: InputData):
'FallShapValues': fall_shap_values,
'ClusterId': int(df.iloc[0]['Cluster']),
'ClusterValues': cluster_values,
'Arguments': arguments
}
def add_embeddings(df: pd.DataFrame, case: str) -> pd.DataFrame:
......@@ -215,6 +218,14 @@ def add_embeddings(df: pd.DataFrame, case: str) -> pd.DataFrame:
df[column] = pd.to_numeric(df[column])
return df
def generate_arguments(df: pd.DataFrame):
gender = 'kvinde' if df.iloc[0].Gender_Male == 0 else 'mand'
arguments = list({f'Personen er en {gender}',
f'Personen er {int(121 - df.iloc[0].BirthYear)} år gammel',
f'Personen har i gennemsnit lånt hjælpemidler i {int(df.iloc[0].LoanPeriod)} dage',
f'Personen har {int(df.iloc[0].NumberAts)} hjælpemidler i hjemmet'})
return arguments
def prepare_data(data: dict) -> pd.DataFrame:
new_data = {k: [v] for k, v in data.items()}
new_data_df = pd.DataFrame.from_dict(new_data)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment