It is a Python library for the N-PLS1 regression with L1 and L2-regularization.
Project description
npls
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
File details
Details for the file npls-0.0.6.tar.gz.
File metadata
- Download URL: npls-0.0.6.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e68f284136dce3ebc1e2b273e2227b961b94602d4a4ccfc2b9bee569dc906f3
|
|
| MD5 |
a0f79336c8b8b05879f8bb0e3a8cdaa7
|
|
| BLAKE2b-256 |
af6a9646c1802a44a242e52499803196a0c0a5c0f6fe7b720db7509dd5cbed10
|