class_docstr: Quantitative Testing with Concept Activation Vectors (TCAV).
  
  TCAV is an interpretability method which allows users to define a concept
  by selecting a set of representative examples and trains a classifier at
  different model layers to determine whether that concept has any influence
  over the predictions of the model (https://arxiv.org/pdf/1711.11279.pdf).
  If so, it can be measured as an aggregate score, and also individual points
  can be measured by how much of that concept they contain, at a given layer.
  
  The original implementation can be found at:
  https://github.com/tensorflow/tcav
  
  This component requires that the following fields in the model spec. Field
  names like `layer` are placeholders; you can call them whatever you like,
  and as with other LIT components multiple segments are supported.
    Output:
      - Embeddings (`emb_layer`) to return the input embeddings
          for a layer
      - Gradients (`grad_layer`) to return the gradients w.r.t.
          `emb_layer`
      - Gradients class (`grad_class`) to return the label that gradients
        were computed for. This is usually a CategoryLabel, but can be anything
        since it will just be fed back into the model.
      - MulticlassPreds (`probas`)
  
  **Note: TCAV calls the model multiple times. It is _strongly_ recommended that
  you use a caching model (i.e., wrap your model in a `CachingModelWrapper`) to
  optimize performance.**
docstr: Trains linear model on activations, returns weights (CAV) and accuracy.
docstr_tok: ["Trains","linear","model","on","activations",",","returns","weights","(","CAV",")","and","accuracy","."]
code: def get_trained_cav(self, x, y, test_size, random_state=None):
      """Trains linear model on activations, returns weights (CAV) and accuracy."""
      (
          x_train,
          x_test,
          y_train,
          y_test,
      ) = sklearn.model_selection.train_test_split(
          x,
          y,
          test_size=test_size,
          stratify=y,
          random_state=random_state,
      )
  
      # Train linear model on training set.
      # TODO(b/177005822): Include additional linear classifier options
      # (e.g. L-BFGS, logistic regression, etc.)
      lm = sklearn.linear_model.SGDClassifier(random_state=random_state)
      lm.fit(x_train, y_train)
      cav = lm.coef_  # the weights of the LM are the CAV.
  
      # Compute accuracy on test set.
      y_pred = lm.predict(x_test)
      correct_count = 0
      for pred_val, test_val in zip(y_pred, y_test):
          if pred_val == test_val:
              correct_count += 1
      accuracy = correct_count / len(y_test)
  
      return cav, accuracy
  
imports: from collections.abc import Sequence
  import dataclasses
  import math
  import random
  from typing import Any, Optional, cast
  from lit_nlp.api import components
  from lit_nlp.api import dataset
  from lit_nlp.api import model
  from lit_nlp.api import types
  from lit_nlp.lib import utils
  import numpy
  import scipy.stats
  import sklearn.linear_model
  import sklearn.model_selection
label_desc: Use image node_id 11 for calling the TCAV obj's underlying member method code with example usage: obj.get_trained_cav(x, y, test_size, random_state) and returns: cav,  accuracy