-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli_main.py
90 lines (76 loc) · 2.59 KB
/
cli_main.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# class InvalidInput(Exception):
# def __init__(self) -> None:
# self.message = 'Enter INTEGERS value only '
# def __str__(self):
# return f"MESSAGE : {self.message}"
def importmodel():
import pickle
with open('model', 'rb') as file: #.\irisTRAINEDmodel\
model = pickle.load(file)
return model
def floatinput():
"""
['sepal length (cm)',
'sepal width (cm)',
'petal length (cm)',
'petal width (cm)']
sepal length: 4.3 7.9 5.84 0.83 0.7826
sepal width: 2.0 4.4 3.05 0.43 -0.4194
petal length: 1.0 6.9 3.76 1.76 0.9490 (high!)
petal width: 0.1 2.5 1.20 0.76 0.9565 (high!)
"""
# SEPAL_LENGHT
while True:
sepal_length = input('Enter sepal length (cm) : ')
try:
sepal_length =float(sepal_length)
break
except Exception as error:
print(error)
# SEPAL_WIDHT
while True:
sepal_width = input('Enter sepal width (cm) : ')
try:
sepal_width =float(sepal_width)
break
except Exception as error:
print(error)
# PATEL_LENGHT
while True:
petal_length = input('Enter petal length (cm) : ')
try:
petal_length =float(petal_length)
break
except Exception as error:
print(error)
# PATEL_WIDHT
while True:
petal_width = input('Enter petal_width (cm) : ')
try:
petal_width =float(petal_width)
break
except Exception as error:
print(error)
# return sepal_length, sepal_width, petal_length, petal_width values
return sepal_length, sepal_width, petal_length, petal_width
def predictValue(model, sepal_length: str, sepal_width: str, petal_length: str, petal_width: str) -> str:
predictions = model.predict([[sepal_length, sepal_width, petal_length, petal_width]])
predictions = predictions[0]
# 0 : 'setosa', 1 : 'versicolor', 2 : 'virginica'
match predictions:
case 0:
return "setosa"
case 1:
return "versicolor"
case 2:
return "virginica"
case _:
...
def main():
Classifier = importmodel()
sepal_length, sepal_width, petal_length, petal_width = floatinput()
result = predictValue(Classifier, sepal_length,
sepal_width, petal_length, petal_width)
print(result)
if __name__ == "__main__":
main()