Skip to content

Facing issue while using Tpot #1378

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

Open
AbhayGoyal opened this issue Apr 28, 2025 · 1 comment
Open

Facing issue while using Tpot #1378

AbhayGoyal opened this issue Apr 28, 2025 · 1 comment

Comments

@AbhayGoyal
Copy link

Hi.
When i install topt[sklearnx] does it install its own sklearn file? If so, how can I change it because I keep on getting the following error

ImportError: cannot import name '_add_to_diagonal' from 'sklearn.utils._array_api' (/usr/local/lib/python3.10/dist-packages/sklearn/utils/_array_api.py)

Here is the code


!pip install tpot[sklearnex]


import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score

import tpot
from tpot import TPOTClassifier

df = df_copy

# 1. Preprocess anxiety column
df['anxiety_binary'] = df['anxiety'].apply(lambda x: 0 if x == 0 else 1)

# 2. Define features and target
X = df.drop(columns=['anxiety', 'anxiety_binary'])  # Drop original and binary if you want
y = df['anxiety_binary']

# 3. Split into train and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)

# 4. Train model

# Option 1: TPOT
tpot = TPOTClassifier(generations=5, population_size=20, verbosity=2, random_state=42, scoring='roc_auc')
tpot.fit(X_train, y_train)
y_pred_proba = tpot.predict_proba(X_test)[:, 1]  # probability of class 1

roc_score = roc_auc_score(y_test, y_pred_proba)
print(f"ROC-AUC Score: {roc_score:.4f}")

Thanks

@perib
Copy link
Contributor

perib commented Apr 28, 2025

installing tpot should automatically install sklearn into the environment if its not already there. Note that the sklearn package is actually "scikit-learn" not "sklearnx" . sklearnx is a separate project that extends scikit learn and not required for TPOT. I see in your code that you are not using sklearnx, so you do not have to install it.

pip install tpot should be sufficient. you can also call pip install scikit-learn if for some reason its not in your environment.

The error is usually indicative of mismatched versions. Can you submit the results of pip list so I can see what versions you are using? The version of TPOT on pip requires scikit learn older than 1.6 (not including 1.6)

you can also try my PR here: #1371 This includes updates to make tpot compatible with the latest version of sklearn. Its possible that the issue is that the current version of tpot is using older version of scikit learn whereas the sklearnx may require the latest package? perhaps a newer version of scikit-learn is already installed before you installed tpot?

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

No branches or pull requests

2 participants