-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrule_based_classifier.py
72 lines (63 loc) · 2.44 KB
/
rule_based_classifier.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
import streamlit as st
import pandas as pd
def is_habitable(pH, Iron, Nitrate, Chloride, Lead, Zinc, Turbidity, Fluoride, Copper, Sulfate, Chlorine, Manganese,
Total_Dissolved_Solids):
if pH >= 6.5 and pH <= 9.0 and Iron < 0.3 and Nitrate < 10 and Chloride < 250 and Lead < 0.015 and Zinc < 5 and Turbidity < 5 and Fluoride >= 0.7 and Fluoride <= 1.5 and Copper < 1.3 and Sulfate < 250 and Chlorine < 4.0 and Manganese < 0.05 and Total_Dissolved_Solids < 500:
return 0
else:
return 1
test_df = pd.read_csv('C:/Users/Acer/Documents/Neural_Ocean/Notebooks_PyFiles/test_data/test_df')
# Define the features and their types
features = {
'pH': float,
'Iron': float,
'Nitrate': float,
'Chloride': float,
'Lead': float,
'Zinc': float,
'Turbidity': float,
'Fluoride': float,
'Copper': float,
'Sulfate': float,
'Chlorine': float,
'Manganese': float,
'Total Dissolved Solids': float,
}
quality_aquatic = []
def rbc():
st.title('Water Quality Assessment Test')
inputs = {}
col1, col2, col3 = st.columns(3)
for i, feature in enumerate(features.items()):
if i % 3 == 0:
col = col1
elif i % 3 == 1:
col = col2
else:
col = col3
with col:
inputs[feature[0]] = st.number_input(f'{feature[0]}', value=0.0, step=0.1, format='%.1f',
key=feature[0])
# Add two buttons aligned in the center
col1, col2 = st.columns([1, 2])
with col1:
if st.button('Predict'):
inputs_list = list(inputs.values())
is_good = is_habitable(*inputs_list)
if is_good == 0:
st.success("Water quality is habitable for aquatic life")
else:
st.error("Water quality is not habitable for aquatic life")
quality_aquatic.append(is_good)
with col2:
if st.button('Random Inputs Predict'):
data = test_df.sample(n=1)
data.drop(['Target', 'Color', 'Odor'], axis=1, inplace=True)
st.write(data)
# st.write(data.values.tolist())
is_good = is_habitable(*data.values.tolist()[0])
if is_good == 0:
st.success("Water quality is habitable for aquatic life")
else:
st.error("Water quality is not habitable for aquatic life")
quality_aquatic.append(is_good)