-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExample.py
More file actions
32 lines (16 loc) · 722 Bytes
/
Example.py
File metadata and controls
32 lines (16 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pandas as pd # pandas to dataframe handle
from ForecastingML import bestForecastModel # Machine learning algorithm
from sklearn.externals import joblib # joblib library
df=pd.read_csv('insurance.csv',sep=',')
cat1={'southwest':1,'southeast':2,'northwest':3,'northeast':4}
df['region']=df['region'].map(cat1)
cat2={'yes':1,'no':2}
df['smoker']=df['smoker'].map(cat2)
cat3={'female':1,'male':2}
df['sex']=df['sex'].map(cat3)
label=df['charges']
df.drop(['charges'], axis=1, inplace=True)
# Here the best model and his score are saved in a and b respectively and then
# the model is saved into a file named <bestForcastModel.pkl>
a,b=bestForecastModel(df,label)
joblib.dump(a, 'bestForecastModel.pkl')