-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTOPS_Prediction.py
More file actions
157 lines (117 loc) · 5.69 KB
/
Copy pathTOPS_Prediction.py
File metadata and controls
157 lines (117 loc) · 5.69 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 08 17:39:02 2018
@author: velmurugan.m
"""
import pickle
import pandas as pd
from nltk import word_tokenize
import re
from sklearn.feature_extraction.text import TfidfVectorizer
from nltk.corpus import stopwords
from nltk.stem import WordNetLemmatizer
targetList = (
'Check & work the order',
'Check the Billing/Dir/Order for active TN #',
'Create the Record in 2nd Drop',
'Disconnect & Create Record in the location',
'Hold the order until response',
'Proceed with Change Process ',
'Cancel the order'
)
DATA_LOCATION = 'D:\Winstream_data\TOPS\FAS_4.xlsx'
stop_words = set(stopwords.words('english'))
wordnet_lemmatizer = WordNetLemmatizer()
def funcForValidatingWholeSet(respData):
lookup_dict = {
'svc' : 'service',
'svr' : 'service',
'cus' : 'customer',
'cust' : 'customer',
'actv' : 'active',
'2nd' : 'second',
'addtl' : 'additional',
'autod' : 'autodialer',
'ialer' : 'dialer',
'auto-dialer': 'autodialer',
'rdy' : 'ready',
'loc' : 'location',
'dup' : 'duplicate'
}
newRespData = []
for line in respData:
tokens = word_tokenize( (str(line )).lower() )
tokens = tokens[2:]
newVal = map( lambda val: lookup_dict[val] if val in lookup_dict else val, tokens )
remDate = filter( lambda ThisWord: not re.match('^(?:(?:[0-9]{1,2}[:\/,]){1,2}[0-9]{1,4})$', ThisWord), newVal)
remInt = filter( lambda ThisWord: not re.match('^(\d{1,10}|\d{12})$', ThisWord), remDate)
remSplCh = filter( lambda ThisWord: not re.match('[^ a-zA-Z0-9]', ThisWord), remInt)
remDat = filter( lambda ThisWord: not re.match("(u')", ThisWord), remSplCh)
filSen = [w for w in remDat if not w in stop_words]
newLine = " ".join(filSen)
newRespData.append(newLine)
newRespDataSeries = pd.Series( newRespData )
return (newRespDataSeries)
def readFormatData(inputText):
lookup_dict = {
'svc' : 'service',
'svr' : 'service',
'cus' : 'customer',
'cust' : 'customer',
'actv' : 'active',
'2nd' : 'second',
'addtl' : 'additional',
'autod' : 'autodialer',
'ialer' : 'dialer',
'auto-dialer': 'autodialer',
'rdy' : 'ready',
'loc' : 'location',
'hses' : 'houses',
'dup' : 'duplicate'
}
tokens = word_tokenize( (str(inputText )).lower() )
tokens = tokens[2:]
newVal = map( lambda val: lookup_dict[val] if val in lookup_dict else val, tokens )
remDate = filter( lambda ThisWord: not re.match('^(?:(?:[0-9]{1,2}[:\/,]){1,2}[0-9]{1,4})$', ThisWord), newVal)
remInt = filter( lambda ThisWord: not re.match('^(\d{1,10}|\d{12})$', ThisWord), remDate)
remSplCh = filter( lambda ThisWord: not re.match('[^ a-zA-Z0-9]', ThisWord), remInt)
remDat = filter( lambda ThisWord: not re.match("(u')", ThisWord), remSplCh)
filSen = [w for w in remDat if not w in stop_words]
lemWord = map( wordnet_lemmatizer.lemmatize, filSen)
newLine = " ".join(lemWord)
newRespDataSeries = pd.Series( newLine )
return newRespDataSeries
def processData(respData):
filename = "D:\Windstream_ML\Models\WindTOPSRandForest.pkl"
tfidfFile = "D:\Windstream_ML\Models\WindTOPSTFIDF.pkl"
TOPSRandFor = open(filename, 'rb')
TFIDFFile = open(tfidfFile, 'rb')
randForest = pickle.load(TOPSRandFor)
TOPSRandFor.close()
vectorize = pickle.load(TFIDFFile)
TFIDFFile.close()
#test = "11/1/2017 SGriffith added to autodialer to get cust to call us to confirm address/apt or lot#/multiple hses @ loc/additional svc/etc. put order in cust action 010118 dd 0 wu simple wkfr. 1172 I01148 CUS-ACTION 172-6039 OCTAVIA U CALLAWAY || -"
cleanData = readFormatData(respData)
vectData = vectorize.transform(cleanData)
output = randForest.predict(vectData)
outText = targetList[output-1]
return outText
#### For TOPS Bulk Data ###################################################
'''
orgDataFrame = pd.read_excel(DATA_LOCATION, sheetname='Sheet1').iloc[2001:2675]
respData = orgDataFrame[orgDataFrame.columns[5]]
newOutput = []
for val in respData:
cleanData = readFormatData(val)
vectData = vectorize.transform(cleanData)
output = randForest.predict(vectData)
outText = targetList[output-1]
newOutput.append(outText)
newDataFr = pd.DataFrame({'Response Data': respData, 'Manual Action Taken': newOutput})
newDataFr.to_csv("predictdOut.csv")
#return targetList[output-1]
'''
#def main():
# processData()
#if __name__ == "__main__":
# main()