View kmeans.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# | |
# K-means clustering using Lloyd's algorithm in pure Python. | |
# Written by Lars Buitinck. This code is in the public domain. | |
# | |
# The main program runs the clustering algorithm on a bunch of text documents | |
# specified as command-line arguments. These documents are first converted to | |
# sparse vectors, represented as lists of (index, value) pairs. | |
from collections import defaultdict |
View gist:11046631
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#test save and load of numpy matrix | |
#test matrix multiplication in memory and using memmap | |
#in case of memmap no need to use batch processing | |
#also can test hdf5 and pytables for matrix mult | |
#can use matrix mult for pca (more smart to use randompca) | |
#need to test it on x64 machine |
View learning_gabor_filters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from sklearn.datasets import fetch_mldata | |
from sklearn.decomposition import FastICA, PCA | |
from sklearn.cluster import KMeans | |
# fetch natural image patches | |
image_patches = fetch_mldata("natural scenes data") | |
X = image_patches.data |
View gist:91f494e0fbe3ce595d2a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#test save and load of numpy matrix | |
#test matrix multiplication in memory and using memmap | |
#in case of memmap no need to use batch processing | |
#also can test hdf5 and pytables for matrix mult | |
#can use matrix mult for pca (more smart to use randompca) | |
#need to test it on x64 machine |
View gist:a8e329b7087281ec4f61
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pca(data,k): | |
#data M x N | |
#get mean | |
mean= np.mean(data,axis=0) # N long | |
# print mean.shape | |
# print mean | |
#M x N | |
data_c= (data-mean) | |
print data_c.shape |
View pca memmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import time | |
def read_data(): | |
#M x N | |
data= np.loadtxt("data_3d.txt",delimiter=" ", skiprows=1, usecols=(0,1,2)) | |
print data.shape | |
# print data | |
return data | |
View gist:fdd8134d1916650898a6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import time | |
def read_data(): | |
#M x N | |
data= np.loadtxt("data_3d.txt",delimiter=" ", skiprows=1, usecols=(0,1,2)) | |
print data.shape | |
# print data | |
return data | |
View svm.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mathieu Blondel, September 2010 | |
# License: BSD 3 clause | |
import numpy as np | |
from numpy import linalg | |
import cvxopt | |
import cvxopt.solvers | |
def linear_kernel(x1, x2): | |
return np.dot(x1, x2) |
View CUR4FIC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# clear the workspace | |
rm(list = ls()) | |
# load the relevant libraries | |
# install.packages(rCUR) | |
library(rCUR) # for CUR decomposition | |
# install.packages(irlba) | |
library(irlba) # for fast svd |
View gist:3943410759f04265f7cb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> a = [1 2 3; 2 5 7; 3 7 9] | |
a = | |
1 2 3 | |
2 5 7 | |
3 7 9 | |
>> [U S V] = svd(a) |
OlderNewer