예제 #1
0
###############################################################################
# Generate sample data
centers = [[1, 1], [0.5, 0.5], [1, -1]]
X, idx = liac.random.make_gaussian(n_samples=100, centers=centers)

gmm = liac.models.GMM(3, 'full')
gmm.fit(X)

means = gmm.means_
covs = gmm.covars_
n_clusters_ = len(means)
ax = liac.plot.gca()

for i in xrange(n_clusters_):
    pi = idx == i
    plot.scatter(X[pi, 0], X[pi, 1], color=liac.random.make_color(i + 10))

    e = liac.plot.Gaussian(means[i],
                           covs[i],
                           5,
                           color=liac.random.make_color(i),
                           alpha=0.75)
    ax.add_artist(e)
    x, y = means[i]
    liac.plot.plot(x, y, 'x', markersize=14, markeredgewidth=2, color='k')
    liac.plot.plot(x,
                   y,
                   'x',
                   markersize=12,
                   markeredgewidth=2,
                   color=liac.random.make_color(i))
예제 #2
0
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# =============================================================================

import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))

import liac
from liac import plot

data = liac.dataset.load('iris')
targets = data.iloc[:, -1]
classes = targets.unique()
data = data.iloc[:, 0:-1]

kpca = liac.models.KernelPCA(2, 'linear')
kpca.fit(data)

transformed_data = kpca.transform(data)
for i, label in enumerate(classes):
    idx = targets == label
    d = transformed_data[idx]
    plot.scatter(d[:, 0], d[:, 1], color=liac.random.make_color(i))

plot.show()
예제 #3
0
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# =============================================================================

import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))

import liac
from liac import plot

data = liac.dataset.load('iris')
targets = data.iloc[:, -1]
classes = targets.unique()
data = data.iloc[:, 0:-1]

kpca = liac.models.KernelPCA(2, 'linear')
kpca.fit(data)

transformed_data = kpca.transform(data)
for i, label in enumerate(classes):
    idx = targets == label
    d = transformed_data[idx]
    plot.scatter(d[:, 0], d[:, 1], color=liac.random.make_color(i))

plot.show()
예제 #4
0

###############################################################################
# Generate sample data
centers = [[1, 1], [0.5, 0.5], [1, -1]]
X, idx = liac.random.make_gaussian(n_samples=100, centers=centers)

gmm = liac.models.GMM(3, 'full')
gmm.fit(X)

means = gmm.means_
covs = gmm.covars_
n_clusters_ = len(means)
ax = liac.plot.gca()

for i in xrange(n_clusters_):
    pi = idx == i
    plot.scatter(X[pi,0], X[pi,1], color=liac.random.make_color(i+10))

    e = liac.plot.Gaussian(means[i], covs[i], 5, color=liac.random.make_color(i), alpha=0.75)
    ax.add_artist(e)
    x, y = means[i]
    liac.plot.plot(x, y, 'x', markersize=14, markeredgewidth=2, color='k')
    liac.plot.plot(x, y, 'x', markersize=12, markeredgewidth=2, color=liac.random.make_color(i))

# for i, center in enumerate(centers):
    # X, idx = liac.random.make_gaussian(n_samples=100, centers=center)
#     plot.scatter(X[:,0], X[:,1], color=liac.random.make_color(i))
plot.show()