-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_story_predict.py
65 lines (55 loc) · 2.37 KB
/
user_story_predict.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
from jira import JIRA
import json
import operator
def define_input(prediction_df, username, password, number):
auth_jira = JIRA(server='https://intelex.atlassian.net', auth=(username, password))
issue = auth_jira.issue(number)
print('Manual prediction was: `', issue.fields.customfield_10049, '`')
for column in prediction_df.columns:
if 'ML-' in column:
prediction_df.loc[0, column] = 0
for label in issue.fields.labels:
if 'ML-' in label:
prediction_df.loc[0, label] = 1
print('Predicting points for `', issue.fields.summary, '` User Story.')
print('With ' + str(issue.fields.labels) + ' labels ')
return prediction_df
def one_hot_decode(coded):
decoded = coded.dot([1, 2,3,5,8]).astype(int)
try:
decoded[:] = [1 if x == 0 else 8 if x > 8 else x for x in decoded]
except TypeError:
return 1 if decoded == 0 else 8 if decoded > 8 else decoded
return decoded
def _fibonacci(n):
if n == 0: return 0
elif n == 1: return 1
else: return _fibonacci(n-1)+_fibonacci(n-2)
def predict_points(classifier, prediction_df):
# try:
estimator = classifier.best_estimator_.estimators_[0]
result = {}
predict = classifier.predict(prediction_df)
if hasattr(estimator, 'predict_proba'):
predict_prop = classifier.predict_proba(prediction_df)
index, value = max(enumerate(predict_prop[0]), key=operator.itemgetter(1))
predicted_point = _fibonacci(index+2)
possibility = round(value,2)*100
print('[',type(estimator).__name__, '] prediction is:',
predicted_point, ' points with ', possibility,'% probability')
result['prediction'] = str(predicted_point)
result['probability'] = str(possibility)
result['status'] = 'Ok'
return result
#return {"prediction": predicted_point, "probability":possibility, "status": "Ok"}
else:
prediction = one_hot_decode(predict)[0]
print('[',type(estimator).__name__, '] prediction is: ', prediction, ' points')
result['prediction'] = str(prediction)
result['probability'] = "100"
result['status'] = 'Ok'
return result
#return {"prediction": prediction, "probability":100, "status": "Ok"}
# except Exception, e:
# return {"prediction": -1, "probability": -1, "status": str(e)}
# raise