Skip to main content

The multi data driven sparse pls package

Project description

=====================================
Multi (& Mono) Data-Driven Sparse PLS
=====================================

*mddspls is the python light package of the data-driven sparse PLS algorithm*

In the high dimensional settings (large number of variables), one objective is to select the relevant variables and thus to reduce the dimension. That subspace selection is often managed with supervised tools. However, some data can be missing, compromising the validity of the sub-space selection. We propose a PLS, Partial Least Square, based method, called **dd-sPLS** for data-driven-sparse PLS, allowing jointly variable selection and subspace estimation while training and testing missing data imputation through a new algorithm called Koh-Lanta.

It contains one main class **mddspls** and one associated important method denote **predict** permitting to predict from a new dataset. The function called **perf_mddsPLS** permits to compute cross-validation.

Data simulation
===============
One might be interested to simulate data and test the package through **regression** and **classification**.

#!/usr/bin/env python

import py_ddspls
import numpy as np
import sklearn.metrics as sklm
n = 100
mean = (0,0,0,0,0,0,0,0,0)
cov = [[1, 0.8,0.8,0.8,0.1,0.1,0.1,0.1,0.1],
[0.8,1, 0.8,0.8,0.1,0.1,0.1,0.1,0.1],
[0.8,0.8,1, 0.8,0.1,0.1,0.1,0.1,0.1],
[0.8,0.8,0.8,1, 0.1,0.1,0.1,0.1,0.1],
[0.1,0.1,0.1,0.1, 0.1,0.1,0.1,0.1,0.1],
[0.1,0.1,0.1,0.1, 0.1,0.1,0.1,0.1,0.1],
[0.1,0.1,0.1,0.1, 0.1,0.1,0.1,0.1,0.1],
[0.1,0.1,0.1,0.1, 0.1,0.1,0.1,0.1,0.1],
[0.1,0.1,0.1,0.1, 0.1,0.1,0.1,0.1,0.1]]
df = np.random.multivariate_normal(mean, cov, n)
Y = df[:,[0]]
k_groups = 2
lolo = np.linspace(min(Y),max(Y),k_groups+1)
Y_bin = np.zeros(n)
for ii in range(n):
for k_i in range(k_groups):
if (Y[ii]>=lolo[k_i])&(Y[ii]<lolo[k_i+1]):
Y_bin[ii] = k_i
if Y[ii]==lolo[k_groups]:
Y_bin[ii] = k_groups-1

Y = df[:,[0,2]]
X0 = df[:,[1,4,5]]
X0[0,:] = None
X1 = df[:,[6,8]]
X1[:,1] = 1
X2 = df[:,[3,7]]
Xs = {0:X0,1:X1,2:X2}
pos_0 = np.where(Y_bin==0)[0]
pos_1 = np.where(Y_bin==1)[0]
Y_classif = np.repeat("Class 2",n)
Y_classif[pos_1] = "Class 1"

The dd-sPLS regularization parameter is fixed to 0.6

lambd=0.6

A train/test dataset is defined

id_train = range(30,100)
id_test = range(30)
Xtrain = {0:X0[id_train,:],1:X1[id_train,:],2:X2[id_train,:]}
Ytrain = Y[id_train,:]
Xtest = {0:X0[id_test,:],1:X1[id_test,:],2:X2[id_test,:]}

Regression analysis
-------------------

Let us produce *2* axes.

R=2

Start model building and tcheck results with sklearn tools

mod_0=py_ddspls.model.ddspls(Xtrain,Ytrain,lambd=lambd,R=R,mode="reg",verbose=True)
Y_est_reg = mod_0.predict(Xtest)
print(sklm.mean_squared_error(Y[id_test,:],Y_est_reg))

Cross validation can be performed with built tools, the parameter **NCORES** permits to use parallellization

perf_model_reg = py_ddspls.model.perf_ddspls(Xs,Y,R=R,kfolds=3,n_lambd=3,NCORES=3,mode="reg")

Classification analysis
-----------------------

Let us produce *1* axis.

R=1

Start model building and tcheck results with sklearn tools

mod_0_classif=py_ddspls.model.ddspls(Xs,Y_bin,lambd=lambd,R=R,mode="clas",verbose=True)
Y_est = mod_0_classif.predict(Xtest)
print(sklm.classification_report(Y_est, Y_classif[id_test]=='Class 1'))

Cross validation can be performed with built tools, the parameter **NCORES** permits to use parallellization

perf_model_class = py_ddspls.model.perf_ddspls(Xs,Y_classif,R=1,kfolds=3,n_lambd=3,NCORES=3,mode="classif")


**Enjoy**

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_ddspls-1.0.6.tar.gz (8.9 kB view details)

Uploaded Source

File details

Details for the file py_ddspls-1.0.6.tar.gz.

File metadata

  • Download URL: py_ddspls-1.0.6.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.7

File hashes

Hashes for py_ddspls-1.0.6.tar.gz
Algorithm Hash digest
SHA256 8e03f869a599543b51ea89077b2fdd06253a72ed7287f5fae383b31d1cfed099
MD5 5523ae81d3bd72d2e9070feb02c32333
BLAKE2b-256 4baf382fd8181b1daf0a7eaaf8415b11815c503f38c7df9be2cbeda63268c1b0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page