本文簡要介紹python語言中 sklearn.cluster.FeatureAgglomeration
的用法。
用法:
class sklearn.cluster.FeatureAgglomeration(n_clusters=2, *, affinity='euclidean', memory=None, connectivity=None, compute_full_tree='auto', linkage='ward', pooling_func=<function mean>, distance_threshold=None, compute_distances=False)
聚合特征。
遞歸地合並一對特征集群。
在用戶指南中閱讀更多信息。
- n_clusters:整數,默認=2
要查找的集群數。如果
distance_threshold
不是None
,則它必須是None
。- affinity:str 或可調用,默認='euclidean'
用於計算鏈接的度量。可以是“euclidean”、“l1”、“l2”、“manhattan”, “cosine” 或‘precomputed’。如果鏈接是“ward”,則隻接受“euclidean”。
- memory:帶有joblib.Memory 接口的str 或對象,默認=None
用於緩存樹計算的輸出。默認情況下,不進行緩存。如果給出一個字符串,它是緩存目錄的路徑。
- connectivity:類似數組或可調用,默認=無
連接矩陣。為每個特征定義遵循給定數據結構的相鄰特征。這可以是連接矩陣本身或將數據轉換為連接矩陣的可調用對象,例如從
kneighbors_graph
派生的。默認值為None
,即層次聚類算法是非結構化的。- compute_full_tree:‘auto’ 或布爾值,默認='auto'
在
n_clusters
處盡早停止樹的構建。如果集群的數量與特征的數量相比不小,這對於減少計算時間很有用。此選項僅在指定連接矩陣時有用。還要注意,當改變集群的數量並使用緩存時,計算完整的樹可能是有利的。如果distance_threshold
不是None
,則它必須是True
。默認情況下compute_full_tree
為 “auto”,當distance_threshold
不是None
或n_clusters
低於 100 或0.02 * n_samples
之間的最大值時,它等效於True
。否則,“auto” 等價於False
。- linkage:{“ward”, “complete”, “average”, “single”},默認=”ward”
使用哪個鏈接標準。鏈接標準確定在特征集之間使用哪個距離。該算法將合並使該標準最小化的集群對。
- “ward” 最小化被合並的集群的方差。
- “complete” 或最大鏈接使用兩組所有特征之間的最大距離。
- “average” 使用兩組每個特征的距離的平均值。
- “single” 使用兩組所有特征之間距離的最小值。
- pooling_func:可調用,默認=np.mean
這會將聚集特征的值組合成一個值,並且應該接受一個形狀為 [M, N] 的數組和關鍵字參數
axis=1
,並將其縮減為一個大小為 [M] 的數組。- distance_threshold:浮點數,默認=無
鏈接距離閾值,超過該閾值,集群將不會被合並。如果不是
None
,則n_clusters
必須是None
並且compute_full_tree
必須是True
。- compute_distances:布爾,默認=假
即使不使用
distance_threshold
,也會計算集群之間的距離。這可用於進行樹狀圖可視化,但會引入計算和內存開銷。
- n_clusters_:int
算法找到的聚類數。如果
distance_threshold=None
,它將等於給定的n_clusters
。- labels_:(n_features,) 的類似數組
每個特征的聚類標簽。
- n_leaves_:int
層次樹中的葉子數。
- n_connected_components_:int
圖中連接組件的估計數量。
- n_features_in_:int
擬合期間看到的特征數。
- feature_names_in_:ndarray 形狀(
n_features_in_
,) 擬合期間看到的特征名稱。僅當
X
具有全為字符串的函數名稱時才定義。- children_:形狀類似數組 (n_nodes-1, 2)
每個非葉節點的子節點。小於
n_features
的值對應於作為原始樣本的樹的葉子。大於或等於n_features
的節點i
是非葉節點,並且具有子節點children_[i - n_features]
。或者在 i-th 迭代中,children[i][0] 和 children[i][1] 合並形成節點n_features + i
。- distances_:形狀類似數組 (n_nodes-1,)
children_
中對應位置的節點之間的距離。僅在使用distance_threshold
或compute_distances
設置為True
時計算。
參數:
屬性:
例子:
>>> import numpy as np >>> from sklearn import datasets, cluster >>> digits = datasets.load_digits() >>> images = digits.images >>> X = np.reshape(images, (len(images), -1)) >>> agglo = cluster.FeatureAgglomeration(n_clusters=32) >>> agglo.fit(X) FeatureAgglomeration(n_clusters=32) >>> X_reduced = agglo.transform(X) >>> X_reduced.shape (1797, 32)
相關用法
- Python sklearn FeatureUnion用法及代碼示例
- Python sklearn FeatureHasher用法及代碼示例
- Python sklearn FactorAnalysis用法及代碼示例
- Python sklearn FastICA用法及代碼示例
- Python sklearn FunctionTransformer用法及代碼示例
- Python sklearn jaccard_score用法及代碼示例
- Python sklearn WhiteKernel用法及代碼示例
- Python sklearn CalibrationDisplay.from_predictions用法及代碼示例
- Python sklearn VotingRegressor用法及代碼示例
- Python sklearn gen_batches用法及代碼示例
- Python sklearn ExpSineSquared用法及代碼示例
- Python sklearn MDS用法及代碼示例
- Python sklearn adjusted_rand_score用法及代碼示例
- Python sklearn MLPClassifier用法及代碼示例
- Python sklearn train_test_split用法及代碼示例
- Python sklearn RandomTreesEmbedding用法及代碼示例
- Python sklearn GradientBoostingRegressor用法及代碼示例
- Python sklearn GridSearchCV用法及代碼示例
- Python sklearn log_loss用法及代碼示例
- Python sklearn r2_score用法及代碼示例
- Python sklearn ndcg_score用法及代碼示例
- Python sklearn ShrunkCovariance用法及代碼示例
- Python sklearn SelfTrainingClassifier用法及代碼示例
- Python sklearn load_svmlight_file用法及代碼示例
- Python sklearn make_pipeline用法及代碼示例
注:本文由純淨天空篩選整理自scikit-learn.org大神的英文原創作品 sklearn.cluster.FeatureAgglomeration。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。