-
Notifications
You must be signed in to change notification settings - Fork 0
/
inference.py
67 lines (55 loc) · 1.71 KB
/
inference.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# !/usr/bin/env python
# coding: utf-8
#
# In[ ]:
#
from pandas import DataFrame
from preprocessing_classification import *
from joblib import load
BEST_MODEL_PATH = "resources/best_model.pkl"
model = load(BEST_MODEL_PATH)
def inference(path):
'''
path: a DataFrame
result is the output of function which should be
somethe like: [0,1,1,1,0]
0 -> Lost
1 -> Won
'''
result = []
dataset = read_data(path)
deal_class = dataset['Stage']
# ''''''
# first = []
# list_prediction = list(dataset['Stage'])
# for a in list_prediction:
# if a == 'Won':
# first.append(1)
# elif a == 'Lost':
# first.append(0)
# else:
# first.append(3)
# print(first)
# '''''
dataset = preprocess(dataset)
dataset = new_feature(dataset)
# get products
dataset = dataset.drop(['Customer', 'Agent', 'SalesAgentEmailID', 'ContactEmailID',
'Created Date', 'Close Date', 'avg_sale_cyc', 'Stage'], axis=1)
# dataset = dataset.drop(['Customer', 'Agent', 'SalesAgentEmailID', 'ContactEmailID',
# 'Created Date', 'Close Date', 'avg_sale_cyc'], axis=1)
# s = (dataset.dtypes == 'object')
# products = list(s[s].index)
# dataset = encoder(dataset, products)
dataset = dataset.join(pd.get_dummies(dataset['Product'])).drop('Product', axis=1)
pred = model.predict(dataset)
list_prediction = list(pred)
for a in list_prediction:
if a == 'Won':
result.append(1)
else:
result.append(0)
print(result)
print('Accuracy:\n', accuracy_score(deal_class, pred), end='\n\n')
return result
inference("test.xls")