Skip to content

Added Kernel #11

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 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
38 changes: 34 additions & 4 deletions src/linearboost/linear_boost.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# See https://github.com/scikit-learn/scikit-learn/blob/main/COPYING for details.
#
# Additional code and modifications:
# - Hamidreza Keshavarz (hamid9@outlook.com) — machine learning logic, design, and new algorithms
# - Mehdi Samsami (mehdisamsami@live.com) — software refactoring, compatibility with scikit-learn framework, and packaging
# - Hamidreza Keshavarz (hamid9@outlook.com) — machine learning logic, design, and new algorithms
# - Mehdi Samsami (mehdisamsami@live.com) — software refactoring, compatibility with scikit-learn framework, and packaging
#
# The combined work is licensed under the MIT License.

Expand Down Expand Up @@ -104,6 +104,20 @@ class LinearBoostClassifier(AdaBoostClassifier):
- 'maxabs': Uses MaxAbsScaler.
- 'robust': Applies RobustScaler.

kernel : {'linear', 'poly', 'rbf', 'sigmoid'} or callable, default='linear'
Specifies the kernel type to be used in the algorithm.
If a callable is given, it is used to pre-compute the kernel matrix.

gamma : float, default=None
Kernel coefficient for 'rbf', 'poly' and 'sigmoid'. If None, then it is
set to 1.0 / n_features.

degree : int, default=3
Degree for 'poly' kernels. Ignored by other kernels.

coef0 : float, default=1
Independent term in kernel function. It is only significant in 'poly' and 'sigmoid'.

class_weight : {"balanced", "balanced_subsample"}, dict or list of dicts, \
default=None
Weights associated with classes in the form ``{class_label: weight}``.
Expand Down Expand Up @@ -195,6 +209,10 @@ class LinearBoostClassifier(AdaBoostClassifier):
"learning_rate": [Interval(Real, 0, None, closed="neither")],
"algorithm": [StrOptions({"SAMME", "SAMME.R"})],
"scaler": [StrOptions({s for s in _scalers})],
"kernel": [StrOptions({"linear", "poly", "rbf", "sigmoid"}), callable],
"gamma": [Interval(Real, 0, None, closed="left"), None],
"degree": [Interval(Integral, 1, None, closed="left"), None],
"coef0": [Real, None],
"class_weight": [
StrOptions({"balanced_subsample", "balanced"}),
dict,
Expand All @@ -213,14 +231,26 @@ def __init__(
scaler="minmax",
class_weight=None,
loss_function=None,
kernel="linear",
gamma=None,
degree=3,
coef0=1,
):
super().__init__(
estimator=SEFR(), n_estimators=n_estimators, learning_rate=learning_rate
estimator=SEFR(
kernel=kernel, gamma=gamma, degree=degree, coef0=coef0
),
n_estimators=n_estimators,
learning_rate=learning_rate,
)
self.algorithm = algorithm
self.scaler = scaler
self.class_weight = class_weight
self.loss_function = loss_function
self.kernel = kernel
self.gamma = gamma
self.degree = degree
self.coef0 = coef0

if SKLEARN_V1_6_OR_LATER:

Expand Down Expand Up @@ -456,4 +486,4 @@ def predict(self, X):
if self.n_classes_ == 2:
return self.classes_.take(pred > 0, axis=0)

return self.classes_.take(np.argmax(pred, axis=1), axis=0)
return self.classes_.take(np.argmax(pred, axis=1), axis=0)
Loading