TabularLearner - Unable to fit one cyle using learner for Multi Label classification problem

Hi,

I am working on Tabular data where I have 10 classes in the dataset. I have created the TabularDataLoader from a dataframe where I am using TrainTestSplitter with stratify based on the class column.

Training/Validation Dataset 80:20 Split

splits_M = TrainTestSplitter(test_size=0.2, random_state=42, stratify=df_multi_class[TARGET_M], shuffle = True)(range_of(df_multi_class))

Instantiate dataloader

dls_M = TabularDataLoaders.from_df(df_multi_class, y_names=TARGET_M, cat_names=CAT_NAMES,
cont_names=CONT_NAMES, procs=procs_M, splits=splits_M)

Also, the loss is weighted loss using CrossEntropyLossFlat wherein I have created 10 weights - one for each class.

n_M_0, n_M_1, n_M_2, n_M_3, n_M_4, n_M_5, n_M_6, n_M_7, n_M_8, n_M_9 = class_count_M_df.iloc[0, 0], class_count_M_df.iloc[1, 0], class_count_M_df.iloc[2, 0], class_count_M_df.iloc[3, 0], class_count_M_df.iloc[4, 0], class_count_M_df.iloc[5, 0], class_count_M_df.iloc[6, 0], class_count_M_df.iloc[7, 0], class_count_M_df.iloc[8, 0], class_count_M_df.iloc[9, 0]

w_M_0 = (n_M_0+ n_M_1 + n_M_2 + n_M_3 + n_M_4 + n_M_5 + n_M_6 + n_M_7 + n_M_8 + n_M_9) / (2.0 * n_M_0)
w_M_1 = (n_M_0+ n_M_1 + n_M_2 + n_M_3 + n_M_4 + n_M_5 + n_M_6 + n_M_7 + n_M_8 + n_M_9) / (2.0 * n_M_1)
w_M_2 = (n_M_0+ n_M_1 + n_M_2 + n_M_3 + n_M_4 + n_M_5 + n_M_6 + n_M_7 + n_M_8 + n_M_9) / (2.0 * n_M_2)
w_M_3 = (n_M_0+ n_M_1 + n_M_2 + n_M_3 + n_M_4 + n_M_5 + n_M_6 + n_M_7 + n_M_8 + n_M_9) / (2.0 * n_M_3)
w_M_4 = (n_M_0+ n_M_1 + n_M_2 + n_M_3 + n_M_4 + n_M_5 + n_M_6 + n_M_7 + n_M_8 + n_M_9) / (2.0 * n_M_4)
w_M_5 = (n_M_0+ n_M_1 + n_M_2 + n_M_3 + n_M_4 + n_M_5 + n_M_6 + n_M_7 + n_M_8 + n_M_9) / (2.0 * n_M_5)
w_M_6 = (n_M_0+ n_M_1 + n_M_2 + n_M_3 + n_M_4 + n_M_5 + n_M_6 + n_M_7 + n_M_8 + n_M_9) / (2.0 * n_M_6)
w_M_7 = (n_M_0+ n_M_1 + n_M_2 + n_M_3 + n_M_4 + n_M_5 + n_M_6 + n_M_7 + n_M_8 + n_M_9) / (2.0 * n_M_7)
w_M_8 = (n_M_0+ n_M_1 + n_M_2 + n_M_3 + n_M_4 + n_M_5 + n_M_6 + n_M_7 + n_M_8 + n_M_9) / (2.0 * n_M_8)
w_M_9 = (n_M_0+ n_M_1 + n_M_2 + n_M_3 + n_M_4 + n_M_5 + n_M_6 + n_M_7 + n_M_8 + n_M_9) / (2.0 * n_M_9)

Loss Function

loss_func_M = CrossEntropyLossFlat(weight = class_weights_M)

The metrics created are as below:

Model Performance Metric - Instantiate RocAucMulti Score

roc_auc_M = RocAucMulti()
precision_M = PrecisionMulti()
f1_M = F1ScoreMulti()

dls_M.c returns 10 as the number of classes.
dls_M.train_ds.c returns 10 as the number of classes.

Model Learner

learn_M = tabular_learner(dls_M, loss_func=loss_func_M, metrics=roc_auc_M)

learn_M.fit_one_cycle(5) → RETURNS THE BELOW ERROR.

ValueError Traceback (most recent call last)
in
----> 1 learn_M.fit_one_cycle(5)

D:\anaconda3\envs\fastai\lib\site-packages\fastai\callback\schedule.py in fit_one_cycle(self, n_epoch, lr_max, div, div_final, pct_start, wd, moms, cbs, reset_opt)
114 scheds = {‘lr’: combined_cos(pct_start, lr_max/div, lr_max, lr_max/div_final),
115 ‘mom’: combined_cos(pct_start, *(self.moms if moms is None else moms))}
→ 116 self.fit(n_epoch, cbs=ParamScheduler(scheds)+L(cbs), reset_opt=reset_opt, wd=wd)
117
118 # Cell

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in fit(self, n_epoch, lr, wd, cbs, reset_opt)
219 self.opt.set_hypers(lr=self.lr if lr is None else lr)
220 self.n_epoch = n_epoch
→ 221 self._with_events(self._do_fit, ‘fit’, CancelFitException, self._end_cleanup)
222
223 def _end_cleanup(self): self.dl,self.xb,self.yb,self.pred,self.loss = None,(None,),(None,),None,None

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in with_events(self, f, event_type, ex, final)
161
162 def with_events(self, f, event_type, ex, final=noop):
→ 163 try: self(f’before
{event_type}’); f()
164 except ex: self(f’after_cancel
{event_type}’)
165 self(f’after_{event_type}’); final()

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in _do_fit(self)
210 for epoch in range(self.n_epoch):
211 self.epoch=epoch
→ 212 self._with_events(self._do_epoch, ‘epoch’, CancelEpochException)
213
214 def fit(self, n_epoch, lr=None, wd=None, cbs=None, reset_opt=False):

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in with_events(self, f, event_type, ex, final)
161
162 def with_events(self, f, event_type, ex, final=noop):
→ 163 try: self(f’before
{event_type}’); f()
164 except ex: self(f’after_cancel
{event_type}’)
165 self(f’after_{event_type}’); final()

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in _do_epoch(self)
205 def _do_epoch(self):
206 self._do_epoch_train()
→ 207 self._do_epoch_validate()
208
209 def _do_fit(self):

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in _do_epoch_validate(self, ds_idx, dl)
201 if dl is None: dl = self.dls[ds_idx]
202 self.dl = dl
→ 203 with torch.no_grad(): self._with_events(self.all_batches, ‘validate’, CancelValidException)
204
205 def _do_epoch(self):

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in with_events(self, f, event_type, ex, final)
163 try: self(f’before
{event_type}’); f()
164 except ex: self(f’after_cancel_{event_type}’)
→ 165 self(f’after_{event_type}’); final()
166
167 def all_batches(self):

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in call(self, event_name)
139
140 def ordered_cbs(self, event): return [cb for cb in self.cbs.sorted(‘order’) if hasattr(cb, event)]
→ 141 def call(self, event_name): L(event_name).map(self._call_one)
142
143 def _call_one(self, event_name):

D:\anaconda3\envs\fastai\lib\site-packages\fastcore\foundation.py in map(self, f, gen, *args, **kwargs)
152 def range(cls, a, b=None, step=None): return cls(range_of(a, b=b, step=step))
153
→ 154 def map(self, f, *args, gen=False, **kwargs): return self._new(map_ex(self, f, *args, gen=gen, **kwargs))
155 def argwhere(self, f, negate=False, **kwargs): return self._new(argwhere(self, f, negate, **kwargs))
156 def argfirst(self, f, negate=False): return first(i for i,o in self.enumerate() if f(o))

D:\anaconda3\envs\fastai\lib\site-packages\fastcore\basics.py in map_ex(iterable, f, gen, *args, **kwargs)
664 res = map(g, iterable)
665 if gen: return res
→ 666 return list(res)
667
668 # Cell

D:\anaconda3\envs\fastai\lib\site-packages\fastcore\basics.py in call(self, *args, **kwargs)
649 if isinstance(v,_Arg): kwargs[k] = args.pop(v.i)
650 fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
→ 651 return self.func(*fargs, **kwargs)
652
653 # Cell

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in _call_one(self, event_name)
143 def _call_one(self, event_name):
144 if not hasattr(event, event_name): raise Exception(f’missing {event_name}’)
→ 145 for cb in self.cbs.sorted(‘order’): cb(event_name)
146
147 def _bn_bias_state(self, with_bias): return norm_bias_params(self.model, with_bias).map(self.opt.state)

