A minimal implementation of softmax regression using only NumPy and Matplotlib. This project is designed for experimenting and understanding how softmax works under the hood.
It utilizes multinomial regression to model the feature space, allowing for any number of classes and features.
-
model.py: Contains the
SoftmaxModelclass, which handles training, inference, and saving/loading model parameters. -
plot.py: Contains the
SoftmaxPlotclass for plotting training analytics. Can be enabled or disabled as a popup.
- Clone the repo:
git clone https://github.com/olsonb97/softmax_regression.git
- Install dependencies:
pip install numpy matplotlib
- Prepare dataset and labels. Normalize the data, as the model does not handle this internally.
- Create an instance of
SoftmaxModeland call itstrainmethod:from model import SoftmaxModel model = SoftmaxModel() model.train( dataset, labels, epochs=50, batches=5, learning_rate=0.01, decay_rate=0.001, shuffle=True, plot=True )
- Evaluate performance:
accuracy = model.test(dataset, labels) print("Accuracy:", accuracy)
- Save model parameters:
model.save("params.npz")
- Load model parameters and avoid re-training:
model = SoftmaxModel() model.load("params.npz")
- The
SoftmaxModelclass inherits fromSoftmaxPlotto allow plotting the training metrics. - This project is intended for educational/experimental purposes and runs quite slow compared to better suited alternatives, such as Sci-kit.