Skip to content

feat: add SEFR linear classifier - #309

Merged
siriak merged 2 commits into
TheAlgorithms:masterfrom
hamidkm9:add-sefr-classifier
Nov 29, 2026
Merged

siriak merged 2 commits into
TheAlgorithms:masterfrom
hamidkm9:add-sefr-classifier

Conversation

@hamidkm9

Copy link
Copy Markdown
Contributor

Description

Adds SEFR, a linear classifier that trains in one pass over the data with no iterations, learning rate or hyperparameters. Each feature is min-max scaled, the weight is (p − n)/(p + n) from the two class means, and the threshold is a class-size-weighted average of the mean scores. Multiclass is one-vs-rest.

  • machine_learning/sefr.r: sefr_fit, sefr_predict, sefr_decision_function, base R only, with header docs and runnable examples
  • DIRECTORY.md: one entry under Machine Learning

Reference: https://arxiv.org/abs/2006.04620 (I am the first author of the paper).

Validation

  • Ran with Rscript on R 4.1.0: iris training accuracy 0.90, 70/30 split test accuracy 0.84, versicolor vs virginica 0.93
  • Weights and biases match a NumPy implementation of the same formulas to 1e-15
  • Checked the error messages for a single class, mismatched lengths, NA values and a feature-count mismatch

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Multiclass training repeatedly scans all samples for each class, violating the documented complexity and becoming quadratic in sample count when the number of classes grows proportionally.

1 open issue
What changed in this PR

Adds SEFR to the repository’s machine-learning algorithms, with a base-R implementation supporting binary and multiclass classification.

Changes:

  • Adds training, decision-score, and prediction functions with min-max feature scaling.
  • Includes algorithm documentation and runnable binary and iris examples.
  • Registers SEFR in the algorithm directory.
File Description
machine_learning/​sefr.r Implements SEFR classification with documentation and examples.
DIRECTORY.md Adds SEFR under Machine Learning.

Review effort: Balanced

Comment thread machine_learning/sefr.r Resolved
…cans for each class head'

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The shared input check accepts infinite feature values, allowing min-max scaling to produce invalid model parameters instead of rejecting non-finite input.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Reject non-finite values before min-max scaling

machine_learning/​sefr.r:38

This check accepts Inf and -Inf, although min-max scaling cannot handle them. For example, fitting a feature containing c(0, 1, Inf, 2) with two classes computes Inf / Inf during scaling and returns invalid model parameters instead of reporting invalid input. Reject non-finite values in this shared helper so both fitting and prediction fail with a clear diagnostic.

1 resolved since last review

Review effort: Balanced

@siriak siriak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@siriak
siriak merged commit 087c10d into TheAlgorithms:master Nov 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants