Skip to main content

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" ]

Release files for npls 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for npls 0.0.7
File Size Uploaded
npls-0.0.7.tar.gz 17.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for npls 0.0.7
File Interpreter ABI Platform
npls-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 34.2 kB

Release files / npls-0.0.7.tar.gz

Download URL npls-0.0.7.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
bec96b75f66a6c5745062817221f8c16f08b61f26c88af1efb658a1e22d265af
BLAKE2b-256 checksum
How to use checksums
bea3a63ded5409d85cba761156712bd0cb3310dfc13601811dd7aca8da61a68c
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / npls-0.0.7-py3-none-any.whl

Download URL npls-0.0.7-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
66d545055583f0bb9a08b0966f5d93579fb59aff8c279300f3220e470b78a038
BLAKE2b-256 checksum
How to use checksums
71bab3114922a2e2c728630a44365075b9ebd86d042d357ef198f56ce5797b27
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page