Spaces:
Sleeping
Sleeping
feat: model
Browse files- README.md +1 -1
- models/HealthInsurance.py +58 -0
- models/__init__.py +1 -0
- models/__pycache__/HealthInsurance.cpython-310.pyc +0 -0
- models/__pycache__/__init__.cpython-310.pyc +0 -0
- parameters/bins_annual_premium_type.joblib +3 -0
- parameters/column_transformer.joblib +3 -0
- parameters/random_forrest.gz +3 -0
- requirements.txt +23 -0
README.md
CHANGED
@@ -9,4 +9,4 @@ app_file: app.py
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
-
|
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
This repository contains an implementation of an App for a health insurance machine learning model.
|
models/HealthInsurance.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
|
5 |
+
class HealthInsurance():
|
6 |
+
|
7 |
+
def __init__(self, model, column_transformer, bins_annual_premium_type):
|
8 |
+
"""model : the sklearn model already trainned.
|
9 |
+
colums_transformer : the column transformer with all transformations.
|
10 |
+
bins_annual_premium_type : bins to create annual_premium_type feature"""
|
11 |
+
|
12 |
+
self.model = model
|
13 |
+
self.transformer = column_transformer
|
14 |
+
self.bins_annual_premium_type = bins_annual_premium_type
|
15 |
+
|
16 |
+
|
17 |
+
def feature_engineering(self, df):
|
18 |
+
premium_categories = ['very_low', 'low', 'moderate', 'high', 'very_high']
|
19 |
+
|
20 |
+
df['vehicle_age'] = df['vehicle_age'].apply(self.get_vehicle_age)
|
21 |
+
df['annual_premium_type'] = pd.cut(x = df['annual_premium'],
|
22 |
+
bins = self.bins_annual_premium_type,
|
23 |
+
labels = premium_categories)
|
24 |
+
return df
|
25 |
+
|
26 |
+
def get_vehicle_age(self, vehicle_age):
|
27 |
+
|
28 |
+
vehicle_labels = {
|
29 |
+
'> 2 Years' : 'over_2_years',
|
30 |
+
'1-2 Year' : 'between_1_2_year',
|
31 |
+
'< 1 Year' : 'below_1_year'
|
32 |
+
}
|
33 |
+
|
34 |
+
return vehicle_labels.get(vehicle_age)
|
35 |
+
|
36 |
+
def data_preparation(self, df):
|
37 |
+
return self.transformer.transform(df)
|
38 |
+
|
39 |
+
def predict(self, payload):
|
40 |
+
df = pd.read_json(payload, orient='records')
|
41 |
+
|
42 |
+
np_array = (df.pipe(self.feature_engineering)
|
43 |
+
.pipe(self.data_preparation)
|
44 |
+
)
|
45 |
+
|
46 |
+
df['score'] = self.model.predict_proba(np_array)[:, 1]
|
47 |
+
|
48 |
+
return df.to_json(orient='records')
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
|
57 |
+
|
58 |
+
|
models/__init__.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
from .HealthInsurance import HealthInsurance
|
models/__pycache__/HealthInsurance.cpython-310.pyc
ADDED
Binary file (1.93 kB). View file
|
|
models/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (217 Bytes). View file
|
|
parameters/bins_annual_premium_type.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e42fdac17630e21c47134283f0690ec69c912e2b9dbd0fd68baaef6319d847ee
|
3 |
+
size 231
|
parameters/column_transformer.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ed9a96c0f7a377578494f6157cfc6ee49b27ac5c1b9ac4cff4b349297d3776cd
|
3 |
+
size 22746
|
parameters/random_forrest.gz
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4d4ffc09d8834ea81a6006d495db91f41621adfff13847c7930f273d7e1ebcf4
|
3 |
+
size 86534189
|
requirements.txt
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
category-encoders==2.5.0
|
2 |
+
click==8.1.3
|
3 |
+
deprecation==2.1.0
|
4 |
+
Flask==2.2.2
|
5 |
+
itsdangerous==2.1.2
|
6 |
+
Jinja2==3.1.2
|
7 |
+
joblib==1.1.0
|
8 |
+
MarkupSafe==2.1.1
|
9 |
+
numpy==1.23.2
|
10 |
+
packaging==21.3
|
11 |
+
pandas==1.4.4
|
12 |
+
patsy==0.5.2
|
13 |
+
pyparsing==3.0.9
|
14 |
+
python-dateutil==2.8.2
|
15 |
+
pytz==2022.2.1
|
16 |
+
scikit-learn==1.1.2
|
17 |
+
scipy==1.9.1
|
18 |
+
six==1.16.0
|
19 |
+
sklearn==0.0
|
20 |
+
statsmodels==0.13.2
|
21 |
+
threadpoolctl==3.1.0
|
22 |
+
watchdog==2.1.9
|
23 |
+
Werkzeug==2.2.2
|