本文整理汇总了Python中sklearn.manifold.Isomap类的典型用法代码示例。如果您正苦于以下问题:Python Isomap类的具体用法?Python Isomap怎么用?Python Isomap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Isomap类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: plot_3d
def plot_3d(dataset):
"""TODO: Docstring for plot_3d.
:returns: TODO
"""
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
iso = Isomap(n_components=3)
projected = iso.fit_transform(dataset.data.toarray())
print 'projected: sample: %s, feature: %s'\
% (projected.shape[0], projected.shape[1])
all_scatter = []
colors = cm.rainbow(np.linspace(0, 1, len(dataset.target_names)), alpha=0.5)
for i in range(len(dataset.target_names)):
points = projected[dataset.target==i,:]
cur = ax.scatter(points[:,0], points[:,1], points[:,2],
color=colors[i], edgecolor='k', lw=0.1,
vmin=0, vmax=len(dataset.target_names))
all_scatter.append(cur)
ax.legend(all_scatter, dataset.target_names,
loc='lower left', scatterpoints=1)
plt.savefig('isomap3d', dpi=500)
plt.show()
return True
开发者ID:ShiehShieh,项目名称:Code_Identifier,代码行数:30,代码来源:visualization.py
示例2: dimension_reduce
def dimension_reduce():
''' This compares a few different methods of
dimensionality reduction on the current dataset.
'''
pca = PCA(n_components=2) # initialize a dimensionality reducer
pca.fit(digits.data) # fit it to our data
X_pca = pca.transform(digits.data) # apply our data to the transformation
plt.subplot(1, 3, 1)
plt.scatter(X_pca[:, 0], X_pca[:, 1], c=digits.target)# plot the manifold
se = SpectralEmbedding()
X_se = se.fit_transform(digits.data)
plt.subplot(1, 3, 2)
plt.scatter(X_se[:, 0], X_se[:, 1], c=digits.target)
isomap = Isomap(n_components=2, n_neighbors=20)
isomap.fit(digits.data)
X_iso = isomap.transform(digits.data)
plt.subplot(1, 3, 3)
plt.scatter(X_iso[:, 0], X_iso[:, 1], c=digits.target)
plt.show()
plt.matshow(pca.mean_.reshape(8, 8)) # plot the mean components
plt.matshow(pca.components_[0].reshape(8, 8)) # plot the first principal component
plt.matshow(pca.components_[1].reshape(8, 8)) # plot the second principal component
plt.show()
开发者ID:bashwork,项目名称:common,代码行数:26,代码来源:digits.py
示例3: plotTrajectory
def plotTrajectory(dfile):
fin = open(dfile)
Vsteps = []
Vtarget = fin.readline().strip().split()
Vtarget = map(float,Vtarget)
Vsteps.append(Vtarget)
for l in fin:
l = l.strip().split()
if len(l) != 26: continue
l = map(float,l)
Vsteps.append(l)
distances = [euclidean(a,Vsteps[0]) for a in Vsteps[1:]]
print len(distances)
_map = plt.get_cmap("winter")
distcolors = _map(distances)
dimred = Isomap(n_components=2)
Vsteps = dimred.fit_transform(Vsteps)
#objective vector
plt.scatter(Vsteps[0,0],Vsteps[0,1],color='red',s=30,marker=(5,1))
#Optimization steps
plt.scatter(Vsteps[1:,0],Vsteps[1:,1],color=distcolors,alpha=0.5)
plt.show()
开发者ID:RicardoCorralC,项目名称:trajectory_plotter,代码行数:32,代码来源:plotTraj.py
示例4: isomap
def isomap(similarity, euclid=False):
if not euclid:
print('podvod')
model = Isomap(n_neighbors=15)
result = model.fit_transform(similarity)
return result.T
开发者ID:thran,项目名称:experiments2.0,代码行数:7,代码来源:projection.py
示例5: iso_map
def iso_map(data, target, target_names):
iso = Isomap(n_components=2)
data_projected = iso.fit_transform(data)
formatter = plt.FuncFormatter(lambda i, *args:target_names[int(i)])
plt.figure(figsize=(8, 8))
plt.scatter(data_projected[:, 0], data_projected[:, 1], c=target,edgecolor='none', alpha=0.5, cmap=plt.cm.get_cmap('rainbow', len(target_names)));
plt.colorbar(ticks=sorted(list(set(target))), format=formatter)
#plt.clim(-200, 0)
return iso, data_projected
开发者ID:SamanthaChen,项目名称:codes,代码行数:9,代码来源:template.py
示例6: ISOMAP_transform
def ISOMAP_transform(train_feature, test_feature, n_components, n_neighbors = 5):
""" ISOMAP method
"""
from sklearn.manifold import Isomap
isomap = Isomap(n_neighbors, n_components).fit(train_feature)
train_feature_transformed = isomap.transform(train_feature)
test_feature_transformed = isomap.transform(test_feature)
return train_feature_transformed, test_feature_transformed
开发者ID:hitalex,项目名称:CCDM2014-contest,代码行数:10,代码来源:dimension_reduction.py
示例7: embedDistanceMatrix
def embedDistanceMatrix(dmatDf, method='kpca', n_components=2, **kwargs):
"""Two-dimensional embedding of sequence distances in dmatDf,
returning Nx2 x,y-coords: tsne, isomap, pca, mds, kpca, sklearn-tsne"""
if isinstance(dmatDf, pd.DataFrame):
dmat = dmatDf.values
else:
dmat = dmatDf
if method == 'tsne':
xy = tsne.run_tsne(dmat, no_dims=n_components, perplexity=kwargs['perplexity'])
elif method == 'isomap':
isoObj = Isomap(n_neighbors=10, n_components=n_components)
xy = isoObj.fit_transform(dmat)
elif method == 'mds':
mds = MDS(n_components=n_components,
max_iter=3000,
eps=1e-9,
random_state=15,
dissimilarity="precomputed",
n_jobs=1)
xy = mds.fit(dmat).embedding_
rot = PCA(n_components=n_components)
xy = rot.fit_transform(xy)
elif method == 'pca':
pcaObj = PCA(n_components=None)
xy = pcaObj.fit_transform(dmat)[:, :n_components]
elif method == 'kpca':
pcaObj = KernelPCA(n_components=dmat.shape[0], kernel='precomputed', eigen_solver='dense')
try:
gram = dist2kernel(dmat)
except:
print('Could not convert dmat to kernel for KernelPCA; using 1 - dmat/dmat.max() instead')
gram = 1 - dmat / dmat.max()
xy = pcaObj.fit_transform(gram)[:, :n_components]
elif method == 'lle':
lle = manifold.LocallyLinearEmbedding(n_neighbors=30, n_components=n_components, method='standard')
xy = lle.fit_transform(dist)
elif method == 'sklearn-tsne':
tsneObj = TSNE(n_components=n_components, metric='precomputed', random_state=0, perplexity=kwargs['perplexity'])
xy = tsneObj.fit_transform(dmat)
elif method == 'umap':
umapObj = umap.UMAP(n_components=n_components, metric='precomputed', **kwargs)
xy = umapObj.fit_transform(dmat)
else:
print('Method unknown: %s' % method)
return
assert xy.shape[0] == dmatDf.shape[0]
xyDf = pd.DataFrame(xy[:, :n_components], index=dmatDf.index, columns=np.arange(n_components))
if method == 'kpca':
"""Not sure how negative eigenvalues should be handled here, but they are usually
small so it shouldn't make a big difference"""
setattr(xyDf, 'explained_variance_', pcaObj.lambdas_[:n_components]/pcaObj.lambdas_[pcaObj.lambdas_>0].sum())
return xyDf
开发者ID:agartland,项目名称:utils,代码行数:54,代码来源:embedding.py
示例8: ML
def ML( self ):
data = self.data.values[ :, :-3 ]
scaler = MinMaxScaler()
#scaler = StandardScaler()
X = scaler.fit_transform( data )
#X = data
isomap = Isomap( n_components = 2 )
isomap.fit( X )
#print pca.explained_variance_ratio_
import pdb; pdb.set_trace()
开发者ID:jjardel,项目名称:bd-bq,代码行数:11,代码来源:dealerML.py
示例9: __init__
def __init__(self):
"""
Instantiate floorplan estimator
"""
self.dimred = Isomap(n_neighbors=25, n_components=2)
self._fingerprints = None
self._label = None
开发者ID:tomvand,项目名称:fingerprint-localization,代码行数:7,代码来源:fpFloorplan.py
示例10: isomap
def isomap(self, data):
print 'Isomap neighbours :', self.parameters["n_neighbors"]
print 'Isomap components, ie final number of coordinates :', self.k
k_means_n_clusters=self.parameters['k_means_n_clusters']
isomap_params = dict(self.parameters)
del isomap_params["k_means_n_clusters"]
m = Isomap(neighbors_algorithm = 'kd_tree',**isomap_params)#eigen_solver='auto', tol=0, path_method='auto', neighbors_algorithm='kd_tree')
x = m.fit_transform(data)
error=m.reconstruction_error()
geod_d = m.dist_matrix_.flatten()
new_euclid_d = cdist(x, x, metric='euclidean').flatten()
corr=1- pearsonr(geod_d, new_euclid_d)[0]**2
new_data = x
print self.parameters
return self.batch_kmeans(new_data, parameters = dict(zip(params["mini-batchk-means"], [k_means_n_clusters, 1000, 500, 1000, 'k-means++', 5])))
开发者ID:PeterJackNaylor,项目名称:Xb_screen,代码行数:18,代码来源:clustering.py
示例11: isomap
def isomap(file_name, dimension, num_neighbors, label):
balls = np.loadtxt(file_name)
matrix = balls[:, 0:dimension]
new_matrix = convert_angles_to_cos_sin(matrix)
imap = Isomap(n_neighbors=num_neighbors, n_components=2, eigen_solver='auto', tol=0, max_iter=None,
path_method='auto', neighbors_algorithm='auto')
transformed_matrix = imap.fit_transform(new_matrix)
ball_coords = np.zeros((balls.shape[0], dimension+3))
for i in xrange(balls.shape[0]):
ball_coords[i, 0:dimension] = balls[i, 0:dimension].tolist()
ball_coords[i, dimension:dimension+2] = transformed_matrix[i]
if label == 'cluster':
ball_coords[i, dimension+2] = balls[i, dimension].tolist()
elif label == 'eq':
ball_coords[i, dimension+2] = (-0.0019872041*300*np.log(abs(balls[i, dimension+1]))).tolist()
elif label == 'committor':
ball_coords[i, dimension+2] = (balls[i, dimension+2]/abs(balls[i, dimension+1])).tolist()
print ' '.join([str(x) for x in ball_coords[i, :]])
开发者ID:shirleyahn,项目名称:CAS_Code,代码行数:18,代码来源:dim_reduction.py
示例12: mult_scl
def mult_scl(X, labels):
print('labels:')
for i, label in zip(range(1, len(labels) + 1), labels):
print('{}: {}'.format(i, label))
isomap = Isomap()
points = isomap.fit(np.nan_to_num(X)).embedding_
f, (ax1, ax2, ax3) = plt.subplots(1, 3)
plot_location(labels, ax3)
ax1.scatter(points[:, 0], points[:, 1], s=20, c='r')
ax1.set_title('Isomap')
add_labels(labels, points, ax1)
mds = MDS()
points = mds.fit(np.nan_to_num(X)).embedding_
ax2.scatter(points[:, 0], points[:, 1], s=20, c='g')
ax2.set_title('MDS')
add_labels(labels, points, ax2)
plt.show()
开发者ID:Sandy4321,项目名称:sml_project_2,代码行数:20,代码来源:mds.py
示例13: compute_iso_map
def compute_iso_map(self, original_features):
feature_matrix = original_features.drop('file', 1).as_matrix()
feature_matrix = np.nan_to_num(feature_matrix)
dimen_reductor = Isomap(n_components=self.n_components)
full_size = feature_matrix.shape[0]
train_size = int(self.ratio * full_size)
row_indices = list(range(full_size))
feature_training_indices = np.random.choice(row_indices, size = train_size)
training_feature_matrix = feature_matrix[feature_training_indices, :]
dimen_reductor.fit(training_feature_matrix)
reduced_features = dimen_reductor.transform(feature_matrix)
reduced_normalized_features = reduced_features - reduced_features.min(axis=0)
reduced_normalized_features /= reduced_normalized_features.max(axis=0)
return reduced_normalized_features
开发者ID:tcoatale,项目名称:cnn_framework,代码行数:20,代码来源:isomap_extractor.py
示例14: isomap
def isomap(self, n_components=2, n_neighbors=3, show=False):
"""
Calculates lower dimention coordinates using the isomap algorithm.
:param n_components: dimentionality of the reduced space
:type n_components: int, optional
:param n_neighbors: Used by isomap to determine the number of neighbors
for each point. Large neighbor size tends to produce a denser map.
:type n_neighbors: int, optional
:param show: Shows the calculated coordinates if true.
:type show: boolean, optional
"""
model = Isomap(n_components=n_components, n_neighbors=n_neighbors)
self.pos = model.fit(self.dismat).embedding_
if show:
return self.pos
开发者ID:HANNATH,项目名称:vsm,代码行数:20,代码来源:manifold.py
示例15: outputBin
def outputBin(data, ctrlSize,nbPheno, lPheno, binSize, sigma, nbDim=2, nbNeighbours=20):
m = Isomap(n_neighbors=nbNeighbours, n_components=nbDim, eigen_solver='auto', tol=0, max_iter=None, path_method='auto', neighbors_algorithm='kd_tree')
D = m.fit_transform(data)
ctrl = D[:ctrlSize]
ctrlTree = KDTree(ctrl, leafsize=10)
length=ctrlSize
mini = np.amin(D, 0); maxi=np.amax(D, 0);
nbPointsX = int((maxi[0]-mini[0])/float(binSize))+1
nbPointsY = int((maxi[1]-mini[1])/float(binSize))+1
result = np.zeros(shape=(nbPheno, nbPointsX, nbPointsY))
denomCtrl = np.zeros(shape=(nbPointsX, nbPointsY))
for pointX, pointY in product(range(nbPointsX), range(nbPointsY)):
x=mini[0]+(pointX+0.5)*binSize; y=mini[1]+(pointY+0.5)*binSize
ctrldou, ctrli = ctrlTree.query((x, y), ctrlSize, distance_upper_bound=binSize/sqrt(2))
if min(ctrldou)<100:
ctrlPoint = filter(lambda t: t[1]<ctrl.shape[0] and np.all(np.abs(ctrl[t[1]]-(x, y))<(binSize/2.0, binSize/2.0)), zip(ctrldou, ctrli))
for distance, cPoint in ctrlPoint:
denomCtrl[pointX, pointY]+=dist((x,y), ctrl[cPoint], sigma)
for ifilm in range(nbPheno):
print 'film ', ifilm
pheno = D[length:length+lPheno[ifilm]]
phenoTree = KDTree(pheno, leafsize=10)
for pointX, pointY in product(range(nbPointsX), range(nbPointsY)):
x=mini[0]+(pointX+0.5)*binSize; y=mini[1]+(pointY+0.5)*binSize
denom=denomCtrl[pointX, pointY]
phenodou, phenoi=phenoTree.query((x, y), data.shape[0]-ctrlSize, distance_upper_bound=binSize/sqrt(2))
if min(phenodou)<100:
phenoPoint =filter(lambda t: t[1]<pheno.shape[0] and np.all(np.abs(pheno[t[1]]-(x, y))<(binSize/2.0, binSize/2.0)), zip(phenodou, phenoi))
for distance, pPoint in phenoPoint:
local = dist((x,y), pheno[pPoint], sigma)
result[ifilm, pointX, pointY]+=local; denom+=local
length+=lPheno[ifilm]
if denom>0:result[ifilm, pointX, pointY]/=denom
plotMovies('/media/lalil0u/New/workspace2/Tracking/images', result, 'pattern_b{}_s{}'.format(binSize, sigma))
return result
开发者ID:PeterJackNaylor,项目名称:Xb_screen,代码行数:40,代码来源:exploiting_clustering.py
示例16: plot_2d
def plot_2d(dataset):
"""TODO: Docstring for plot_2d.
:returns: TODO
"""
iso = Isomap(n_components=2)
projected = iso.fit_transform(dataset.data.toarray())
print 'projected: sample: %s, feature: %s'\
% (projected.shape[0], projected.shape[1])
all_scatter = []
colors = cm.rainbow(np.linspace(0, 1, len(dataset.target_names)), alpha=0.5)
for i in range(len(dataset.target_names)):
points = projected[dataset.target==i,:]
cur = plt.scatter(points[:,0], points[:,1], color=colors[i],
edgecolor='k', lw=0.6,
vmin=0, vmax=len(dataset.target_names))
all_scatter.append(cur)
plt.legend(all_scatter, dataset.target_names,
loc='lower left', scatterpoints=1)
plt.clim(-0.5, 9.5)
plt.savefig('isomap2d', dpi=500)
开发者ID:ShiehShieh,项目名称:Code_Identifier,代码行数:23,代码来源:visualization.py
示例17: embedDistanceMatrix
def embedDistanceMatrix(dist,method='tsne'):
"""MDS embedding of sequence distances in dist, returning Nx2 x,y-coords: tsne, isomap, pca, mds, kpca"""
if method == 'tsne':
xy = tsne.run_tsne(dist, no_dims=2)
#xy=pytsne.run_tsne(adist,no_dims=2)
elif method == 'isomap':
isoObj = Isomap(n_neighbors=10, n_components=2)
xy = isoObj.fit_transform(dist)
elif method == 'mds':
mds = manifold.MDS(n_components=2, max_iter=3000, eps=1e-9, random_state=15,
dissimilarity="precomputed", n_jobs=1)
xy = mds.fit(dist).embedding_
rot = PCA(n_components=2)
xy = rot.fit_transform(xy)
elif method == 'pca':
pcaObj = PCA(n_components=2)
xy = pcaObj.fit_transform(1-dist)
elif method == 'kpca':
pcaObj = KernelPCA(n_components=2, kernel='precomputed')
xy = pcaObj.fit_transform(1-dist)
elif method == 'lle':
lle = manifold.LocallyLinearEmbedding(n_neighbors=30, n_components=2, method='standard')
xy = lle.fit_transform(dist)
return xy
开发者ID:agartland,项目名称:utils,代码行数:24,代码来源:seqdistance_old.py
示例18: PCA
pca = PCA(n_components=3)
pca.fit(df)
T = pca.transform(df)
Plot2D(T, 'chart title', 1,2)
#
# TODO: Implement Isomap here. Reduce the dataframe df down
# to THREE components. Once you've done that, call Plot2D using
# the first two components.
#
# .. your code here ..
from sklearn.manifold import Isomap
im = Isomap(n_components=3)
im.fit(df)
T = im.transform(df)
Plot2D(T, 'chart title', 1,2)
#
# TODO: If you're up for a challenge, draw your dataframes in 3D
# Even if you're not, just do it anyway.
#
# .. your code here ..
fig = plt.figure()
ax = fig.add_subplot(111,projection="3d")
ax.set_xlabel('0')
ax.set_ylabel('1')
开发者ID:griblik,项目名称:scratch,代码行数:30,代码来源:assignment4.py
示例19: PCA
# title is your chart title
# x is the principal component you want displayed on the x-axis, Can be 0 or 1
# y is the principal component you want displayed on the y-axis, Can be 1 or 2
#
# .. your code here ..
from sklearn.decomposition import PCA
pca = PCA(n_components=3)
pca.fit(df)
T = pca.transform(df)
Plot2D(T, "PCA 1 2", 1, 2)
#
# TODO: Implement Isomap here. Reduce the dataframe df down
# to THREE components. Once you've done that, call Plot2D using
# the first two components.
#
# .. your code here ..
from sklearn.manifold import Isomap
imap = Isomap(n_neighbors=8, n_components=3)
imap.fit(df)
T2 = imap.transform(df)
Plot2D(T2, "Isomap", 1, 2)
#
# TODO: If you're up for a challenge, draw your dataframes in 3D
# Even if you're not, just do it anyway.
#
# .. your code here ..
plt.show()
开发者ID:anhualin,项目名称:MyLearning,代码行数:30,代码来源:assignment4.py
示例20: plot2D_classification
def plot2D_classification(self, query=None, colors=None, markers=['*', 'v', 'o', '+', '-', '.', ',']):
X, y = self.__check_data_available()
n_row, n_col = X.shape
import matplotlib.pyplot as plt
import matplotlib as mpl
c_map = plt.cm.get_cmap("hsv", self._nb_clazz + 1)
colors = dict((self._clazz[idx], c_map(idx)) for idx in range(0, self._nb_clazz)) \
if colors is None else colors
markers = dict((self._clazz[idx], markers[idx]) for idx in range(0, self._nb_clazz))
def plot_constraints(lower, upper, _linestyle="solid"):
plt.plot([lower[0], lower[0], upper[0], upper[0], lower[0]],
[lower[1], upper[1], upper[1], lower[1], lower[1]],
linestyle=_linestyle)
plt.grid()
def plot2D_scatter(X, y):
for row in range(0, len(y)):
plt.scatter(X[row, 0], X[row, 1], marker=markers[y[row]], c=colors[y[row]])
def plot_ellipse(splot, mean, cov, color):
from scipy import linalg
v, w = linalg.eigh(cov)
u = w[0] / linalg.norm(w[0])
angle = np.arctan(u[1] / u[0])
angle = 180 * angle / np.pi
ell = mpl.patches.Ellipse(mean, 2 * v[0] ** 0.5, 2 * v[1] ** 0.5,
180 + angle, facecolor="none",
edgecolor=color,
linewidth=2, zorder=2)
ell.set_clip_box(splot.bbox)
ell.set_alpha(0.9)
splot.add_artist(ell)
if n_col == 2:
for clazz in self._clazz:
post_mean_lower = self._mean_lower[clazz]
post_mean_upper = self._mean_upper[clazz]
plot_constraints(post_mean_lower, post_mean_upper)
mean = self.get_mean_by_clazz(clazz)
prior_mean_lower = mean - self.ell
prior_mean_upper = mean + self.ell
plot_constraints(prior_mean_lower, prior_mean_upper, _linestyle="dashed")
if query is not None:
ml_mean, ml_cov, ml_prob = self.fit_max_likelihood(query)
plt.plot([query[0]], [query[1]], marker='h', markersize=5, color="black")
_, _bounds = self.evaluate(query)
for clazz in self._clazz:
plt.plot([ml_mean[clazz][0]], [ml_mean[clazz][1]], marker='o', markersize=5, color=colors[clazz])
_, est_mean_lower = _bounds[clazz]['inf']
_, est_mean_upper = _bounds[clazz]['sup']
plt.plot([est_mean_lower[0]], [est_mean_lower[1]], marker='x', markersize=4, color="black")
plt.plot([est_mean_upper[0]], [est_mean_upper[1]], marker='x', markersize=4, color="black")
cov, inv, det = self.__cov_group_sample()
s_plot = plt.subplot()
for clazz in self._clazz:
mean = self.get_mean_by_clazz(clazz)
plot_ellipse(s_plot, mean, cov, colors[clazz])
elif n_col > 2:
if query is not None:
inference, _ = self.evaluate(query)
X = np.vstack([X, query])
y = np.append(y, inference[0])
from sklearn.manifold import Isomap
iso = Isomap(n_components=2)
projection = iso.fit_transform(X)
X = np.c_[projection[:, 0], projection[:, 1]]
if query is not None:
color_instance = colors[inference[0]] if len(inference) == 1 else 'black'
plt.plot([X[n_row, 0]], [X[n_row, 1]], color='red', marker='o', mfc=color_instance)
else:
raise Exception("Not implemented for one feature yet.")
plot2D_scatter(X, y)
plt.show()
开发者ID:sdestercke,项目名称:classifip,代码行数:84,代码来源:qda.py
注:本文中的sklearn.manifold.Isomap类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论