Issue
For example, ss
is an sklearn.preprocessing.StandardScaler
object. If ss
is fitted already, I want to use it to transform my data. If ss
is not fitted yet, I want to use my data to fit it and transform my data. Is there a way to know whether ss
is already fitted or not?
Solution
Sklearn implements the check_is_fitted function to check if any generic estimator is fitted, which works with StandardScaler:
from sklearn.preprocessing import StandardScaler
from sklearn.utils.validation import check_is_fitted
ss = StandardScaler()
check_is_fitted(ss) # Raises error
ss.fit([[1,2,3]])
check_is_fitted(ss) # No error
Answered By - EEtch
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.