Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add perceptron #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ __pycache__

**/.DS_Store

notebooks/
notebooks/

.idea/
34 changes: 34 additions & 0 deletions models/Perceptron.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import streamlit as st
from sklearn.linear_model import Perceptron


def lp_param_selector():
eta0 = st.slider("learning_rate", 0.001, 10.0, step=0.001, value=1.0)
max_iter = st.number_input("max_iter", 100, 2000, step=50, value=100)

penalty = st.selectbox("penalty", options=["None", "l2", "l1", "elasticnet"])

if penalty in ["l2", "l1", "elasticnet"]:
alpha = st.slider("alpha", 0.00001, 0.001, step=0.00001, value=0.0001)
else:
alpha = 0.0001

early_stopping = st.checkbox('early_stopping', value=False)

if early_stopping:
validation_fraction = st.number_input("validation_fraction", 0.0, 1.0, step=0.05, value=0.1)
n_iter_no_change = st.number_input("n_iter_no_change", 2, 100, step=1, value=5)
else:
validation_fraction = 0.1
n_iter_no_change = 5

params = {"eta0": eta0,
"max_iter": max_iter,
"penalty": penalty,
"alpha": alpha,
"early_stopping": early_stopping,
"validation_fraction": validation_fraction,
"n_iter_no_change": n_iter_no_change}

model = Perceptron(**params)
return model
8 changes: 8 additions & 0 deletions models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"K Nearest Neighbors": "from sklearn.neighbors import KNeighborsClassifier",
"Gaussian Naive Bayes": "from sklearn.naive_bayes import GaussianNB",
"SVC": "from sklearn.svm import SVC",
"Perceptron": "from sklearn.linear_model import Perceptron",
}


Expand All @@ -19,6 +20,7 @@
"K Nearest Neighbors": "https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html",
"Gaussian Naive Bayes": "https://scikit-learn.org/stable/modules/naive_bayes.html",
"SVC": "https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html",
"Perceptron": "https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Perceptron.html",
}


Expand Down Expand Up @@ -63,4 +65,10 @@
- They provide different type of kernel functions
- They require careful normalization
""",
"Perceptron": """
- Perceptron is the simples form of Artificial Neural Network
- Single-layer Perceptrons require linearly separable data, otherwise it does not converge
- Multilayer Perceptrons (MLP) are feedforward neural networks with two or more layers which have the greater
processing power and can process non-linearly separable data.
""",
}
5 changes: 5 additions & 0 deletions utils/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from models.KNearesNeighbors import knn_param_selector
from models.SVC import svc_param_selector
from models.GradientBoosting import gb_param_selector
from models.Perceptron import lp_param_selector

from models.utils import model_imports
from utils.functions import img_to_bytes
Expand Down Expand Up @@ -83,6 +84,7 @@ def model_selector():
"K Nearest Neighbors",
"Gaussian Naive Bayes",
"SVC",
"Perceptron",
),
)

Expand Down Expand Up @@ -110,6 +112,9 @@ def model_selector():
elif model_type == "Gradient Boosting":
model = gb_param_selector()

elif model_type == "Perceptron":
model = lp_param_selector()

return model_type, model


Expand Down