Skip to main content

Python中ProcessPLS的实现

项目描述

过程PLS

Python 中 ProcessPLS 的实现

代码编写者

由冼永腾执行。荷兰奈梅亨拉德布德大学。

执行

在此代码实现中,使用了 sklearn 语法。此外,ProcessPLS 算法已被表示为有向图数据结构。这允许更灵活地与图论例程一起使用。

功能

安装库

pip install processPLS

获取数据

from processPLS.model import *
from processPLS.datasets import *
X,Y,matrix=ValdeLoirData() #Get the data conviniently

或者,您可以像这样自己导入数据:

df=pd.read_csv(r'.\ValdeLoirData.csv')
df=df.drop(columns=df.columns[0])
smell_at_rest=df.iloc[:,:5]
view=df.iloc[:,5:8]
smell_after_shaking=df.iloc[:,8:18]
tasting=df.iloc[:,18:27]
global_quality=df.iloc[:,27]

X={
'Smell at Rest':smell_at_rest,
"View":view,
"Smell after Shaking":smell_after_shaking,
"Tasting":tasting,
}

Y={"Global Quality":global_quality}

matrix = pd.DataFrame(
[
[0,0,0,0,0], 
[1,0,0,0,0],
[1,1,0,0,0],
[1,1,1,0,0],
[1,1,1,1,0],
],
index=list(X.keys())+list(Y.keys()),
columns=list(X.keys())+list(Y.keys())
)

调用并拟合过程 PLS 模型

import matplotlib.pyplot as plt
model = ProcessPLS()
model.fit(X,Y,matrix)
model.plot
plt.show()

主要函数参数

Process_PLS(cv=RepeatedKFold(n_splits=5,n_repeats=2,random_state=999),scoring='neg_mean_squared_error',max_lv=30,overwrite_lv=False,inner_forced_lv=None,outer_forced_lv=None,name=None)

'''
This function sets up the processPLS model.

cv= cross validation method  (follows sklearn syntax)

scoring= loss function/ scoring function (follows sklearn syntax)

max_lv= maximum numbers of latent variable (lv) for all SIMPLS models within ProcessPLS

overwrite_LV= (True/False) A boolean to set whether inner_forced_lv and outer_forced_lv should be used instead of automatically selecting latent variables

inner_forced_lv= (dict) a specific key value combination of number of LVs to forced into the inner model. Argument overwrite_LV must be set to True for this to be used. Example input:
 inner_forced_lv={
  'Smell at Rest':None,
  "View":3,
  "Smell after Shaking":6,
  "Tasting":8,
  "Global Quality":13
  }

  inner_forced_lv= (dict) a specific key value combination of number of LVs to forced into the outer model. Argument overwrite_LV must be set to True for this to be used. Example input:

  outer_forced_lv={
  'Smell at Rest':3,
  "View":3,
  "Smell after Shaking":2,
  "Tasting":5,
  "Global Quality":3
  }

name: (string) Optional name of model.

'''

ValdeLoirData(original=False)

'''
This function gets the data for Valde Loir Dataset

original==False:  The function returns X (dataframe in dict), Y (dataframe dict), and matrix (dataframe). matrix is the adjacency matrix for the graph connections.

original==True:  The function returns the raw data (dataframe) with both X and Y combined within


'''

新数据的推理/预测

y_pred= model.predict(Xnew)

Colab 示例在这里

再现性

此实现提供与 MATLAB 版本的 ProcessPLS 完全相同的输出。

过程PLS

参考原始论文:

van Kollenburg, G.、Bouman, R.、Offermans, T.、Gerretzen, J.、Buydens, L.、van Manen, HJ 和 Jansen, J.,2021。过程 PLS:将实质性知识纳入多块预测建模、多步、多维和多共线过程数据。计算机与化学工程,154,p.107466。

对于 MATLAB 实现,请参阅 Tim Offermans 编写的这个存储库。 https://gitlab.science.ru.nl/toffermans/matlab-process-pls/-/tree/main/

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

内置分布

ProcessPLS-1.7-py3-none-any.whl (310.1 kB 查看哈希

已上传 py3