Skip to content

samryan18/dumb_sklearn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dumb scikit-learn

Work in progress. Based on the popular scikit-learn python package...just a little dumber.

See: Dumb Starbucks.

Refreshing on the basics.

Installation

$ git clone git@github.com:samryan18/dumb_sklearn.git
$ pip install dumb_sklearn

Models

1. Neural Networks

Implemented in matlab. Sorry.

2. Principal Component Analysis (dumb_sklearn.PCA)

The API for this model is very similar to the one in sklearn.

Basic usage:

from dumb_sklearn import PCA

X = get_some_data()
pca = PCA(n_components=n_components, standardize=True)
X_transform = pca.fit_transform(X)
X_recon = pca.inverse_transform(X_transform)

Example 1: Eigenfaces

In
from sklearn.datasets import fetch_lfw_people

from dumb_sklearn import PCA
from dumb_sklearn.utils import plot_gallery

faces = fetch_lfw_people(min_faces_per_person=60)

_, h, w = faces.images.shape
X, y = faces.data, faces.target
target_names = faces.target_names
n_components = 200

pca = PCA(n_components=n_components, standardize=True)
X_transform = pca.fit_transform(X)
eigenfaces = pca.components.reshape((n_components, h, w))

print("ORIGINAL FACES:")
real_titles = [f"original {i}" for i in range(eigenfaces.shape[0])]
real_faces = faces.images
plot_gallery(real_faces, real_titles, h, w, n_row=2, n_col=7)

print("EIGENFACES:")
eigenface_titles = [f"eigenface {i}" for i in range(eigenfaces.shape[0])]
plot_gallery(eigenfaces, eigenface_titles, h, w, n_row=2, n_col=7)

print("AVERAGE FACE:")
plot_gallery(pca._mean.reshape(1, h, w), ["mean"], h, w, n_row=1, n_col=1)

print("STANDARD DEV FACE:")
plot_gallery(pca._std.reshape(1, h, w), ["stddev"], h, w, n_row=1, n_col=1)

print("RECON FACES:")
recon = pca.inverse_transform(X_transform)
recon = recon.reshape((faces.images.shape[0], h, w))
recon_titles = [f"recon {i}" for i in range(eigenfaces.shape[0])]
plot_gallery(recon, recon_titles, h, w, n_row=2, n_col=7)
Out
ORIGINAL FACES

ORIGINAL FACES

EIGENFACES

EIGENFACES

AVERAGE FACE

AVERAGE FACE

STANDARD DEV FACE

STANDARD DEV FACE

RECON FACES

RECON FACES

About

simple, readable ML implementations

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages