class_docstr: CAV class contains methods for concept activation vector (CAV).
  
  CAV represents semenatically meaningful vector directions in
  network's embeddings (bottlenecks).
class_docstr_tok: ["CAV","class","contains","methods","for","concept","activation","vector","(","CAV",")",".","CAV","represents","semenatically","meaningful","vector","directions","in","network","'s","embeddings","(","bottlenecks",")","."]
docstr: Train a model to get CAVs.
  
  Modifies lm by calling the lm.fit functions. The cav coefficients are then
  in lm._coefs.
  
  Args:
    lm: An sklearn linear_model object. Can be linear regression or
      logistic regression. Must support .fit and ._coef.
    x: An array of training data of shape [num_data, data_dim]
    y: An array of integer labels of shape [num_data]
    labels2text: Dictionary of text for each label.
  
  Returns:
    Dictionary of accuracies of the CAVs.
docstr_tok: ["Train","a","model","to","get","CAVs",".","Modifies","lm","by","calling","the","lm.fit","functions",".","The","cav","coefficients","are","then","in","lm._coefs",".","Args",":","lm",":","An","sklearn","linear_model","object",".","Can","be","linear","regression","or","logistic","regression",".","Must","support",".fit","and","._coef",".","x",":","An","array","of","training","data","of","shape","[","num_data",",","data_dim","]","y",":","An","array","of","integer","labels","of","shape","[","num_data","]","labels2text",":","Dictionary","of","text","for","each","label",".","Returns",":","Dictionary","of","accuracies","of","the","CAVs","."]
code: def _train_lm(self, lm, x, y, labels2text):
      """Train a model to get CAVs.
  
      Modifies lm by calling the lm.fit functions. The cav coefficients are then
      in lm._coefs.
  
      Args:
        lm: An sklearn linear_model object. Can be linear regression or
          logistic regression. Must support .fit and ._coef.
        x: An array of training data of shape [num_data, data_dim]
        y: An array of integer labels of shape [num_data]
        labels2text: Dictionary of text for each label.
  
      Returns:
        Dictionary of accuracies of the CAVs.
  
      """
      x_train, x_test, y_train, y_test = train_test_split(
          x, y, test_size=0.33, stratify=y
      )
      # if you get setting an array element with a sequence, chances are that your
      # each of your activation had different shape - make sure they are all from
      # the same layer, and input image size was the same
      lm.fit(x_train, y_train)
      y_pred = lm.predict(x_test)
      # get acc for each class.
      num_classes = max(y) + 1
      acc = {}
      num_correct = 0
      for class_id in range(num_classes):
          # get indices of all test data that has this class.
          idx = y_test == class_id
          acc[labels2text[class_id]] = metrics.accuracy_score(
              y_pred[idx], y_test[idx]
          )
          # overall correctness is weighted by the number of examples in this class.
          num_correct += sum(idx) * acc[labels2text[class_id]]
      acc["overall"] = float(num_correct) / float(len(y_test))
      tf.compat.v1.logging.info("acc per class %s" % (str(acc)))
      return acc
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os.path
  import pickle
  import numpy
  from six.moves import range
  from sklearn import linear_model
  from sklearn import metrics
  from sklearn.model_selection import train_test_split
  from tcav import utils
  import tensorflow
label_desc: Use image node_id 12 for calling the CAV obj's underlying member method code with example usage: obj._train_lm(lm, x, y, labels2text) and returns: acc