python RDA (抄的)

import numpy as np
import pandas as pd

X = np.array([[1.0, 0.0, 1.0, 0.0],
              [2.0, 0.0, 1.0, 0.0],
              [3.0, 0.0, 1.0, 0.0],
              [4.0, 0.0, 0.0, 1.0],
              [5.0, 1.0, 0.0, 0.0],
              [6.0, 0.0, 0.0, 1.0],
              [7.0, 1.0, 0.0, 0.0],
              [8.0, 0.0, 0.0, 1.0],
              [9.0, 1.0, 0.0, 0.0],
              [10.0, 0.0, 0.0, 1.0]])
transects = ['depth', 'substrate_coral', 'substrate_sand',
             'substrate_other']
sites = ['site1', 'site2', 'site3', 'site4', 'site5', 'site6', 'site7',
         'site8', 'site9', 'site10']
X = pd.DataFrame(X, sites, transects)

species = ['specie1', 'specie2', 'specie3', 'specie4', 'specie5',
           'specie6', 'specie7', 'specie8', 'specie9']
Y = np.array([[1, 0, 0, 0, 0, 0, 2, 4, 4],
              [0, 0, 0, 0, 0, 0, 5, 6, 1],
              [0, 1, 0, 0, 0, 0, 0, 2, 3],
              [11, 4, 0, 0, 8, 1, 6, 2, 0],
              [11, 5, 17, 7, 0, 0, 6, 6, 2],
              [9, 6, 0, 0, 6, 2, 10, 1, 4],
              [9, 7, 13, 10, 0, 0, 4, 5, 4],
              [7, 8, 0, 0, 4, 3, 6, 6, 4],
              [7, 9, 10, 13, 0, 0, 6, 2, 0],
              [5, 10, 0, 0, 2, 4, 0, 1, 3]])
Y = pd.DataFrame(Y, sites, species)

from skbio.stats.ordination import cca
del X['substrate_other']
ordination_result = cca(Y, X, scaling=2)
print(ordination_result )

这个是cca的,RDA跟他差不多

画图抄下面的

def plot_metrics(vals, ylabel, objective, xticks):
    with plt.style.context('ggplot'):
        plt.plot(xticks, np.array(vals), '-v', color='blue', mfc='blue')
        if objective=='min':
            idx = np.argmin(vals)
        else:
            idx = np.argmax(vals)
        plt.plot(xticks[idx], np.array(vals)[idx], 'P', ms=10, mfc='red')
        plt.xlabel('Number of CCA components')
        plt.xticks = xticks
        plt.ylabel(ylabel)
        plt.title('CCA')
    plt.show()

后面想怎么调就怎么调呗,反正是骂他普劳特画的

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值