In [2]:
# DictionaryLearning attempts to take a dataset and transform
# it into a sparse representation for classification.
# The features are a basis for the resulting datasets.

In [3]:
from sklearn.datasets import load_iris

In [4]:
from sklearn.decomposition import DictionaryLearning

In [5]:
iris = load_iris()

In [6]:
iris_data = iris.data

In [7]:
iris_target = iris.target

In [8]:
dl = DictionaryLearning(3)

In [9]:
transformed = dl.fit_transform(iris_data[::2])

In [10]:
transformed[:5]


Out[10]:
array([[ 0.        ,  6.34476574,  0.        ],
       [ 0.        ,  5.83576461,  0.        ],
       [ 0.        ,  6.32038375,  0.        ],
       [ 0.        ,  5.89318572,  0.        ],
       [ 0.        ,  5.45222715,  0.        ]])

In [11]:
transformed = dl.transform(iris_data[1::2])

In [ ]: