Spaces:
Sleeping
Sleeping
Q-b1t
commited on
Commit
·
73481a7
1
Parent(s):
51996af
initial commit
Browse files- .gitattributes +2 -0
- README.md +1 -1
- app.py +67 -0
- assets/column_transformer.joblib +3 -0
- assets/insurance_regression_model.keras +3 -0
- requirements.txt +6 -0
.gitattributes
CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
assets/insurance_regression_model.keras filter=lfs diff=lfs merge=lfs -text
|
37 |
+
assets/column_transformer.joblib filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
title: Insurance Regression
|
3 |
-
emoji:
|
4 |
colorFrom: green
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
|
|
1 |
---
|
2 |
title: Insurance Regression
|
3 |
+
emoji: 🏥
|
4 |
colorFrom: green
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
app.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import pandas as pd
|
3 |
+
from joblib import load
|
4 |
+
import gradio as gr
|
5 |
+
from tensorflow.keras.models import load_model
|
6 |
+
|
7 |
+
|
8 |
+
# filepaths
|
9 |
+
column_transform_path = "assets/column_transformer.joblib" # change during the creation of the huggingface app
|
10 |
+
model_path = "assets/insurance_regression_model.keras" # change during the creation of the huggingface app
|
11 |
+
|
12 |
+
# instance the models
|
13 |
+
column_transformer = load(column_transform_path)
|
14 |
+
insurance_model = load_model(model_path)
|
15 |
+
|
16 |
+
# short description of the stuff
|
17 |
+
title = "Insurance Regressor Model"
|
18 |
+
description = "POC of a deep learning regression model for estimating insurance charges based on 11 input variables."
|
19 |
+
article = "The model was implemented in tensorflow. It is simple as i made it as a refresher for reviewing the Tensorflow fundamentals (the problem most likely could be solved using classical regression). The dataset used was [Medical Cost Personal Datasets](https://www.kaggle.com/datasets/mirichoi0218/insurance)."
|
20 |
+
|
21 |
+
# processing function
|
22 |
+
def insurance_prediction(age,gender,bmi,children,smoker,region):
|
23 |
+
columns = ['age', 'sex', 'bmi', 'children', 'smoker', 'region']
|
24 |
+
# transform some data to the datatypes compatible with column transfomer
|
25 |
+
age = int(age)
|
26 |
+
gender = "male" if gender else "female"
|
27 |
+
children = int(children)
|
28 |
+
smoker = "yes" if smoker else "no"
|
29 |
+
region = region[0] if len(region) > 0 else 'northeast' # since it is a proof of concept, i left the value there.
|
30 |
+
# arange the values into a list
|
31 |
+
values = [age,gender,bmi,children,smoker,region]
|
32 |
+
# create a dictionary to structure the sample at hand
|
33 |
+
sample = {k:v for k,v in zip(columns,values)}
|
34 |
+
# create a dataframe using the sample
|
35 |
+
X = pd.DataFrame(data = pd.Series(sample)).T
|
36 |
+
# preprocess the dataframe
|
37 |
+
X_preprocessed = column_transformer.transform(X)
|
38 |
+
# make the prediction accordingly
|
39 |
+
y_pred = insurance_model.predict(X_preprocessed)
|
40 |
+
return y_pred[0][0]
|
41 |
+
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
demo = gr.Interface(
|
47 |
+
fn = insurance_prediction,
|
48 |
+
inputs = [
|
49 |
+
gr.Number(value = 40,label = "Age",show_label=True),
|
50 |
+
gr.Checkbox(value = False,label = "Male",show_label = True),
|
51 |
+
gr.Number(value = 30,label = "Body Mass Index",show_label=True),
|
52 |
+
gr.Number(value = 1,label = "Number of Children",show_label=True),
|
53 |
+
gr.Checkbox(value = False,label = "Smoker",show_label = True),
|
54 |
+
gr.CheckboxGroup(choices = ['northeast', 'northwest', 'southeast', 'southwest'],
|
55 |
+
value = ['northeast', 'northwest', 'southeast', 'southwest'],
|
56 |
+
label="Region",
|
57 |
+
info="Will only take into consideration the fist one selected.")
|
58 |
+
],
|
59 |
+
outputs = [
|
60 |
+
gr.Number(label = "Insurance Charges Estimate (American Dollars)")
|
61 |
+
],
|
62 |
+
title = title,
|
63 |
+
description = description,
|
64 |
+
article = article
|
65 |
+
)
|
66 |
+
|
67 |
+
demo.launch()
|
assets/column_transformer.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d53d73e17da5e8fb4822f307772383138631fa489d251d7844071d87e5a0a0e2
|
3 |
+
size 3503
|
assets/insurance_regression_model.keras
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:291424b48786654966fe4dd77332444458cd5e33793872ea1bec708b9db3ccd8
|
3 |
+
size 78752
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow==2.12.0
|
2 |
+
gradio==3.39.0
|
3 |
+
pandas==1.5.3
|
4 |
+
numpy==1.23.5
|
5 |
+
scikit-learn==1.2.2
|
6 |
+
joblib==1.3.1
|