Reputation: 43
I'm trying to make a multiclass classification here and the score from the cross validaiton are all nan
Below the code which works perfectly for binary classifcation
when i only keep accuracy and balanced_accuracy it shows the actual score when i add f1 or precison or recall all scores turns into nan
the problem that my code worked perfectly for binary classifcation and i'm using the same dataset just changed the target data
scoring = {'accuracy': 'accuracy',
"balanced_accuracy": "balanced_accuracy",
"precision": "precision",
"recall": "recall",
"f1" :"f1",
"roc_auc":"roc_auc" }
# load the dataset
def load_dataset(df):
# load the dataset as a numpy array
data = df
# retrieve numpy array
data = data.values
# split into input and output elements
X, y = data[:, :-1], data[:, -1]
y = LabelEncoder().fit_transform(y)
return X, y
# evaluate a model
def evaluate_model(X, y, model):
# define evaluation procedure
cv = RepeatedStratifiedKFold(n_splits=10, n_repeats=3, random_state=1)
# evaluate model
scores = cross_validate(model, X, y, scoring=scoring, cv=cv, n_jobs=-1)
return scores
model=DecisionTreeClassifier()
# define the location of the dataset
# load the dataset
X, y = load_dataset(df2)
# evaluate the model and store results
results_without_nlp = evaluate_model(X, y, model)
i have tried to use those
from sklearn.metrics import accuracy_score, f1_score, precision_score, recall_score
but that does not seem to help
Upvotes: 0
Views: 456
Reputation: 335
For precision_score, recall_score and f1_score, I think you can try using parameter average = micro (or macro and weighted)
for multiple targets. Because its default value is binary
.
Upvotes: 1