Upload 3 files
Browse files- app.py +96 -0
- inno.jpg +0 -0
- requirements.txt +6 -0
app.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
from sklearn.datasets import make_classification, make_circles, make_blobs, make_moons
|
| 5 |
+
from sklearn.model_selection import train_test_split, learning_curve
|
| 6 |
+
from sklearn.neighbors import KNeighborsClassifier
|
| 7 |
+
from sklearn.naive_bayes import GaussianNB
|
| 8 |
+
from sklearn.linear_model import LogisticRegression
|
| 9 |
+
from sklearn.tree import DecisionTreeClassifier
|
| 10 |
+
from sklearn.metrics import accuracy_score, f1_score
|
| 11 |
+
from mlxtend.plotting import plot_decision_regions
|
| 12 |
+
|
| 13 |
+
# Display image
|
| 14 |
+
st.image("inno.jpg", width=600)
|
| 15 |
+
|
| 16 |
+
# Streamlit app title
|
| 17 |
+
st.title('Boundary Surfaces Visualization')
|
| 18 |
+
|
| 19 |
+
# Select dataset
|
| 20 |
+
data = st.sidebar.selectbox('Type of data ', ('Classification', 'Circles', 'Blobs', 'Moons'))
|
| 21 |
+
|
| 22 |
+
if data == 'Classification':
|
| 23 |
+
X, y = make_classification(n_samples=100, n_features=2, n_redundant=0, random_state=42)
|
| 24 |
+
elif data == 'Circles':
|
| 25 |
+
X, y = make_circles(n_samples=100, factor=0.5, noise=0.05)
|
| 26 |
+
elif data == 'Blobs':
|
| 27 |
+
X, y = make_blobs(n_samples=250, centers=2, n_features=2, cluster_std=1.0, random_state=42)
|
| 28 |
+
elif data == 'Moons':
|
| 29 |
+
X, y = make_moons(n_samples=250, noise=0.1, random_state=42)
|
| 30 |
+
|
| 31 |
+
# Split dataset
|
| 32 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
|
| 33 |
+
|
| 34 |
+
def plot_decision_surface(X, y, model, title):
|
| 35 |
+
plt.figure(figsize=(6,4))
|
| 36 |
+
plot_decision_regions(X, y, clf=model, colors="#7f7f7f,#bcbd22,#17becf")
|
| 37 |
+
plt.title(title)
|
| 38 |
+
st.pyplot(plt.gcf(), clear_figure=True)
|
| 39 |
+
|
| 40 |
+
# Select classifier
|
| 41 |
+
classifier_name = st.sidebar.selectbox('Select Classifier', ('KNN', 'Naive Bayes', 'Logistic Regression', 'DecisionTreeClassifier'))
|
| 42 |
+
|
| 43 |
+
if classifier_name == 'KNN':
|
| 44 |
+
n_neighbors = st.sidebar.slider('Number of Neighbors (k)', 1, 15, 3)
|
| 45 |
+
weights = st.sidebar.radio('Weight Function', ('uniform', 'distance'))
|
| 46 |
+
algorithm = st.sidebar.selectbox('Algorithm', ('auto', 'ball_tree', 'kd_tree', 'brute'))
|
| 47 |
+
|
| 48 |
+
model = KNeighborsClassifier(n_neighbors=n_neighbors, weights=weights, algorithm=algorithm)
|
| 49 |
+
|
| 50 |
+
elif classifier_name == 'Naive Bayes':
|
| 51 |
+
model = GaussianNB()
|
| 52 |
+
|
| 53 |
+
elif classifier_name == 'DecisionTreeClassifier':
|
| 54 |
+
model = DecisionTreeClassifier()
|
| 55 |
+
|
| 56 |
+
else:
|
| 57 |
+
model = LogisticRegression()
|
| 58 |
+
|
| 59 |
+
# Train model
|
| 60 |
+
model.fit(X_train, y_train)
|
| 61 |
+
|
| 62 |
+
# Make predictions
|
| 63 |
+
y_pred = model.predict(X_test)
|
| 64 |
+
|
| 65 |
+
# Compute accuracy & F1-score
|
| 66 |
+
accuracy = accuracy_score(y_test, y_pred)
|
| 67 |
+
f1 = f1_score(y_test, y_pred)
|
| 68 |
+
|
| 69 |
+
# Display metrics in Streamlit
|
| 70 |
+
st.subheader("Model Performance")
|
| 71 |
+
st.write(f"*Accuracy:* {accuracy:.2f}")
|
| 72 |
+
st.write(f"*F1-score:* {f1:.2f}")
|
| 73 |
+
|
| 74 |
+
# Plot decision boundary
|
| 75 |
+
plot_decision_surface(X, y, model, f'{classifier_name} Decision Surface')
|
| 76 |
+
|
| 77 |
+
# Plot Learning Curve
|
| 78 |
+
def plot_learning_curve(model, X, y):
|
| 79 |
+
train_sizes, train_scores, test_scores = learning_curve(model, X, y, cv=5, scoring='accuracy', train_sizes=np.linspace(0.1, 1.0, 10))
|
| 80 |
+
|
| 81 |
+
train_mean = np.mean(train_scores, axis=1)
|
| 82 |
+
test_mean = np.mean(test_scores, axis=1)
|
| 83 |
+
|
| 84 |
+
plt.figure(figsize=(6,4))
|
| 85 |
+
plt.plot(train_sizes, train_mean, 'o-', label="Training Accuracy")
|
| 86 |
+
plt.plot(train_sizes, test_mean, 'o-', label="Validation Accuracy")
|
| 87 |
+
|
| 88 |
+
plt.xlabel("Training Samples")
|
| 89 |
+
plt.ylabel("Accuracy")
|
| 90 |
+
plt.title(f"Learning Curve: {classifier_name}")
|
| 91 |
+
plt.legend()
|
| 92 |
+
st.pyplot(plt.gcf(), clear_figure=True)
|
| 93 |
+
|
| 94 |
+
# Display Learning Curve
|
| 95 |
+
st.subheader("Learning Curve")
|
| 96 |
+
plot_learning_curve(model, X, y)
|
inno.jpg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
scikit-learn
|
| 3 |
+
numpy
|
| 4 |
+
matplotlib
|
| 5 |
+
seaborn
|
| 6 |
+
mlxtend
|