sgd_classifier / README.md
nanye's picture
initial commit
1b19efc
|
Raw
History Blame Contribute Delete
1.58 kB
---
title: SGD Classifier
emoji: 😻
colorFrom: indigo
colorTo: green
sdk: static
app_file: index.html
pinned: false
---
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
# SGD Classifier
`SGDClassifier` is a NumPy-only linear classifier trained with
stochastic gradient descent. It supports `hinge`, `log_loss`,
`modified_huber`, `squared_hinge`, `perceptron`, `squared_error`, `huber`,
`epsilon_insensitive`, and `squared_epsilon_insensitive` losses.
Choose `batch_selection="random"` to independently sample each mini-batch, or
`batch_selection="permutation"` to shuffle the dataset and consume all of its
non-overlapping mini-batches before reshuffling.
```python
from sgd_classifier import SGDClassifier
classifier = SGDClassifier(
loss="log_loss",
batch_size=32,
batch_selection="permutation",
max_epochs=20,
random_state=42,
)
classifier.fit(X_train, y_train)
predictions = classifier.predict(X_test)
```
For manual or streaming training, one call performs exactly one SGD update and
returns the classifier:
```python
classifier = SGDClassifier(loss="hinge", learning_rate=0.01)
classifier.train_step(X_batch, y_batch, classes=[0, 1])
```
## Interactive visualizer
Open `index.html` through a local web server to create a two-dimensional binary
dataset by clicking on the plot. The model runs in the browser through Pyodide;
each press of **Take one SGD step** selects one mini-batch, calls
`train_step`, and redraws the decision regions and boundary.
```bash
python -m http.server 8000
```