Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-226
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Anuththara K.G.S.N
2022-226
Commits
7f10080b
Commit
7f10080b
authored
May 16, 2022
by
Anuththara K.G.S.N
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload the Model
parent
50d89040
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
427 additions
and
0 deletions
+427
-0
Severity_Level_Prediction/Severity_Level_Prediction.py
Severity_Level_Prediction/Severity_Level_Prediction.py
+427
-0
No files found.
Severity_Level_Prediction/Severity_Level_Prediction.py
0 → 100644
View file @
7f10080b
#!/usr/bin/env python
# coding: utf-8
# Severity Level Prediction
# In[1]:
#Importing Libraries
from
mpl_toolkits.mplot3d
import
Axes3D
from
sklearn.preprocessing
import
StandardScaler
import
matplotlib.pyplot
as
plt
from
tkinter
import
*
import
numpy
as
np
import
pandas
as
pd
import
os
# In[2]:
#List of the symptoms is listed here in list l1.
l1
=
[
'Yeast_Visibility-ears,armpits,_or_paws'
,
'Yeast_Visibility-around_half_of_the_body'
,
'Yeast_Visibility-whole_body'
,
'Redness-pink_or_red_skin'
,
'Redness-red_skin'
,
'Redness-gray_or_black_skin'
,
'No_unpleasant_Smell'
,
'Musty_smell'
,
'Extreme_musty_smell'
,
'No_Itching_and_Scratching'
,
'Itching_and_Scratching-time_to_time'
,
'Itching_and_Scratching-constantly'
,
'No_Thickened_Skin'
,
'Thickened_Skin'
,
'Extremely_Thickened_Skin(Elephant_skin_appearance)'
,
'No_Hair_Loss'
,
'Starting_Hair_Loss'
,
'Hair_Loss'
,
'No_Hearing_Issues'
,
'Hearing_Issues'
,
'Deafness'
]
# In[3]:
#List of Severity Levels.
level
=
[
'Primary'
,
'Secondary'
,
'Tertiary'
]
#level = [df['Prediction'].unique()]
# In[4]:
l2
=
[]
for
i
in
range
(
0
,
len
(
l1
)):
l2
.
append
(
0
)
print
(
l2
)
# In[5]:
#Reading the training.csv file
df
=
pd
.
read_csv
(
"severity level.csv"
)
DF
=
pd
.
read_csv
(
"severity level.csv"
,
index_col
=
'Prediction'
)
#Replace the values in the imported file by pandas by the inbuilt function replace in pandas.
df
.
replace
({
'Prediction'
:{
'Primary'
:
0
,
'Secondary'
:
1
,
'Tertiary'
:
2
}},
inplace
=
True
)
#df.head()
DF
.
head
()
# In[6]:
X
=
df
[
l1
]
y
=
df
[[
"Prediction"
]]
np
.
ravel
(
y
)
print
(
X
)
# In[7]:
#Reading the testing.csv file
tr
=
pd
.
read_csv
(
"testing.csv"
)
#Using inbuilt function replace in pandas for replacing the values
tr
.
replace
({
'Prediction'
:{
'Primary'
:
0
,
'Secondary'
:
1
,
'Tertiary'
:
2
}},
inplace
=
True
)
tr
.
head
()
# In[8]:
X_test
=
tr
[
l1
]
y_test
=
tr
[[
"Prediction"
]]
np
.
ravel
(
y_test
)
print
(
X_test
)
# In[9]:
print
(
y_test
)
# Decision Tree Algorithm
# In[10]:
root
=
Tk
()
pred1
=
StringVar
()
def
DecisionTree
():
if
len
(
NameEn
.
get
())
==
0
:
pred1
.
set
(
" "
)
comp
=
messagebox
.
askokcancel
(
"System"
,
"Please fill the breed of your pet !"
)
if
comp
:
root
.
mainloop
()
elif
((
Symptom1
.
get
()
==
"Select Here"
)
or
(
Symptom2
.
get
()
==
"Select Here"
)
):
pred1
.
set
(
" "
)
sym
=
messagebox
.
askokcancel
(
"System"
,
"Please fill atleast first two Symptoms"
)
if
sym
:
root
.
mainloop
()
else
:
from
sklearn
import
tree
clf3
=
tree
.
DecisionTreeClassifier
()
clf3
=
clf3
.
fit
(
X
,
y
)
from
sklearn.metrics
import
classification_report
,
confusion_matrix
,
accuracy_score
y_pred
=
clf3
.
predict
(
X_test
)
print
(
"Decision Tree"
)
print
(
"Accuracy"
)
print
(
accuracy_score
(
y_test
,
y_pred
))
print
(
accuracy_score
(
y_test
,
y_pred
,
normalize
=
False
))
print
(
"Confusion matrix"
)
conf_matrix
=
confusion_matrix
(
y_test
,
y_pred
)
print
(
conf_matrix
)
psymptoms
=
[
Symptom1
.
get
(),
Symptom2
.
get
(),
Symptom3
.
get
(),
Symptom4
.
get
(),
Symptom5
.
get
(),
Symptom6
.
get
(),
Symptom7
.
get
()]
for
k
in
range
(
0
,
len
(
l1
)):
for
z
in
psymptoms
:
if
(
z
==
l1
[
k
]):
l2
[
k
]
=
1
inputtest
=
[
l2
]
predict
=
clf3
.
predict
(
inputtest
)
predicted
=
predict
[
0
]
h
=
'no'
for
a
in
range
(
0
,
len
(
level
)):
if
(
predicted
==
a
):
h
=
'yes'
break
if
(
h
==
'yes'
):
pred1
.
set
(
" "
)
pred1
.
set
(
level
[
a
])
else
:
pred1
.
set
(
" "
)
pred1
.
set
(
"Not Found"
)
# Random Forest Algorithm
# In[11]:
pred2
=
StringVar
()
def
randomforest
():
if
len
(
NameEn
.
get
())
==
0
:
pred1
.
set
(
" "
)
comp
=
messagebox
.
askokcancel
(
"System"
,
"Please fill the breed of your pet !"
)
if
comp
:
root
.
mainloop
()
elif
((
Symptom1
.
get
()
==
"Select Here"
)
or
(
Symptom2
.
get
()
==
"Select Here"
)):
pred1
.
set
(
" "
)
sym
=
messagebox
.
askokcancel
(
"System"
,
"Please fill atleast first two Symptoms"
)
if
sym
:
root
.
mainloop
()
else
:
from
sklearn.ensemble
import
RandomForestClassifier
clf4
=
RandomForestClassifier
(
n_estimators
=
100
)
clf4
=
clf4
.
fit
(
X
,
np
.
ravel
(
y
))
# calculating accuracy
from
sklearn.metrics
import
classification_report
,
confusion_matrix
,
accuracy_score
y_pred
=
clf4
.
predict
(
X_test
)
print
(
"Random Forest"
)
print
(
"Accuracy"
)
print
(
accuracy_score
(
y_test
,
y_pred
))
print
(
accuracy_score
(
y_test
,
y_pred
,
normalize
=
False
))
print
(
"Confusion matrix"
)
conf_matrix
=
confusion_matrix
(
y_test
,
y_pred
)
print
(
conf_matrix
)
psymptoms
=
[
Symptom1
.
get
(),
Symptom2
.
get
(),
Symptom3
.
get
(),
Symptom4
.
get
(),
Symptom5
.
get
(),
Symptom6
.
get
(),
Symptom7
.
get
()]
for
k
in
range
(
0
,
len
(
l1
)):
for
z
in
psymptoms
:
if
(
z
==
l1
[
k
]):
l2
[
k
]
=
1
inputtest
=
[
l2
]
predict
=
clf4
.
predict
(
inputtest
)
predicted
=
predict
[
0
]
h
=
'no'
for
a
in
range
(
0
,
len
(
level
)):
if
(
predicted
==
a
):
h
=
'yes'
break
if
(
h
==
'yes'
):
pred2
.
set
(
" "
)
pred2
.
set
(
level
[
a
])
else
:
pred2
.
set
(
" "
)
pred2
.
set
(
"Not Found"
)
# Building Graphical User Interface
# In[12]:
#Tk class is used to create a root window
root
.
configure
(
background
=
'Ivory'
)
root
.
title
(
'Skin Disease Severity Level Predictor System'
)
root
.
resizable
(
0
,
0
)
# In[13]:
Symptom1
=
StringVar
()
Symptom1
.
set
(
"Select Here"
)
Symptom2
=
StringVar
()
Symptom2
.
set
(
"Select Here"
)
Symptom3
=
StringVar
()
Symptom3
.
set
(
"Select Here"
)
Symptom4
=
StringVar
()
Symptom4
.
set
(
"Select Here"
)
Symptom5
=
StringVar
()
Symptom5
.
set
(
"Select Here"
)
Symptom6
=
StringVar
()
Symptom6
.
set
(
"Select Here"
)
Symptom7
=
StringVar
()
Symptom7
.
set
(
"Select Here"
)
Name
=
StringVar
()
# In[14]:
prev_win
=
None
def
Reset
():
global
prev_win
Symptom1
.
set
(
"Select Here"
)
Symptom2
.
set
(
"Select Here"
)
Symptom3
.
set
(
"Select Here"
)
Symptom4
.
set
(
"Select Here"
)
Symptom5
.
set
(
"Select Here"
)
Symptom6
.
set
(
"Select Here"
)
Symptom7
.
set
(
"Select Here"
)
NameEn
.
delete
(
first
=
0
,
last
=
100
)
pred1
.
set
(
" "
)
pred2
.
set
(
" "
)
try
:
prev_win
.
destroy
()
prev_win
=
None
except
AttributeError
:
pass
# In[15]:
from
tkinter
import
messagebox
def
Exit
():
qExit
=
messagebox
.
askyesno
(
"System"
,
"Do you want to exit the system ?"
)
if
qExit
:
root
.
destroy
()
exit
()
# In[16]:
#Headings for the GUI written at the top of GUI
w2
=
Label
(
root
,
justify
=
LEFT
,
text
=
"Skin Disease Severity Level Prediction"
,
fg
=
"Black"
,
bg
=
"Ivory"
)
w2
.
config
(
font
=
(
"Times"
,
30
,
"bold"
))
w2
.
grid
(
row
=
1
,
column
=
0
,
columnspan
=
2
,
padx
=
100
)
# In[17]:
#Label for the name
NameLb
=
Label
(
root
,
text
=
"Breed of the Pet *"
,
fg
=
"Dark Blue"
,
bg
=
"Ivory"
)
NameLb
.
config
(
font
=
(
"Times"
,
15
,
"bold"
))
NameLb
.
grid
(
row
=
6
,
column
=
0
,
pady
=
15
,
sticky
=
W
)
# In[18]:
#Creating Labels for the symtoms
S1Lb
=
Label
(
root
,
text
=
"Symptom 1 *"
,
fg
=
"Black"
,
bg
=
"Ivory"
)
S1Lb
.
config
(
font
=
(
"Times"
,
15
,
"bold"
))
S1Lb
.
grid
(
row
=
7
,
column
=
0
,
pady
=
10
,
sticky
=
W
)
S2Lb
=
Label
(
root
,
text
=
"Symptom 2 *"
,
fg
=
"Black"
,
bg
=
"Ivory"
)
S2Lb
.
config
(
font
=
(
"Times"
,
15
,
"bold"
))
S2Lb
.
grid
(
row
=
8
,
column
=
0
,
pady
=
10
,
sticky
=
W
)
S3Lb
=
Label
(
root
,
text
=
"Symptom 3"
,
fg
=
"Black"
,
bg
=
"Ivory"
)
S3Lb
.
config
(
font
=
(
"Times"
,
15
,
"bold"
))
S3Lb
.
grid
(
row
=
9
,
column
=
0
,
pady
=
10
,
sticky
=
W
)
S4Lb
=
Label
(
root
,
text
=
"Symptom 4"
,
fg
=
"Black"
,
bg
=
"Ivory"
)
S4Lb
.
config
(
font
=
(
"Times"
,
15
,
"bold"
))
S4Lb
.
grid
(
row
=
10
,
column
=
0
,
pady
=
10
,
sticky
=
W
)
S5Lb
=
Label
(
root
,
text
=
"Symptom 5"
,
fg
=
"Black"
,
bg
=
"Ivory"
)
S5Lb
.
config
(
font
=
(
"Times"
,
15
,
"bold"
))
S5Lb
.
grid
(
row
=
11
,
column
=
0
,
pady
=
10
,
sticky
=
W
)
S6Lb
=
Label
(
root
,
text
=
"Symptom 6"
,
fg
=
"Black"
,
bg
=
"Ivory"
)
S6Lb
.
config
(
font
=
(
"Times"
,
15
,
"bold"
))
S6Lb
.
grid
(
row
=
12
,
column
=
0
,
pady
=
10
,
sticky
=
W
)
S7Lb
=
Label
(
root
,
text
=
"Symptom 7"
,
fg
=
"Black"
,
bg
=
"Ivory"
)
S7Lb
.
config
(
font
=
(
"Times"
,
15
,
"bold"
))
S7Lb
.
grid
(
row
=
13
,
column
=
0
,
pady
=
10
,
sticky
=
W
)
# In[19]:
#Labels for the different algorithms
lrLb
=
Label
(
root
,
text
=
"DecisionTree"
,
fg
=
"black"
,
bg
=
"Light blue"
,
width
=
20
)
lrLb
.
config
(
font
=
(
"Times"
,
15
,
"bold"
))
lrLb
.
grid
(
row
=
15
,
column
=
0
,
pady
=
10
,
sticky
=
W
)
destreeLb
=
Label
(
root
,
text
=
"RandomForest"
,
fg
=
"black"
,
bg
=
"Light blue"
,
width
=
20
)
destreeLb
.
config
(
font
=
(
"Times"
,
15
,
"bold"
))
destreeLb
.
grid
(
row
=
17
,
column
=
0
,
pady
=
10
,
sticky
=
W
)
OPTIONS
=
sorted
(
l1
)
# In[20]:
#Taking breed-name as input from user
NameEn
=
Entry
(
root
,
textvariable
=
Name
)
NameEn
.
grid
(
row
=
6
,
column
=
1
)
#Taking Symptoms as input from the dropdown from the user
S1
=
OptionMenu
(
root
,
Symptom1
,
*
OPTIONS
)
S1
.
grid
(
row
=
7
,
column
=
1
)
S2
=
OptionMenu
(
root
,
Symptom2
,
*
OPTIONS
)
S2
.
grid
(
row
=
8
,
column
=
1
)
S3
=
OptionMenu
(
root
,
Symptom3
,
*
OPTIONS
)
S3
.
grid
(
row
=
9
,
column
=
1
)
S4
=
OptionMenu
(
root
,
Symptom4
,
*
OPTIONS
)
S4
.
grid
(
row
=
10
,
column
=
1
)
S5
=
OptionMenu
(
root
,
Symptom5
,
*
OPTIONS
)
S5
.
grid
(
row
=
11
,
column
=
1
)
S6
=
OptionMenu
(
root
,
Symptom6
,
*
OPTIONS
)
S6
.
grid
(
row
=
12
,
column
=
1
)
S7
=
OptionMenu
(
root
,
Symptom7
,
*
OPTIONS
)
S7
.
grid
(
row
=
13
,
column
=
1
)
# In[21]:
#Buttons for predicting the severity level using different algorithms
dst
=
Button
(
root
,
text
=
"Prediction 1"
,
command
=
DecisionTree
,
bg
=
"Blue"
,
fg
=
"yellow"
)
dst
.
config
(
font
=
(
"Times"
,
15
,
"bold"
))
dst
.
grid
(
row
=
6
,
column
=
3
,
padx
=
10
)
rnf
=
Button
(
root
,
text
=
"Prediction 2"
,
command
=
randomforest
,
bg
=
"Blue"
,
fg
=
"yellow"
)
rnf
.
config
(
font
=
(
"Times"
,
15
,
"bold"
))
rnf
.
grid
(
row
=
7
,
column
=
3
,
padx
=
10
)
rs
=
Button
(
root
,
text
=
"Reset Inputs"
,
command
=
Reset
,
bg
=
"yellow"
,
fg
=
"purple"
,
width
=
12
)
rs
.
config
(
font
=
(
"Times"
,
15
,
"bold"
))
rs
.
grid
(
row
=
10
,
column
=
3
,
padx
=
10
)
ex
=
Button
(
root
,
text
=
"Exit System"
,
command
=
Exit
,
bg
=
"yellow"
,
fg
=
"purple"
,
width
=
12
)
ex
.
config
(
font
=
(
"Times"
,
15
,
"bold"
))
ex
.
grid
(
row
=
11
,
column
=
3
,
padx
=
10
)
# In[22]:
#Showing the output of different algorithms
t1
=
Label
(
root
,
font
=
(
"Times"
,
15
,
"bold"
),
text
=
"Decision Tree"
,
height
=
1
,
bg
=
"Light green"
,
width
=
40
,
fg
=
"black"
,
textvariable
=
pred1
,
relief
=
"sunken"
)
.
grid
(
row
=
15
,
column
=
1
,
padx
=
10
)
t2
=
Label
(
root
,
font
=
(
"Times"
,
15
,
"bold"
),
text
=
"Random Forest"
,
height
=
1
,
bg
=
"Light green"
,
width
=
40
,
fg
=
"black"
,
textvariable
=
pred2
,
relief
=
"sunken"
)
.
grid
(
row
=
17
,
column
=
1
,
padx
=
10
)
# In[23]:
#calling this function because the application is ready to run
root
.
mainloop
()
# In[ ]:
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment