Skip to content

TypeError using the Box-Cox method #1

@danielavornic

Description

@danielavornic

Code

from imperio import BoxCoxTransformer

boxcox = BoxCoxTransformer()
boxcox.fit(X_train, y_train)
X_transformed = boxcox.transform(X_test)

Data Set

Heart Failure Prediction Dataset

Expected Behaviour

The Box-Cox feature selection method should transform the test data using the BoxCoxTransformer without any errors.

Actual Behaviour

When executing the transform method of the BoxCoxTransformer, the following error is raised:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[84], line 10
      8 boxcox = BoxCoxTransformer()
      9 boxcox.fit(X_train, y_train)
---> 10 X_transformed = boxcox.transform(X_test)

File ~/.local/lib/python3.10/site-packages/imperio/BoxCox.py:77, in BoxCoxTransformer.transform(self, X, **fit_params)
     75             return X_copy
     76         else:
---> 77             return np.array([self.__apply_change(xi) for xi in X])

File ~/.local/lib/python3.10/site-packages/imperio/BoxCox.py:77, in <listcomp>(.0)
     75             return X_copy
     76         else:
---> 77             return np.array([self.__apply_change(xi) for xi in X])

File ~/.local/lib/python3.10/site-packages/imperio/BoxCox.py:47, in BoxCoxTransformer.__apply_change(self, value)
     39 def __apply_change(self, value : float) -> float:
     40     '''
     41         The functions that transforms a scalar value.
     42     :param value: float
   (...)
     45         The transformed value by BoxCoxTransformer.
     46     '''
---> 47     return np.log(value) if self.l == 0 else (self.l ** (-1)) * (value ** self.l - 1)

TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'float'

Additional Information

To provide more context and assist with debugging, this is the Jupyter Notebook where I encountered this error and attempted to resolve it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions