Why do I get AttributeError: 'NoneType' object has no attribute 'something'?

前端 未结 10 2339
长情又很酷
长情又很酷 2020-11-21 13:36

I keep getting an error that says

AttributeError: \'NoneType\' object has no attribute \'something\'
10条回答
  •  南旧
    南旧 (楼主)
    2020-11-21 13:52

    When building a estimator (sklearn), if you forget to return self in the fit function, you get the same error.

    class ImputeLags(BaseEstimator, TransformerMixin):
        def __init__(self, columns):
            self.columns = columns
    
        def fit(self, x, y=None):
            """ do something """
    
        def transfrom(self, x):
            return x
    

    AttributeError: 'NoneType' object has no attribute 'transform'?

    Adding return self to the fit function fixes the error.

提交回复
热议问题