D:\anaconda3\envs\fastai\lib\site-packages\fastai\callback\core.py in call(self, event_name)
43 (self.run_valid and not getattr(self, ‘training’, False)))
44 res = None
—> 45 if self.run and _run: res = getattr(self, event_name, noop)()
46 if event_name==‘after_fit’: self.run=True #Reset self.run to True at each end of fit
47 return res

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in after_validate(self)
517 def before_validate(self): self._valid_mets.map(Self.reset())
518 def after_train (self): self.log += self._train_mets.map(_maybe_item)
→ 519 def after_validate(self): self.log += self._valid_mets.map(_maybe_item)
520 def after_cancel_train(self): self.cancel_train = True
521 def after_cancel_validate(self): self.cancel_valid = True

D:\anaconda3\envs\fastai\lib\site-packages\fastcore\foundation.py in map(self, f, gen, *args, **kwargs)
152 def range(cls, a, b=None, step=None): return cls(range_of(a, b=b, step=step))
153
→ 154 def map(self, f, *args, gen=False, **kwargs): return self._new(map_ex(self, f, *args, gen=gen, **kwargs))
155 def argwhere(self, f, negate=False, **kwargs): return self._new(argwhere(self, f, negate, **kwargs))
156 def argfirst(self, f, negate=False): return first(i for i,o in self.enumerate() if f(o))

D:\anaconda3\envs\fastai\lib\site-packages\fastcore\basics.py in map_ex(iterable, f, gen, *args, **kwargs)
664 res = map(g, iterable)
665 if gen: return res
→ 666 return list(res)
667
668 # Cell

D:\anaconda3\envs\fastai\lib\site-packages\fastcore\basics.py in call(self, *args, **kwargs)
649 if isinstance(v,_Arg): kwargs[k] = args.pop(v.i)
650 fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
→ 651 return self.func(*fargs, **kwargs)
652
653 # Cell

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in _maybe_item(t)
471 # Cell
472 def _maybe_item(t):
→ 473 t = t.value
474 try: return t.item()
475 except: return t

D:\anaconda3\envs\fastai\lib\site-packages\fastai\metrics.py in value(self)
65 preds,targs = torch.cat(self.preds),torch.cat(self.targs)
66 if self.to_np: preds,targs = preds.numpy(),targs.numpy()
—> 67 return self.func(targs, preds, **self.kwargs) if self.invert_args else self.func(preds, targs, **self.kwargs)
68
69 @property

D:\anaconda3\envs\fastai\lib\site-packages\sklearn\utils\validation.py in inner_f(*args, **kwargs)
61 extra_args = len(args) - len(all_args)
62 if extra_args <= 0:
—> 63 return f(*args, **kwargs)
64
65 # extra_args > 0

D:\anaconda3\envs\fastai\lib\site-packages\sklearn\metrics_ranking.py in roc_auc_score(y_true, y_score, average, sample_weight, max_fpr, multi_class, labels)
534 “instead”.format(max_fpr))
535 if multi_class == ‘raise’:
→ 536 raise ValueError(“multi_class must be in (‘ovo’, ‘ovr’)”)
537 return _multiclass_roc_auc_score(y_true, y_score, labels,
538 multi_class, average, sample_weight)

ValueError: multi_class must be in (‘ovo’, ‘ovr’)

If I change the metric to RoCAUC(), I still get the below error:

ValueError Traceback (most recent call last)
in
----> 1 learn_M.fit_one_cycle(5)

D:\anaconda3\envs\fastai\lib\site-packages\fastai\callback\schedule.py in fit_one_cycle(self, n_epoch, lr_max, div, div_final, pct_start, wd, moms, cbs, reset_opt)
114 scheds = {‘lr’: combined_cos(pct_start, lr_max/div, lr_max, lr_max/div_final),
115 ‘mom’: combined_cos(pct_start, *(self.moms if moms is None else moms))}
→ 116 self.fit(n_epoch, cbs=ParamScheduler(scheds)+L(cbs), reset_opt=reset_opt, wd=wd)
117
118 # Cell

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in fit(self, n_epoch, lr, wd, cbs, reset_opt)
219 self.opt.set_hypers(lr=self.lr if lr is None else lr)
220 self.n_epoch = n_epoch
→ 221 self._with_events(self._do_fit, ‘fit’, CancelFitException, self._end_cleanup)
222
223 def _end_cleanup(self): self.dl,self.xb,self.yb,self.pred,self.loss = None,(None,),(None,),None,None

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in with_events(self, f, event_type, ex, final)
161
162 def with_events(self, f, event_type, ex, final=noop):
→ 163 try: self(f’before
{event_type}’); f()
164 except ex: self(f’after_cancel
{event_type}’)
165 self(f’after_{event_type}’); final()

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in _do_fit(self)
210 for epoch in range(self.n_epoch):
211 self.epoch=epoch
→ 212 self._with_events(self._do_epoch, ‘epoch’, CancelEpochException)
213
214 def fit(self, n_epoch, lr=None, wd=None, cbs=None, reset_opt=False):

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in with_events(self, f, event_type, ex, final)
161
162 def with_events(self, f, event_type, ex, final=noop):
→ 163 try: self(f’before
{event_type}’); f()
164 except ex: self(f’after_cancel
{event_type}’)
165 self(f’after_{event_type}’); final()

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in _do_epoch(self)
205 def _do_epoch(self):
206 self._do_epoch_train()
→ 207 self._do_epoch_validate()
208
209 def _do_fit(self):

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in _do_epoch_validate(self, ds_idx, dl)
201 if dl is None: dl = self.dls[ds_idx]
202 self.dl = dl
→ 203 with torch.no_grad(): self._with_events(self.all_batches, ‘validate’, CancelValidException)
204
205 def _do_epoch(self):

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in with_events(self, f, event_type, ex, final)
163 try: self(f’before
{event_type}’); f()
164 except ex: self(f’after_cancel_{event_type}’)
→ 165 self(f’after_{event_type}’); final()
166
167 def all_batches(self):

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in call(self, event_name)
139
140 def ordered_cbs(self, event): return [cb for cb in self.cbs.sorted(‘order’) if hasattr(cb, event)]
→ 141 def call(self, event_name): L(event_name).map(self._call_one)
142
143 def _call_one(self, event_name):

D:\anaconda3\envs\fastai\lib\site-packages\fastcore\foundation.py in map(self, f, gen, *args, **kwargs)
152 def range(cls, a, b=None, step=None): return cls(range_of(a, b=b, step=step))
153
→ 154 def map(self, f, *args, gen=False, **kwargs): return self._new(map_ex(self, f, *args, gen=gen, **kwargs))
155 def argwhere(self, f, negate=False, **kwargs): return self._new(argwhere(self, f, negate, **kwargs))
156 def argfirst(self, f, negate=False): return first(i for i,o in self.enumerate() if f(o))

D:\anaconda3\envs\fastai\lib\site-packages\fastcore\basics.py in map_ex(iterable, f, gen, *args, **kwargs)
664 res = map(g, iterable)
665 if gen: return res
→ 666 return list(res)
667
668 # Cell

D:\anaconda3\envs\fastai\lib\site-packages\fastcore\basics.py in call(self, *args, **kwargs)
649 if isinstance(v,_Arg): kwargs[k] = args.pop(v.i)
650 fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
→ 651 return self.func(*fargs, **kwargs)
652
653 # Cell

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in _call_one(self, event_name)
143 def _call_one(self, event_name):
144 if not hasattr(event, event_name): raise Exception(f’missing {event_name}’)
→ 145 for cb in self.cbs.sorted(‘order’): cb(event_name)
146
147 def _bn_bias_state(self, with_bias): return norm_bias_params(self.model, with_bias).map(self.opt.state)

D:\anaconda3\envs\fastai\lib\site-packages\fastai\callback\core.py in call(self, event_name)
43 (self.run_valid and not getattr(self, ‘training’, False)))
44 res = None
—> 45 if self.run and _run: res = getattr(self, event_name, noop)()
46 if event_name==‘after_fit’: self.run=True #Reset self.run to True at each end of fit
47 return res

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in after_validate(self)
517 def before_validate(self): self._valid_mets.map(Self.reset())
518 def after_train (self): self.log += self._train_mets.map(_maybe_item)
→ 519 def after_validate(self): self.log += self._valid_mets.map(_maybe_item)
520 def after_cancel_train(self): self.cancel_train = True
521 def after_cancel_validate(self): self.cancel_valid = True

