scikit-learn Integration¶
Note
Requires scikit-learn: pip install pyspectrakit[sklearn]
spectrakit.sklearn.SpectralTransformer ¶
Bases: BaseEstimator, TransformerMixin
scikit-learn transformer wrapping any SpectraKit function.
Wraps a SpectraKit processing function (e.g., baseline_als,
normalize_snv, smooth_savgol) as a scikit-learn compatible
transformer that can be used in sklearn.pipeline.Pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., ndarray]
|
A SpectraKit processing function with signature
|
required |
**kwargs
|
Any
|
Keyword arguments passed to |
{}
|
Examples:
>>> from sklearn.pipeline import Pipeline as SkPipeline
>>> from spectrakit import baseline_als, normalize_snv
>>> from spectrakit.sklearn import SpectralTransformer
>>>
>>> pipe = SkPipeline([
... ("baseline", SpectralTransformer(baseline_als, lam=1e6)),
... ("normalize", SpectralTransformer(normalize_snv)),
... ])
>>> X_processed = pipe.fit_transform(X_raw)
Source code in src/spectrakit/sklearn/transformers.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
fit ¶
No-op fit (stateless transformer).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Training data (ignored). |
required |
y
|
Any
|
Training labels (ignored). |
None
|
Returns:
| Type | Description |
|---|---|
SpectralTransformer
|
Self. |
Source code in src/spectrakit/sklearn/transformers.py
get_params ¶
Get transformer parameters (sklearn interface).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deep
|
bool
|
If True, return nested params. |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict of parameters. |
Source code in src/spectrakit/sklearn/transformers.py
set_params ¶
Set transformer parameters (sklearn interface).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**params
|
Any
|
Parameters to set. |
{}
|
Returns:
| Type | Description |
|---|---|
SpectralTransformer
|
Self. |
Source code in src/spectrakit/sklearn/transformers.py
transform ¶
Apply the wrapped SpectraKit function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Input spectral data, shape |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Processed spectral data, same shape. |