1
+ from __future__ import annotations
2
+
3
+ import numpy as np
1
4
from sklearn .base import BaseEstimator , TransformerMixin
2
5
from sklearn .utils .validation import check_is_fitted
3
6
4
7
from ._fdatabasis import FDataBasis
5
8
6
9
7
- class CoefficientsTransformer (BaseEstimator , TransformerMixin ):
8
- """
10
+ class CoefficientsTransformer (
11
+ BaseEstimator , # type:ignore
12
+ TransformerMixin , # type:ignore
13
+ ):
14
+ r"""
9
15
Transformer returning the coefficients of FDataBasis objects as a matrix.
10
16
11
17
Attributes:
12
- shape_ (tuple): original shape of coefficients per sample .
18
+ basis\_ (tuple): Basis used .
13
19
14
20
Examples:
15
21
>>> from skfda.representation.basis import (FDataBasis, Monomial,
@@ -26,19 +32,24 @@ class CoefficientsTransformer(BaseEstimator, TransformerMixin):
26
32
27
33
"""
28
34
29
- def fit (self , X : FDataBasis , y = None ):
35
+ def fit ( # noqa: D102
36
+ self ,
37
+ X : FDataBasis ,
38
+ y : None = None ,
39
+ ) -> CoefficientsTransformer :
30
40
31
- self .shape_ = X .coefficients . shape [ 1 :]
41
+ self .basis_ = X .basis
32
42
33
43
return self
34
44
35
- def transform (self , X , y = None ):
45
+ def transform ( # noqa: D102
46
+ self ,
47
+ X : FDataBasis ,
48
+ y : None = None ,
49
+ ) -> np .ndarray :
36
50
37
51
check_is_fitted (self )
38
52
39
- assert X .coefficients .shape [1 :] == self .shape_
40
-
41
- coefficients = X .coefficients .copy ()
42
- coefficients = coefficients .reshape ((X .n_samples , - 1 ))
53
+ assert X .basis == self .basis_
43
54
44
- return coefficients
55
+ return X . coefficients . copy ()
0 commit comments