D:\anaconda3\envs\fastai\lib\site-packages\fastcore\foundation.py in map(self, f, gen, *args, **kwargs)
152 def range(cls, a, b=None, step=None): return cls(range_of(a, b=b, step=step))
153
→ 154 def map(self, f, *args, gen=False, **kwargs): return self._new(map_ex(self, f, *args, gen=gen, **kwargs))
155 def argwhere(self, f, negate=False, **kwargs): return self._new(argwhere(self, f, negate, **kwargs))
156 def argfirst(self, f, negate=False): return first(i for i,o in self.enumerate() if f(o))

D:\anaconda3\envs\fastai\lib\site-packages\fastcore\basics.py in map_ex(iterable, f, gen, *args, **kwargs)
664 res = map(g, iterable)
665 if gen: return res
→ 666 return list(res)
667
668 # Cell

D:\anaconda3\envs\fastai\lib\site-packages\fastcore\basics.py in call(self, *args, **kwargs)
649 if isinstance(v,_Arg): kwargs[k] = args.pop(v.i)
650 fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
→ 651 return self.func(*fargs, **kwargs)
652
653 # Cell

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in _maybe_item(t)
471 # Cell
472 def _maybe_item(t):
→ 473 t = t.value
474 try: return t.item()
475 except: return t

D:\anaconda3\envs\fastai\lib\site-packages\fastai\metrics.py in value(self)
65 preds,targs = torch.cat(self.preds),torch.cat(self.targs)
66 if self.to_np: preds,targs = preds.numpy(),targs.numpy()
—> 67 return self.func(targs, preds, **self.kwargs) if self.invert_args else self.func(preds, targs, **self.kwargs)
68
69 @property

D:\anaconda3\envs\fastai\lib\site-packages\sklearn\utils\validation.py in inner_f(*args, **kwargs)
61 extra_args = len(args) - len(all_args)
62 if extra_args <= 0:
—> 63 return f(*args, **kwargs)
64
65 # extra_args > 0

D:\anaconda3\envs\fastai\lib\site-packages\sklearn\metrics_ranking.py in roc_auc_score(y_true, y_score, average, sample_weight, max_fpr, multi_class, labels)
535 if multi_class == ‘raise’:
536 raise ValueError(“multi_class must be in (‘ovo’, ‘ovr’)”)
→ 537 return _multiclass_roc_auc_score(y_true, y_score, labels,
538 multi_class, average, sample_weight)
539 elif y_type == “binary”:

D:\anaconda3\envs\fastai\lib\site-packages\sklearn\metrics_ranking.py in _multiclass_roc_auc_score(y_true, y_score, labels, multi_class, average, sample_weight)
629 classes = _unique(y_true)
630 if len(classes) != y_score.shape[1]:
→ 631 raise ValueError(
632 "Number of classes in y_true not equal to the number of "
633 “columns in ‘y_score’”)

ValueError: Number of classes in y_true not equal to the number of columns in ‘y_score’

When I change the metric to precision or F1score, I get the below error:

Model Learner

learn_M = tabular_learner(dls_M, loss_func=loss_func_M, metrics=precision_M)

ERROR

ValueError Traceback (most recent call last)
in
----> 1 learn_M.fit_one_cycle(5)

D:\anaconda3\envs\fastai\lib\site-packages\fastai\callback\schedule.py in fit_one_cycle(self, n_epoch, lr_max, div, div_final, pct_start, wd, moms, cbs, reset_opt)
114 scheds = {‘lr’: combined_cos(pct_start, lr_max/div, lr_max, lr_max/div_final),
115 ‘mom’: combined_cos(pct_start, *(self.moms if moms is None else moms))}
→ 116 self.fit(n_epoch, cbs=ParamScheduler(scheds)+L(cbs), reset_opt=reset_opt, wd=wd)
117
118 # Cell

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in fit(self, n_epoch, lr, wd, cbs, reset_opt)
219 self.opt.set_hypers(lr=self.lr if lr is None else lr)
220 self.n_epoch = n_epoch
→ 221 self._with_events(self._do_fit, ‘fit’, CancelFitException, self._end_cleanup)
222
223 def _end_cleanup(self): self.dl,self.xb,self.yb,self.pred,self.loss = None,(None,),(None,),None,None

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in with_events(self, f, event_type, ex, final)
161
162 def with_events(self, f, event_type, ex, final=noop):
→ 163 try: self(f’before
{event_type}’); f()
164 except ex: self(f’after_cancel
{event_type}’)
165 self(f’after_{event_type}’); final()

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in _do_fit(self)
210 for epoch in range(self.n_epoch):
211 self.epoch=epoch
→ 212 self._with_events(self._do_epoch, ‘epoch’, CancelEpochException)
213
214 def fit(self, n_epoch, lr=None, wd=None, cbs=None, reset_opt=False):

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in with_events(self, f, event_type, ex, final)
161
162 def with_events(self, f, event_type, ex, final=noop):
→ 163 try: self(f’before
{event_type}’); f()
164 except ex: self(f’after_cancel
{event_type}’)
165 self(f’after_{event_type}’); final()

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in _do_epoch(self)
205 def _do_epoch(self):
206 self._do_epoch_train()
→ 207 self._do_epoch_validate()
208
209 def _do_fit(self):

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in _do_epoch_validate(self, ds_idx, dl)
201 if dl is None: dl = self.dls[ds_idx]
202 self.dl = dl
→ 203 with torch.no_grad(): self._with_events(self.all_batches, ‘validate’, CancelValidException)
204
205 def _do_epoch(self):

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in with_events(self, f, event_type, ex, final)
163 try: self(f’before
{event_type}’); f()
164 except ex: self(f’after_cancel_{event_type}’)
→ 165 self(f’after_{event_type}’); final()
166
167 def all_batches(self):

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in call(self, event_name)
139
140 def ordered_cbs(self, event): return [cb for cb in self.cbs.sorted(‘order’) if hasattr(cb, event)]
→ 141 def call(self, event_name): L(event_name).map(self._call_one)
142
143 def _call_one(self, event_name):

D:\anaconda3\envs\fastai\lib\site-packages\fastcore\foundation.py in map(self, f, gen, *args, **kwargs)
152 def range(cls, a, b=None, step=None): return cls(range_of(a, b=b, step=step))
153
→ 154 def map(self, f, *args, gen=False, **kwargs): return self._new(map_ex(self, f, *args, gen=gen, **kwargs))
155 def argwhere(self, f, negate=False, **kwargs): return self._new(argwhere(self, f, negate, **kwargs))
156 def argfirst(self, f, negate=False): return first(i for i,o in self.enumerate() if f(o))

D:\anaconda3\envs\fastai\lib\site-packages\fastcore\basics.py in map_ex(iterable, f, gen, *args, **kwargs)
664 res = map(g, iterable)
665 if gen: return res
→ 666 return list(res)
667
668 # Cell

D:\anaconda3\envs\fastai\lib\site-packages\fastcore\basics.py in call(self, *args, **kwargs)
649 if isinstance(v,_Arg): kwargs[k] = args.pop(v.i)
650 fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
→ 651 return self.func(*fargs, **kwargs)
652
653 # Cell

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in _call_one(self, event_name)
143 def _call_one(self, event_name):
144 if not hasattr(event, event_name): raise Exception(f’missing {event_name}’)
→ 145 for cb in self.cbs.sorted(‘order’): cb(event_name)
146
147 def _bn_bias_state(self, with_bias): return norm_bias_params(self.model, with_bias).map(self.opt.state)

D:\anaconda3\envs\fastai\lib\site-packages\fastai\callback\core.py in call(self, event_name)
43 (self.run_valid and not getattr(self, ‘training’, False)))
44 res = None
—> 45 if self.run and _run: res = getattr(self, event_name, noop)()
46 if event_name==‘after_fit’: self.run=True #Reset self.run to True at each end of fit
47 return res

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in after_validate(self)
517 def before_validate(self): self._valid_mets.map(Self.reset())
518 def after_train (self): self.log += self._train_mets.map(_maybe_item)
→ 519 def after_validate(self): self.log += self._valid_mets.map(_maybe_item)
520 def after_cancel_train(self): self.cancel_train = True
521 def after_cancel_validate(self): self.cancel_valid = True

D:\anaconda3\envs\fastai\lib\site-packages\fastcore\foundation.py in map(self, f, gen, *args, **kwargs)
152 def range(cls, a, b=None, step=None): return cls(range_of(a, b=b, step=step))
153
→ 154 def map(self, f, *args, gen=False, **kwargs): return self._new(map_ex(self, f, *args, gen=gen, **kwargs))
155 def argwhere(self, f, negate=False, **kwargs): return self._new(argwhere(self, f, negate, **kwargs))
156 def argfirst(self, f, negate=False): return first(i for i,o in self.enumerate() if f(o))

D:\anaconda3\envs\fastai\lib\site-packages\fastcore\basics.py in map_ex(iterable, f, gen, *args, **kwargs)
664 res = map(g, iterable)
665 if gen: return res
→ 666 return list(res)
667
668 # Cell

D:\anaconda3\envs\fastai\lib\site-packages\fastcore\basics.py in call(self, *args, **kwargs)
649 if isinstance(v,_Arg): kwargs[k] = args.pop(v.i)
650 fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
→ 651 return self.func(*fargs, **kwargs)
652
653 # Cell

D:\anaconda3\envs\fastai\lib\site-packages\fastai\learner.py in _maybe_item(t)
471 # Cell
472 def _maybe_item(t):
→ 473 t = t.value
474 try: return t.item()
475 except: return t

D:\anaconda3\envs\fastai\lib\site-packages\fastai\metrics.py in value(self)
65 preds,targs = torch.cat(self.preds),torch.cat(self.targs)
66 if self.to_np: preds,targs = preds.numpy(),targs.numpy()
—> 67 return self.func(targs, preds, **self.kwargs) if self.invert_args else self.func(preds, targs, **self.kwargs)
68
69 @property

D:\anaconda3\envs\fastai\lib\site-packages\sklearn\utils\validation.py in inner_f(*args, **kwargs)
61 extra_args = len(args) - len(all_args)
62 if extra_args <= 0:
—> 63 return f(*args, **kwargs)
64
65 # extra_args > 0

D:\anaconda3\envs\fastai\lib\site-packages\sklearn\metrics_classification.py in precision_score(y_true, y_pred, labels, pos_label, average, sample_weight, zero_division)
1654
1655 “”"
→ 1656 p, _, _, _ = precision_recall_fscore_support(y_true, y_pred,
1657 labels=labels,
1658 pos_label=pos_label,

D:\anaconda3\envs\fastai\lib\site-packages\sklearn\utils\validation.py in inner_f(*args, **kwargs)
61 extra_args = len(args) - len(all_args)
62 if extra_args <= 0:
—> 63 return f(*args, **kwargs)
64
65 # extra_args > 0

D:\anaconda3\envs\fastai\lib\site-packages\sklearn\metrics_classification.py in precision_recall_fscore_support(y_true, y_pred, beta, labels, pos_label, average, warn_for, sample_weight, zero_division)
1462 if beta < 0:
1463 raise ValueError(“beta should be >=0 in the F-beta score”)
→ 1464 labels = _check_set_wise_labels(y_true, y_pred, average, labels,
1465 pos_label)
1466

D:\anaconda3\envs\fastai\lib\site-packages\sklearn\metrics_classification.py in _check_set_wise_labels(y_true, y_pred, average, labels, pos_label)
1275 str(average_options))
1276
→ 1277 y_type, y_true, y_pred = _check_targets(y_true, y_pred)
1278 # Convert to Python primitive type to avoid NumPy type / Python str
1279 # comparison. See https://github.com/numpy/numpy/issues/6784

D:\anaconda3\envs\fastai\lib\site-packages\sklearn\metrics_classification.py in _check_targets(y_true, y_pred)
90
91 if len(y_type) > 1:
—> 92 raise ValueError("Classification metrics can’t handle a mix of {0} "
93 “and {1} targets”.format(type_true, type_pred))
94

ValueError: Classification metrics can’t handle a mix of multiclass and multilabel-indicator targets

How can I resolve it? Any suggestions?