Skip to main content

It is a Python library for the N-PLS1 regression with L1 and L2-regularization.

Project description

npls

PyPI Python 3.8, 3.9, 3.10, 3.11,3.12 GitHub Pull Requests License Forks

npls - this module is a Python library for the N-PLS1 regression with L1 and L2-regularization.

Installation

Install the current version with PyPI:

pip install npls

Or from Github:

pip install https://github.com/89605502155/npls/main.zip

Usage

You can fit your own regression model. n_components - is a number of components of SVD decomposition and l2 is a parameter of L2-regularization (Ridge) and l1 is a parameter of L1-regularization (LASSO), excitation_wavelenth - is an excitation wavelenth of fluor. (if you have not excitation wavelenth you can write list with len equal first shape of X_train),emission_wavelenth is an emission wavelenth. X_train - is a 3d-array. y_train -is a vector.

from npls import npls 

model=npls(n_components=4, l2=0.09)
model.fit(X_train,y_train)
#components of svd-decomposition
w_i=model.w_i
w_k=model.w_k
#predict
y_predicted=model.predict(X_test)

If you want to use snr, you need input excitation_wavelenth and emission_wavelenth, crash_norm_name and crash_norm_value and norm_func and derivative_rang. Example:

from npls import npls 
model=npls(crash_norm_name='evklid',derivative_rang=[1],
    emission_wavelenth=np.array([1,2,3]),
    excitation_wavelenth=np.array([1,2,3]),
    crash_norm_value=9)

and with use L2 and N components:

from npls import npls 
model=npls(crash_norm_name='evklid',derivative_rang=[1],
    emission_wavelenth=np.array([1,2,3]),
    excitation_wavelenth=np.array([1,2,3]),
    crash_norm_value=9,n_components=4, l2=0.09)

Example

You can use this library with Scikit-learn library. For example, we can use GridSearchCV.

If you installed a module from PyPi, you should to import it like this: from npls import npls

If from GitHub or source: from npls import npls

from npls import npls 
from sklearn.metrics import mean_squared_error
from sklearn.metrics import r2_score, make_scorer
import sklearn
from sklearn.model_selection import GridSearchCV

npls1=npls(excitation_wavelenth=[501,552],emission_wavelenth=[553,604])
#you can use many error metrics
scoring={'mse': make_scorer(mean_squared_error),'r2':'r2'}
parametrsNames={'n_components': [4],
                'l2': np.logspace(-25, 25,num = 51),
                'l1': np.logspace(-25, 25,num = 51)
                }

gridCought=GridSearchCV(npls1, parametrsNames, cv=5, 
    scoring=scoring,refit='r2',return_train_score=True)
gridCought.fit(X_train,y_train)
#errors
r2_p=gridCought.score(X_test.copy(), y_test.copy())
mse_cv=gridCought.cv_results_[ "mean_test_mse" ]
mse_c=gridCought.cv_results_[ "mean_train_mse" ]
r2_cv=gridCought.cv_results_[ "mean_test_r2" ]
r2_c=gridCought.cv_results_[ "mean_train_r2" ]

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

npls-0.0.7.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

npls-0.0.7-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file npls-0.0.7.tar.gz.

File metadata

  • Download URL: npls-0.0.7.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for npls-0.0.7.tar.gz
Algorithm Hash digest
SHA256 bec96b75f66a6c5745062817221f8c16f08b61f26c88af1efb658a1e22d265af
MD5 6b21f9705012c4ae69a8e690c4ecc34e
BLAKE2b-256 bea3a63ded5409d85cba761156712bd0cb3310dfc13601811dd7aca8da61a68c

See more details on using hashes here.

File details

Details for the file npls-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: npls-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for npls-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 66d545055583f0bb9a08b0966f5d93579fb59aff8c279300f3220e470b78a038
MD5 9ddbb103be6860c59f2fea434010ca99
BLAKE2b-256 71bab3114922a2e2c728630a44365075b9ebd86d042d357ef198f56ce5797b27

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