Implementation of common machine learning algorithms from scratch in Python
Algorithm | Math | Implementation | Demo |
---|---|---|---|
Ridge Regression | Theory and Derivation | Python Implementation | Demo |
Regularised Logistic Regression | Theory and Derivation | Python Implementation | Demo |
Lasso Regression | Theory and Derivation | Python Implementation | Demo |
K Means | Theory and Algorithm | Python Implementation | Demo |
Principal Component Analysis | Theory and Algorithm | Python Implementation | Demo |
The package depends only on numpy
. Running the demos will require additional packages such as jupyter
, pandas
and sklearn
.
The demos are in ipynb notebooks. Make sure you have the dependencies - pandas
and sklearn
installed in your
environment. Then from the root of the project start the ipynb server by running $ jupyter notebook
and navigate to
the directory demo
.
To install the package locally, run the following from the root of the project
$ python setup.py install
To make a pip installable tar archive, run
$ python setup.py sdist
The tar file would be generated inside dist
folder. The package can be installed using the tar archive by running
$ pip install pymlalgo-0.0.1.tar.gz
For details on how to install packages from tar archive, refer to this link on StackOverflow
Once you have the package installed, import the module, initialize the class with data and hyper parameters and then
train the model. For example to use KMeans
:
from pymlalgo.clustering.k_means import KMeans
model = KMeans(x, k, max_iter=200)
model.train()
# get assigned cluster
model.labels