Esempio n. 1
0
def dm_to_pcoa(dm, sample_md, category):
    title = "Samples colored by %s." % category
    pcoa_results = PCoA(dm).scores()
    _ = pcoa_results.plot(df=sample_md,
                          column=category,
                          axis_labels=['PC 1', 'PC 2', 'PC 3'],
                          title=title,
                          s=35)
Esempio n. 2
0
    'E': {
        'body_site': 'tongue',
        'subject': 's2'
    },
    'F': {
        'body_site': 'skin',
        'subject': 's2'
    }
}
sample_md = pd.DataFrame.from_dict(sample_md, orient='index')
sample_md
# subject body_site
# A      s1       gut
# B      s1      skin
# C      s1    tongue
# D      s2       gut
# E      s2    tongue
# F      s2      skin
# <BLANKLINE>
# [6 rows x 2 columns]

# Now let's plot our PCoA results, coloring each sample by the subject it
# was taken from:

fig = bc_pc.plot(sample_md,
                 'subject',
                 axis_labels=('PC 1', 'PC 2', 'PC 3'),
                 title='Samples colored by subject',
                 cmap='jet',
                 s=50)
Esempio n. 3
0
    'C': {
        'Méthode': 's3'
    },
    'D': {
        'Méthode': 's4'
    },
    'E': {
        'Méthode': 's5'
    }
}
df = pd.DataFrame.from_dict(metadata, orient='index')
pcoa_results = PCoA(dm).scores()
print(pcoa_results)
fig = pcoa_results.plot(
    df=df,
    column='Méthode',
    title='Estimation methods projected on 3 first principal components',
    cmap='Set1',
    s=500)
plt.show()
"""
digits = datasets.load_digits()
X = np.array([[ 0.         ,35.57933426 ,17.75168991 ,32.03273392 ,33.87740707],[35.57933426 , 0.         ,17.86463547 , 7.161726   , 5.87323952], [17.75168991 ,17.86463547 , 0.         ,14.88137054 ,16.6187191 ], [32.03273392 , 7.161726   ,14.88137054 , 0.          ,3.63054395], [33.87740707 , 5.87323952 ,16.6187191  , 3.63054395  ,0.        ]] )
print(type(X) )
y = np.array( [1, 2, 3, 4, 5])
print(y)
print(type(y) )
n_samples, n_features = X.shape
n_neighbors = 2


# ----------------------------------------------------------------------
import pandas as pd
metadata = {
    'A': {
        'body_site': 'skin'
    },
    'B': {
        'body_site': 'gut'
    },
    'C': {
        'body_site': 'gut'
    },
    'D': {
        'body_site': 'skin'
    }
}
df = pd.DataFrame.from_dict(metadata, orient='index')

# Run principal coordinate analysis (PCoA) on the distance matrix:

from skbio.stats.ordination import PCoA
pcoa_results = PCoA(dm).scores()

# Plot the ordination results, where each site is colored by body site
# (a categorical variable):

fig = pcoa_results.plot(df=df,
                        column='body_site',
                        title='Sites colored by body site',
                        cmap='Set1',
                        s=50)