Spaces:
Running
Running
optimise code and add multiple selection of model and provision for hyper parameter for selected model
Browse files- app.py +100 -92
- classification.py +2 -0
- test.py +93 -0
app.py
CHANGED
@@ -53,103 +53,111 @@ def resume():
|
|
53 |
# Main function to run the app
|
54 |
def main():
|
55 |
st.sidebar.title("Navigation")
|
56 |
-
page_options = ["Classification", "Regressor", "NLP", "Image","Voice","Video","LLMs"]
|
57 |
choice = st.sidebar.radio("Go to", page_options)
|
58 |
|
59 |
if choice == "Classification":
|
60 |
-
|
61 |
st.title("Classification")
|
62 |
-
spectra = st.file_uploader("
|
63 |
-
st.write("Waiting for file upload...")
|
64 |
-
status =True
|
65 |
-
while status:
|
66 |
-
# st.write("Waiting for file upload...")
|
67 |
-
# spectra = st.file_uploader("upload file", type={"csv", "txt"})
|
68 |
-
if spectra is not None:
|
69 |
-
status = False
|
70 |
-
|
71 |
-
# if spectra is None:
|
72 |
-
# # print("Spectra", spectra)
|
73 |
-
# st.write("Waiting for file upload...")
|
74 |
-
# # spectra = st.file_uploader("Upload File", key=file_uploader_key)
|
75 |
-
|
76 |
-
spectra_df = pd.read_csv(spectra)
|
77 |
-
st.write(spectra_df.head(5))
|
78 |
-
|
79 |
-
# dataset
|
80 |
-
headers = spectra_df.columns.tolist()
|
81 |
-
total_rows = spectra_df.shape[0]
|
82 |
-
|
83 |
-
st.write("Headers", headers)
|
84 |
-
st.write("Total Rows", total_rows)
|
85 |
-
|
86 |
-
option = st.selectbox(
|
87 |
-
'Select the output columns', headers)
|
88 |
-
st.write('Output column is :', option)
|
89 |
-
|
90 |
-
status1 = True
|
91 |
-
while status1:
|
92 |
-
if option is not None:
|
93 |
-
status1 = False
|
94 |
-
|
95 |
-
|
96 |
-
y = spectra_df[option]
|
97 |
-
X= spectra_df.drop(option, axis=1)
|
98 |
-
|
99 |
-
|
100 |
-
st.write("X",X.head(5) )
|
101 |
-
st.write("y", y.head(5))
|
102 |
-
|
103 |
-
|
104 |
-
clf = ClassificationModels(X,y)
|
105 |
-
|
106 |
-
# Split the data
|
107 |
-
clf.split_data()
|
108 |
-
|
109 |
-
# Train the models
|
110 |
-
naive_bayes_model = clf.naive_bayes_classifier()
|
111 |
-
logistic_regression_model = clf.logistic_regression()
|
112 |
-
decision_tree_model = clf.decision_tree()
|
113 |
-
random_forests_model = clf.random_forests()
|
114 |
-
svm_model = clf.support_vector_machines()
|
115 |
-
knn_model = clf.k_nearest_neighbour()
|
116 |
-
|
117 |
-
# Evaluate the models
|
118 |
-
naive_bayes_accuracy = clf.evaluate_model(naive_bayes_model)
|
119 |
-
logistic_regression_accuracy = clf.evaluate_model(logistic_regression_model)
|
120 |
-
decision_tree_accuracy = clf.evaluate_model(decision_tree_model)
|
121 |
-
random_forests_accuracy = clf.evaluate_model(random_forests_model)
|
122 |
-
svm_accuracy = clf.evaluate_model(svm_model)
|
123 |
-
knn_accuracy = clf.evaluate_model(knn_model)
|
124 |
-
|
125 |
-
# Evaluate classification model
|
126 |
-
naive_bayes_classification_report = clf.evaluate_classification_report(naive_bayes_model)
|
127 |
-
logistic_regression_classification_report = clf.evaluate_classification_report(logistic_regression_model)
|
128 |
-
decision_tree_classification_report = clf.evaluate_classification_report(decision_tree_model)
|
129 |
-
random_forest_classification_report = clf.evaluate_classification_report(random_forests_model)
|
130 |
-
svm_classification_report = clf.evaluate_classification_report(svm_model)
|
131 |
-
knn_classification_report = clf.evaluate_classification_report(knn_model)
|
132 |
-
|
133 |
-
# Display the model prediction
|
134 |
-
|
135 |
-
# st.write("Naive Bayes Model Prediction:", clf.predict_model(naive_bayes_model))
|
136 |
-
|
137 |
-
# Display the accuracies
|
138 |
-
st.write("Naive Bayes Accuracy:", naive_bayes_accuracy)
|
139 |
-
st.write("Logistic Regression Accuracy:", logistic_regression_accuracy)
|
140 |
-
st.write("Decision Tree Accuracy:", decision_tree_accuracy)
|
141 |
-
st.write("Random Forests Accuracy:", random_forests_accuracy)
|
142 |
-
st.write("Support Vector Machines Accuracy:", svm_accuracy)
|
143 |
-
st.write("K-Nearest Neighbors Accuracy:", knn_accuracy)
|
144 |
-
|
145 |
-
# Display classification reports
|
146 |
-
st.write("Naive Bayes Classification Report:", naive_bayes_classification_report)
|
147 |
-
st.write("Logistic Regression Classification Report:", logistic_regression_classification_report)
|
148 |
-
st.write("Decision Tree Classification Report:", decision_tree_classification_report)
|
149 |
-
st.write("Random Forests Classification Report:", random_forest_classification_report)
|
150 |
-
st.write("Support Vector Machines Classification Report:", svm_classification_report)
|
151 |
-
st.write("K-Nearest Neighbors Classification Report:", knn_classification_report)
|
152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
|
154 |
|
155 |
|
|
|
53 |
# Main function to run the app
|
54 |
def main():
|
55 |
st.sidebar.title("Navigation")
|
56 |
+
page_options = ["Classification", "Regressor", "NLP", "Image", "Voice", "Video", "LLMs"]
|
57 |
choice = st.sidebar.radio("Go to", page_options)
|
58 |
|
59 |
if choice == "Classification":
|
|
|
60 |
st.title("Classification")
|
61 |
+
spectra = st.file_uploader("Upload file", type={"csv", "txt"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
+
if spectra is not None:
|
64 |
+
spectra_df = pd.read_csv(spectra)
|
65 |
+
|
66 |
+
st.write(spectra_df.head(5))
|
67 |
+
st.write("Headers", spectra_df.columns.tolist())
|
68 |
+
st.write("Total Rows", spectra_df.shape[0])
|
69 |
+
|
70 |
+
option = st.text_input("Enter your text here:")
|
71 |
+
if option:
|
72 |
+
st.write("You entered:", option)
|
73 |
+
|
74 |
+
y = spectra_df[option]
|
75 |
+
X= spectra_df.drop(option, axis=1)
|
76 |
+
|
77 |
+
st.write("X",X.head(5) )
|
78 |
+
st.write("y", y.head(5))
|
79 |
+
|
80 |
+
|
81 |
+
clf = ClassificationModels(X,y)
|
82 |
+
|
83 |
+
# Split the data
|
84 |
+
clf.split_data()
|
85 |
+
|
86 |
+
# Train the models
|
87 |
+
naive_bayes_model = clf.naive_bayes_classifier()
|
88 |
+
logistic_regression_model = clf.logistic_regression()
|
89 |
+
decision_tree_model = clf.decision_tree()
|
90 |
+
random_forests_model = clf.random_forests()
|
91 |
+
svm_model = clf.support_vector_machines()
|
92 |
+
knn_model = clf.k_nearest_neighbour()
|
93 |
+
|
94 |
+
# Evaluate the models
|
95 |
+
naive_bayes_accuracy = clf.evaluate_model(naive_bayes_model)
|
96 |
+
logistic_regression_accuracy = clf.evaluate_model(logistic_regression_model)
|
97 |
+
decision_tree_accuracy = clf.evaluate_model(decision_tree_model)
|
98 |
+
random_forests_accuracy = clf.evaluate_model(random_forests_model)
|
99 |
+
svm_accuracy = clf.evaluate_model(svm_model)
|
100 |
+
knn_accuracy = clf.evaluate_model(knn_model)
|
101 |
+
|
102 |
+
# Evaluate classification model
|
103 |
+
naive_bayes_classification_report = clf.evaluate_classification_report(naive_bayes_model)
|
104 |
+
logistic_regression_classification_report = clf.evaluate_classification_report(logistic_regression_model)
|
105 |
+
decision_tree_classification_report = clf.evaluate_classification_report(decision_tree_model)
|
106 |
+
random_forest_classification_report = clf.evaluate_classification_report(random_forests_model)
|
107 |
+
svm_classification_report = clf.evaluate_classification_report(svm_model)
|
108 |
+
knn_classification_report = clf.evaluate_classification_report(knn_model)
|
109 |
+
|
110 |
+
# Display the model prediction
|
111 |
+
|
112 |
+
# st.write("Naive Bayes Model Prediction:", clf.predict_model(naive_bayes_model))
|
113 |
+
|
114 |
+
# Display the accuracies
|
115 |
+
st.write("Naive Bayes Accuracy:", naive_bayes_accuracy)
|
116 |
+
st.write("Logistic Regression Accuracy:", logistic_regression_accuracy)
|
117 |
+
st.write("Decision Tree Accuracy:", decision_tree_accuracy)
|
118 |
+
st.write("Random Forests Accuracy:", random_forests_accuracy)
|
119 |
+
st.write("Support Vector Machines Accuracy:", svm_accuracy)
|
120 |
+
st.write("K-Nearest Neighbors Accuracy:", knn_accuracy)
|
121 |
+
|
122 |
+
# Display classification reports
|
123 |
+
st.write("Naive Bayes Classification Report:", pd.DataFrame(naive_bayes_classification_report))
|
124 |
+
st.write("Logistic Regression Classification Report:", pd.DataFrame(logistic_regression_classification_report))
|
125 |
+
st.write("Decision Tree Classification Report:", pd.DataFrame(decision_tree_classification_report))
|
126 |
+
st.write("Random Forests Classification Report:", pd.DataFrame(random_forest_classification_report))
|
127 |
+
st.write("Support Vector Machines Classification Report:", pd.DataFrame(svm_classification_report))
|
128 |
+
st.write("K-Nearest Neighbors Classification Report:", pd.DataFrame(knn_classification_report))
|
129 |
+
|
130 |
+
# Display the confusion matrix
|
131 |
+
|
132 |
+
# Add a multiple selection dropdown
|
133 |
+
|
134 |
+
list_of_classifier_models = [
|
135 |
+
"naive_bayes_classifier",
|
136 |
+
"logistic_regression",
|
137 |
+
"decision_tree",
|
138 |
+
"random_forests",
|
139 |
+
"support_vector_machines",
|
140 |
+
"k_nearest_neighbour",
|
141 |
+
"k_means_clustering"
|
142 |
+
]
|
143 |
+
|
144 |
+
selected_models = st.multiselect("Select Models",list_of_classifier_models)
|
145 |
+
|
146 |
+
# Execute further code based on selected models
|
147 |
+
if selected_models:
|
148 |
+
# Further code execution based on selected models
|
149 |
+
st.write("Selected Models:", selected_models)
|
150 |
+
st.write("Selected Models type:", len(selected_models))
|
151 |
+
|
152 |
+
# Toggle to add hyperparameters
|
153 |
+
add_hyperparameters = st.checkbox("Add Hyperparameters")
|
154 |
+
|
155 |
+
# If hyperparameters should be added
|
156 |
+
if add_hyperparameters:
|
157 |
+
# For each selected model, create a space for hyperparameters
|
158 |
+
for model in selected_models:
|
159 |
+
st.write(f"Hyperparameters for {model}:")
|
160 |
+
# Here you can add text inputs, sliders, or any other widgets to input hyperparameters
|
161 |
|
162 |
|
163 |
|
classification.py
CHANGED
@@ -19,6 +19,7 @@ class ClassificationModels:
|
|
19 |
self.X, self.y, test_size=test_size, random_state=random_state
|
20 |
)
|
21 |
|
|
|
22 |
def naive_bayes_classifier(self):
|
23 |
model = GaussianNB()
|
24 |
model.fit(self.X_train, self.y_train)
|
@@ -59,6 +60,7 @@ class ClassificationModels:
|
|
59 |
model.fit(self.X_train, self.y_train)
|
60 |
return model
|
61 |
|
|
|
62 |
def k_means_clustering(self, n_clusters):
|
63 |
model = KMeans(n_clusters=n_clusters)
|
64 |
model.fit(self.X_train)
|
|
|
19 |
self.X, self.y, test_size=test_size, random_state=random_state
|
20 |
)
|
21 |
|
22 |
+
|
23 |
def naive_bayes_classifier(self):
|
24 |
model = GaussianNB()
|
25 |
model.fit(self.X_train, self.y_train)
|
|
|
60 |
model.fit(self.X_train, self.y_train)
|
61 |
return model
|
62 |
|
63 |
+
|
64 |
def k_means_clustering(self, n_clusters):
|
65 |
model = KMeans(n_clusters=n_clusters)
|
66 |
model.fit(self.X_train)
|
test.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import streamlit as st
|
3 |
+
from classification import ClassificationModels
|
4 |
+
|
5 |
+
|
6 |
+
def main():
|
7 |
+
|
8 |
+
st.sidebar.title("Navigation")
|
9 |
+
page_options = ["Classification", "Regressor", "NLP", "Image", "Voice", "Video", "LLMs"]
|
10 |
+
choice = st.sidebar.radio("Go to", page_options)
|
11 |
+
|
12 |
+
if choice == "Classification":
|
13 |
+
st.title("Classification")
|
14 |
+
spectra = st.file_uploader("Upload file", type={"csv", "txt"})
|
15 |
+
|
16 |
+
if spectra is not None:
|
17 |
+
spectra_df = pd.read_csv(spectra)
|
18 |
+
|
19 |
+
st.write(spectra_df.head(5))
|
20 |
+
st.write("Headers", spectra_df.columns.tolist())
|
21 |
+
st.write("Total Rows", spectra_df.shape[0])
|
22 |
+
|
23 |
+
option = st.text_input("Enter your text here:")
|
24 |
+
if option:
|
25 |
+
st.write("You entered:", option)
|
26 |
+
|
27 |
+
y = spectra_df[option]
|
28 |
+
X= spectra_df.drop(option, axis=1)
|
29 |
+
|
30 |
+
st.write("X",X.head(5) )
|
31 |
+
st.write("y", y.head(5))
|
32 |
+
|
33 |
+
|
34 |
+
clf = ClassificationModels(X,y)
|
35 |
+
|
36 |
+
# Split the data
|
37 |
+
clf.split_data()
|
38 |
+
|
39 |
+
# Train the models
|
40 |
+
naive_bayes_model = clf.naive_bayes_classifier()
|
41 |
+
logistic_regression_model = clf.logistic_regression()
|
42 |
+
decision_tree_model = clf.decision_tree()
|
43 |
+
random_forests_model = clf.random_forests()
|
44 |
+
svm_model = clf.support_vector_machines()
|
45 |
+
knn_model = clf.k_nearest_neighbour()
|
46 |
+
|
47 |
+
# Evaluate the models
|
48 |
+
naive_bayes_accuracy = clf.evaluate_model(naive_bayes_model)
|
49 |
+
logistic_regression_accuracy = clf.evaluate_model(logistic_regression_model)
|
50 |
+
decision_tree_accuracy = clf.evaluate_model(decision_tree_model)
|
51 |
+
random_forests_accuracy = clf.evaluate_model(random_forests_model)
|
52 |
+
svm_accuracy = clf.evaluate_model(svm_model)
|
53 |
+
knn_accuracy = clf.evaluate_model(knn_model)
|
54 |
+
|
55 |
+
# Evaluate classification model
|
56 |
+
naive_bayes_classification_report = clf.evaluate_classification_report(naive_bayes_model)
|
57 |
+
logistic_regression_classification_report = clf.evaluate_classification_report(logistic_regression_model)
|
58 |
+
decision_tree_classification_report = clf.evaluate_classification_report(decision_tree_model)
|
59 |
+
random_forest_classification_report = clf.evaluate_classification_report(random_forests_model)
|
60 |
+
svm_classification_report = clf.evaluate_classification_report(svm_model)
|
61 |
+
knn_classification_report = clf.evaluate_classification_report(knn_model)
|
62 |
+
|
63 |
+
# Display the model prediction
|
64 |
+
|
65 |
+
# st.write("Naive Bayes Model Prediction:", clf.predict_model(naive_bayes_model))
|
66 |
+
|
67 |
+
# Display the accuracies
|
68 |
+
st.write("Naive Bayes Accuracy:", naive_bayes_accuracy)
|
69 |
+
st.write("Logistic Regression Accuracy:", logistic_regression_accuracy)
|
70 |
+
st.write("Decision Tree Accuracy:", decision_tree_accuracy)
|
71 |
+
st.write("Random Forests Accuracy:", random_forests_accuracy)
|
72 |
+
st.write("Support Vector Machines Accuracy:", svm_accuracy)
|
73 |
+
st.write("K-Nearest Neighbors Accuracy:", knn_accuracy)
|
74 |
+
|
75 |
+
# Display classification reports
|
76 |
+
st.write("Naive Bayes Classification Report:", pd.DataFrame(naive_bayes_classification_report))
|
77 |
+
st.write("Logistic Regression Classification Report:", pd.DataFrame(logistic_regression_classification_report))
|
78 |
+
st.write("Decision Tree Classification Report:", pd.DataFrame(decision_tree_classification_report))
|
79 |
+
st.write("Random Forests Classification Report:", pd.DataFrame(random_forest_classification_report))
|
80 |
+
st.write("Support Vector Machines Classification Report:", pd.DataFrame(svm_classification_report))
|
81 |
+
st.write("K-Nearest Neighbors Classification Report:", pd.DataFrame(knn_classification_report))
|
82 |
+
|
83 |
+
# Display the confusion matrix
|
84 |
+
|
85 |
+
|
86 |
+
|
87 |
+
|
88 |
+
|
89 |
+
|
90 |
+
|
91 |
+
|
92 |
+
if __name__ == "__main__":
|
93 |
+
main()
|