Skip to content

power_transform() lacks lambda retrieval in the new version #30673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
samer-oxy opened this issue Jan 19, 2025 · 2 comments
Closed

power_transform() lacks lambda retrieval in the new version #30673

samer-oxy opened this issue Jan 19, 2025 · 2 comments
Labels
Needs Triage Issue requires triage

Comments

@samer-oxy
Copy link

Describe the issue

In the latest version of scikit-learn, the power_transform() function does not provide a way to access the lambda values ((\lambda)) used during the transformation. This was possible in the older version using the PowerTransformer class with the lambdas_ attribute.

Steps

from sklearn.preprocessing import power_transform
import pandas as pd
import numpy as np

np.random.seed(42)  
data = np.random.exponential(scale=2, size=1000)

transformed_data = power_transform(data, method='box-cox')
# No way to access lambda values

Actual behavior

The power_transform() function does not expose lambda values, making it less informative for users who need them.

transformed_data.lambdas_
AttributeError: numpy.ndarray object has no attribute lambdas_

Expected behavior

There should be a way to retrieve the lambda values (𝜆) when using the power_transform() function.

Environment

scikit-learn version: 1.6.1

@github-actions github-actions bot added the Needs Triage Issue requires triage label Jan 19, 2025
@StefanieSenger
Copy link
Contributor

Hi @samer-oxy,

thanks for reporting.

I think this bug was accidentally introduced with #26566, but I'm not 100 % sure yet.
I would like to take a look and give it a try in fixing that, if it's okay, @jeremiedbb?

@StefanieSenger
Copy link
Contributor

StefanieSenger commented Jan 19, 2025

I now understand it better and I don't think it is a bug, @samer-oxy.

power_transform() in contrast to the PowerTransformer class returns only X as an array and not attributes that were created while fitting.

I did some investigation to see if I could re-create the fact that you said it worked in previous versions, but not even with scikit-learn==1.1.0 and numpy==1.22.0 we would get an attribute for the lambdas on the numpy array (which makes sense, because scikit-learn doesn't manipulate other librarie's objects).

Please use PowerTransformer directly to obtain the lambdas_.

(And sorry for the confusion @jeremiedbb, just ignore that.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Triage Issue requires triage
Projects
None yet
Development

No branches or pull requests

2 participants