You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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?
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
Thanks
The text was updated successfully, but these errors were encountered: