class_docstr: An abstract class definition of any classifier that allows to train a model
  and access trained weights of that model.
  
  More specifically the classifier can, for instance, be trained on the
  activations of a particular layer. Below we can see an example a sklearn
  linear classifier wrapped by the `CustomClassifier` which extends `Classifier`
  abstract class.
  
  Example::
  
  >>> from sklearn import linear_model
  >>>
  >>> class CustomClassifier(Classifier):
  >>>
  >>> def __init__(self):
  >>>
  >>>     self.lm = linear_model.SGDClassifier(alpha=0.01, max_iter=1000,
  >>>                                          tol=1e-3)
  >>>
  >>> def train_and_eval(self, dataloader):
  >>>
  >>>     x_train, x_test, y_train, y_test = train_test_split(inputs, labels)
  >>>     self.lm.fit(x_train.detach().numpy(), y_train.detach().numpy())
  >>>
  >>>     preds = torch.tensor(self.lm.predict(x_test.detach().numpy()))
  >>>     return {'accs': (preds == y_test).float().mean()}
  >>>
  >>>
  >>> def weights(self):
  >>>
  >>>     if len(self.lm.coef_) == 1:
  >>>         # if there are two concepts, there is only one label.
  >>>         # We split it in two.
  >>>         return torch.tensor([-1 * self.lm.coef_[0], self.lm.coef_[0]])
  >>>     else:
  >>>         return torch.tensor(self.lm.coef_)
  >>>
  >>>
  >>> def classes(self):
  >>>     return self.lm.classes_
  >>>
  >>>
class_docstr_tok: ["An","abstract","class","definition","of","any","classifier","that","allows","to","train","a","model","and","access","trained","weights","of","that","model",".","More","specifically","the","classifier","can",",","for","instance",",","be","trained","on","the","activations","of","a","particular","layer",".","Below","we","can","see","an","example","a","sklearn","linear","classifier","wrapped","by","the","`","CustomClassifier","`","which","extends","`","Classifier","`","abstract","class",".","Example",":",":",">",">",">","from","sklearn","import","linear_model",">",">",">",">",">",">","class","CustomClassifier","(","Classifier",")",":",">",">",">",">",">",">","def","__init__","(","self",")",":",">",">",">",">",">",">","self.lm","=","linear_model.SGDClassifier","(","alpha=0.01",",","max_iter=1000",",",">",">",">","tol=1e-3",")",">",">",">",">",">",">","def","train_and_eval","(","self",",","dataloader",")",":",">",">",">",">",">",">","x_train",",","x_test",",","y_train",",","y_test","=","train_test_split","(","inputs",",","labels",")",">",">",">","self.lm.fit","(","x_train.detach","(",")",".numpy","(",")",",","y_train.detach","(",")",".numpy","(",")",")",">",">",">",">",">",">","preds","=","torch.tensor","(","self.lm.predict","(","x_test.detach","(",")",".numpy","(",")",")",")",">",">",">","return","{","'accs","'",":","(","preds","==","y_test",")",".float","(",")",".mean","(",")","}",">",">",">",">",">",">",">",">",">","def","weights","(","self",")",":",">",">",">",">",">",">","if","len","(","self.lm.coef_",")","==","1",":",">",">",">","#","if","there","are","two","concepts",",","there","is","only","one","label",".",">",">",">","#","We","split","it","in","two",".",">",">",">","return","torch.tensor","(","[","-1","*","self.lm.coef_","[","0","]",",","self.lm.coef_","[","0","]","]",")",">",">",">","else",":",">",">",">","return","torch.tensor","(","self.lm.coef_",")",">",">",">",">",">",">",">",">",">","def","classes","(","self",")",":",">",">",">","return","self.lm.classes_",">",">",">",">",">",">"]
docstr: This function returns the list of all classes that are used by the
  classifier to train the model in the `train_and_eval` method.
  The order of returned classes has to match the same order used in
  the weights matrix returned by the `weights` method.
  
  Returns:
      classes (list): The list of classes used by the classifier to train
      the model in the `train_and_eval` method.
docstr_tok: ["This","function","returns","the","list","of","all","classes","that","are","used","by","the","classifier","to","train","the","model","in","the","`","train_and_eval","`","method",".","The","order","of","returned","classes","has","to","match","the","same","order","used","in","the","weights","matrix","returned","by","the","`","weights","`","method",".","Returns",":","classes","(","list",")",":","The","list","of","classes","used","by","the","classifier","to","train","the","model","in","the","`","train_and_eval","`","method","."]
code: def classes(self) -> List[int]:
      r"""
      This function returns the list of all classes that are used by the
      classifier to train the model in the `train_and_eval` method.
      The order of returned classes has to match the same order used in
      the weights matrix returned by the `weights` method.
  
      Returns:
          classes (list): The list of classes used by the classifier to train
          the model in the `train_and_eval` method.
      """
      pass
  
imports: import random
  import warnings
  from abc import ABC, abstractmethod
  from typing import Any, Dict, List, Tuple, Union
  import torch
  from captum._utils.models.linear_model import model
  from torch import Tensor
  from torch.utils.data import DataLoader, TensorDataset
label_desc: Use image node_id 4 for calling the Classifier obj's underlying member method code with example usage: obj.classes() without return types