Skip to content

Commit ec7056e

Browse files
committed
Add the polynomial kernel to the SVM code
2 parents cc27828 + f56f028 commit ec7056e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

machine_learning/support_vector_machines.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ def __init__(
7070
regularization: float = np.inf,
7171
kernel: str = "linear",
7272
gamma: float = 0.0,
73+
<<<<<<< HEAD
7374
degree: float =0.0,
75+
=======
76+
degree: int = 0.0,
77+
>>>>>>> f56f0285a7e96496e47793e3f7c7440d03e61f69
7478
coef0: float = 0.0,
7579
) -> None:
7680
self.regularization = regularization
@@ -93,8 +97,13 @@ def __init__(
9397
elif kernel == "polynomial":
9498
if self.degree == 0:
9599
raise ValueError("polynomial kernel requires degree")
100+
<<<<<<< HEAD
96101
if not isinstance(self.degree, (float, int)) :
97102
raise ValueError("degree must be float or int")
103+
=======
104+
if not isinstance(self.degree, int):
105+
raise ValueError("degree must be int")
106+
>>>>>>> f56f0285a7e96496e47793e3f7c7440d03e61f69
98107
if not self.degree > 0:
99108
raise ValueError("degree must be > 0")
100109
self.kernel = self.__polynomial
@@ -123,7 +132,6 @@ def __rbf(self, vector1: ndarray, vector2: ndarray) -> float:
123132
"""
124133
return np.exp(-(self.gamma * norm_squared(vector1 - vector2)))
125134

126-
127135
def __polynomial(self, vector1: ndarray, vector2: ndarray) -> float:
128136
"""
129137
Polynomial kernel: (x . y + coef0)^degree

0 commit comments

Comments
 (0)