Skip to content

Update support_vector_machines.py to add the polynomial kernel #12748

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed May 14, 2025
commit 190ed5a37a79935c55a6c75af5e9a756d05e326b
5 changes: 2 additions & 3 deletions machine_learning/support_vector_machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(
regularization: float = np.inf,
kernel: str = "linear",
gamma: float = 0.0,
degree: float=0.0,
degree: float = 0.0,
coef0: float = 0.0,
) -> None:
self.regularization = regularization
Expand All @@ -93,7 +93,7 @@ def __init__(
elif kernel == "polynomial":
if self.degree == 0:
raise ValueError("polynomial kernel requires degree")
if not isinstance(self.degree, (float, int)) :
if not isinstance(self.degree, (float, int)):
raise ValueError("degree must be float or int")
if not self.degree > 0:
raise ValueError("degree must be > 0")
Expand Down Expand Up @@ -123,7 +123,6 @@ def __rbf(self, vector1: ndarray, vector2: ndarray) -> float:
"""
return np.exp(-(self.gamma * norm_squared(vector1 - vector2)))


def __polynomial(self, vector1: ndarray, vector2: ndarray) -> float:
"""
Polynomial kernel: (x . y + coef0)^degree
Expand Down