sklearn.manifold.Isomap?

class sklearn.manifold.Isomap(*, n_neighbors=5, n_components=2, eigen_solver='auto', tol=0, max_iter=None, path_method='auto', neighbors_algorithm='auto', n_jobs=None, metric='minkowski', p=2, metric_params=None)

[源碼]

等值圖嵌入

通過等距映射的非線性降維

用戶指南中閱讀更多內容。

參數 說明
n_neighbors integer
每個點要考慮的鄰域數。
n_components integer
流形的坐標數
eigen_solver ['auto'|'arpack'|'dense']
“auto”:嘗試為給定問題選擇最有效的解決方案。
“arpack”:使用Arnoldi分解來查找特征值和特征向量。
“dense”:使用直接解算器(即LAPACK)進行特征值分解。
tol float
傳遞給arpack或lobpcg的收斂公差。如果eigen_solver=='dense',則不使用。
max_iter integer
arpack求解器的最大迭代次數。如果eigen_solver =='dense',則不使用。
path_method string [‘auto’|’FW’|'D']
在尋找最短路徑時使用的方法。
“auto”:嘗試自動選擇最佳算法。
“FW”:Floyd-Warshall算法。
“D”:Dijkstra的算法。
neighbors_algorithm string[‘auto’|’brute’|’kd_tree’|’ball_tree’]
用于最近鄰居搜索的算法,傳遞給neighbors.NearestNeighbors實例。
n_jobs int or None, default=None
要并行運行的作業數。 None除非在joblib.parallel_backend上下文,否則表示1 。 -1表示使用所有處理器。有關更多詳細信息,請參見詞匯表
metric string, or callable, default=”minkowski”
計算要素陣列中實例之間的距離時使用的度量。如果metric是字符串或可調用,則它必須是sklearn.metrics.pairwise_distances的度量參數。如果度量是“預先計算的”,則將X假定為距離矩陣,并且必須為平方。X可能是一個詞匯表
0.22版中的新功能。
p int, default=2
sklearn.metrics.pairwise.pairwise_distances中的Minkowski指標的參數。當p = 1時,這等效于對p = 2使用manhattan_distance(l1)和euclidean_distance(l2)。對于任意p,使用minkowski_distance(l_p)。
0.22版中的新功能。
metric_params dict, default=None
度量功能的其他關鍵字參數。
0.22版中的新功能。
屬性 說明
embedding_ array-like, shape (n_samples, n_components)
存儲嵌入向量。
kernel_pca_ object
KernelPCA 用于實現嵌入的對象。
nbrs_ sklearn.neighbors.NearestNeighbors instance
存儲最近的實例,包括BallTree或KDtree(如果適用)。
dist_matrix_ array-like, shape (n_samples, n_samples)
存儲訓練數據的測地距離矩陣。

參考文獻

1 R7f4d308f5054-1 Tenenbaum, J.B.; De Silva, V.; & Langford, J.C. A global geometric framework for nonlinear dimensionality reduction. Science 290 (5500)

實例

>>> from sklearn.datasets import load_digits
>>> from sklearn.manifold import Isomap
>>> X, _ = load_digits(return_X_y=True)
>>> X.shape
(179764)
>>> embedding = Isomap(n_components=2)
>>> X_transformed = embedding.fit_transform(X[:100])
>>> X_transformed.shape
(1002)
方法 說明
fit(self, X[, y]) 計算數據X的嵌入向量
fit_transform(self, X[, y]) 根據X中的數據擬合模型并轉換X。
get_params(self[, deep]) 獲取此估計量的參數。
reconstruction_error(self) 計算嵌入的重建誤差。
set_params(self, **params) 設置此估算量的參數。
transform(self, X) 轉換X。
__init__(self, *, n_neighbors=5, n_components=2, eigen_solver='auto', tol=0, max_iter=None, path_method='auto', neighbors_algorithm='auto', n_jobs=None, metric='minkowski', p=2, metric_params=None)

[源碼]

初始化self, 請參閱help(type(self))以獲得準確的說明。

fit(self, X, y=None)

[源碼]

計算數據X的嵌入向量

參數 說明
X {array-like, sparse graph, BallTree, KDTree, NearestNeighbors}
以numpy數組,稀疏圖,預計算樹或NearestNeighbors對象形式的形狀為(n_samples,n_features)的樣本數據。
y Ignored
返回值 說明
self returns an instance of self.
get_params(self, deep=True)

[源碼]

獲取此估計量的參數。

參數 說明
deep bool, default=True
如果為True,則將返回此估算量和作為估算量的所包含子對象的參數。
返回值 說明
params mapping of string to any
參數名稱映射到其值。
reconstruction_error(self)

[源碼\]

計算嵌入的重建誤差。

返回值 說明
reconstruction_error float

等值線圖嵌入的成本函數為

E = frobenius_norm[K(D) - K(D_fit)] / n_samples

其中D是輸入數據X的距離矩陣,D_fit是輸出嵌入X_fit的距離矩陣,而K是isomap內核:

K(D) = -0.5 * (I - 1/n_samples) * D^2 * (I - 1/n_samples)
set_params(self, **params)

[源碼]

設置此估算量的參數。

該方法適用于簡單估計量以及嵌套對象(例如pipelines)。后者具有形式的參數。<component>__<parameter>以便可以更新嵌套對象的每個組件。

參數 說明
**params dict
估算量參數。
返回值 說明
self object
估算量實例。
transform(self, X)

[源碼]

轉換X。

這是通過將點X鏈接到訓練數據的測地距離圖中來實現的。首先在訓練數據中找到X的n_近鄰,然后計算出X上每個點到訓練數據中每個點的最短測地線距離,以構造核。X的嵌入是該核在訓練集的嵌入向量上的投影。

參數 說明
X array-like, shape (n_queries, n_features)
如果neighborks_algorithm='precomputed',則假設X是距離矩陣或形狀的稀疏圖(n_queries, n_samples_fit).
返回值 說明
X_new array-like, shape (n_queries, n_components)