python中da_Python中的PLSDA加载图

本文介绍如何使用Python的Matplotlib库结合PLS-DA(偏最小二乘判别分析)来绘制加载图,通过具体代码示例展示了从数据预处理到最终图表呈现的全过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如何使用PLS-DA绘图的Matplotlib绘制加载图,如PCA的加载图?在

为了绘制PLS-DA图,我使用以下代码:from sklearn.preprocessing import StandardScaler

from sklearn.cross_decomposition import PLSRegression

import numpy as np

import pandas as pd

targets = [0, 1]

x_vals = StandardScaler().fit_transform(df.values)

y = [g == targets[0] for g in sample_description]

y = np.array(y, dtype=int)

plsr = PLSRegression(n_components=2, scale=False)

plsr.fit(x_vals, y)

colormap = {

targets[0]: '#ff0000', # Red

targets[1]: '#0000ff', # Blue

}

colorlist = [colormap[c] for c in sample_description]

scores = pd.DataFrame(plsr.x_scores_)

scores.index = x.index

x_loadings = plsr.x_loadings_

y_loadings = plsr.y_loadings_

fig1, ax = get_default_fig_ax('Scores on LV 1', 'Scores on LV 2', title)

ax = scores.plot(x=0, y=1, kind='scatter', s=50, alpha=0.7,

c=colorlist, ax=ax)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值