2

私はattributesskbio'sPCoA(以下に記載)の方法で探しています。私はこの新しいAPIに新しく、を得て、.fit_transformsklearn.decomposition.PCAに似た新しい軸に投影された元の点が得られるように、PC_1 vs PC_2スタイルのプロットを作成することができます。私はeigvalsproportion_explainedを得る方法を考え出しましたが、featuresNoneとして戻ってきます。`skbio` PCoA(Principal Coordinate Analysis)の結果を得る方法は?

これはベータ版のためですか?

これを使用するチュートリアルがあれば、それは非常に感謝しています。私はscikit-learnの巨大なファンであり、より多くの製品を使用開始したいと考えていますscikit's製品。

| Attributes 
| ---------- 
| short_method_name : str 
|  Abbreviated ordination method name. 
| long_method_name : str 
|  Ordination method name. 
| eigvals : pd.Series 
|  The resulting eigenvalues. The index corresponds to the ordination 
|  axis labels 
| samples : pd.DataFrame 
|  The position of the samples in the ordination space, row-indexed by the 
|  sample id. 
| features : pd.DataFrame 
|  The position of the features in the ordination space, row-indexed by 
|  the feature id. 
| biplot_scores : pd.DataFrame 
|  Correlation coefficients of the samples with respect to the features. 
| sample_constraints : pd.DataFrame 
|  Site constraints (linear combinations of constraining variables): 
|  coordinates of the sites in the space of the explanatory variables X. 
|  These are the fitted site scores 
| proportion_explained : pd.Series 
|  Proportion explained by each of the dimensions in the ordination space. 
|  The index corresponds to the ordination axis labels 

ここにprincipal component analysisオブジェクトを生成するコードです。

import numpy as np 
import pandas as pd 
import matplotlib.pyplot as plt 
from sklearn.datasets import load_iris 
from sklearn.preprocessing import StandardScaler 
from sklearn import decomposition 
import seaborn as sns; sns.set_style("whitegrid", {'axes.grid' : False}) 
import skbio 
from scipy.spatial import distance 

%matplotlib inline 
np.random.seed(0) 

# Iris dataset 
DF_data = pd.DataFrame(load_iris().data, 
         index = ["iris_%d" % i for i in range(load_iris().data.shape[0])], 
         columns = load_iris().feature_names) 
n,m = DF_data.shape 
# print(n,m) 
# 150 4 

Se_targets = pd.Series(load_iris().target, 
         index = ["iris_%d" % i for i in range(load_iris().data.shape[0])], 
         name = "Species") 

# Scaling mean = 0, var = 1 
DF_standard = pd.DataFrame(StandardScaler().fit_transform(DF_data), 
          index = DF_data.index, 
          columns = DF_data.columns) 

# Distance Matrix 
Ar_dist = distance.squareform(distance.pdist(DF_standard.T, metric="braycurtis")) # (m x m) distance measure 
DM_dist = skbio.stats.distance.DistanceMatrix(Ar_dist, ids=DF_standard.columns) 
PCoA = skbio.stats.ordination.pcoa(DM_dist) 

enter image description here

答えて

5

あなたは、変換されたサンプルは、OrdinationResults.samplesと調整アクセスすることができます。これにより、サンプルID(すなわち、距離行列のID)によって行インデックスされたpandas.DataFrameが返されます。主座標分析はサンプルの距離マトリックス上で動作するので、変換された特徴座標(OrdinationResults.features)は利用できません。サンプルx特徴テーブルを入力として受け入れるscikit-bioの他のアライメント方法は、利用可能な変換された特徴座標(例えば、CA、CCA、RDA)を有する。

注:skbio.DistanceMatrixは方形またはベクトル形式の配列をサポートしているため、distance.squareformコールは不要です。

+0

私は '.samples'は何も返されないと信じています。私はもう一度やり直すことができます、私は私の 'skbio'を更新していることを確認します。私はPCoAについて読んできましたが、多くのリソースはかなりわかりにくいです。 PCAに関しては、それは同じステップであるが、共分散行列の代わりに距離行列上の固有分解であるか? –

+1

'' pcoa 'によって生成された 'OrdinationResults'に' .samples'が必要です。まだ 'None'を取得している場合は、[scikit-bio issue tracker](https://github.com/biocore/scikit-bio/issues)に問題を投稿してください。私の理解では、PCoAは距離行列に適用され、非ユークリッド距離メトリクスの使用が可能になりますが、PCAはフィーチャテーブルに適用されユークリッド距離が使用されます。したがって、ユークリッド距離行列上でPCoAを実行することは、PCAと同等である。 [ここにある](http://ordination.okstate.edu/overview.htm#Principal_coordinates_analysis)は、指導方法の役に立つ資料です。 – jairideout

+0

'DF = skbio.OrdinationResults(long_method_name =" TESTING "、short_method_name ="テスト "、eigvals = PCoA.eigvals、samples = DF_data) DF.samples'は変換されていない元のデータを返します。私はこれを間違ってやっていますか? –