-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Description
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
Metadata
Metadata
Assignees
Labels
No labels