Created
June 18, 2017 14:31
-
-
Save dvas0004/1b53672df70a1339742dd9670d49c418 to your computer and use it in GitHub Desktop.
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
from sklearn.decomposition import DictionaryLearning | |
from sklearn.decomposition import SparseCoder | |
import pandas as pd | |
# load data from CSV | |
df = pd.read_csv('/mnt/c/Users/davev/Documents/test_sparse.csv') | |
# get rid of the "label" column - AS Number in our case | |
del df['AS Number'] | |
# change data into required format from scikit learn | |
t=df.as_matrix() | |
# create a dictionary with 2 components (to make it easier to plot later) | |
# the dictionary is learnt by iterating over the data a 100 times | |
dict=DictionaryLearning(n_components=2, max_iter=100) | |
dict.fit(t) | |
# load the dictionary we just created into a Sparse Coder | |
sp = SparseCoder(dict.components_) | |
# instruct the sparse coder to represent our data in terms of the dictionary we previously "learnt" | |
sp.transform(t) | |
# ... [results displayed] ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment