class_docstr: Encapsulate features, labels, and metadata for a given dataset.
  
  Parameters
  ----------
  name : str
      The name of this feature set.
  
  ids : Union[List[str], numpy.ndarray]
      Example IDs for this set.
  
  labels : Optional[Union[List[str], numpy.ndarray], default=None
      Labels for this set.
  
  features : Optional[Union[:class:`skll.types.FeatureDictList`, :class:`numpy.ndarray`]], default=None
      The features for each instance represented as either a
      list of dictionaries or a numpy array (if ``vectorizer`` is
      also specified).
  
  vectorizer : Optional[Union[:class:`sklearn.feature_extraction.DictVectorizer`, :class:`sklearn.feature_extraction.FeatureHasher`], default=None
      Vectorizer which will be used to generate the feature matrix.
  
  Warnings
  --------
  FeatureSets can only be equal if the order of the instances is
  identical because these are stored as lists/arrays. Since scikit-learn's
  ``DictVectorizer`` automatically sorts the underlying feature matrix
  if it is sparse, we do not do any sorting before checking for equality.
  This is not a problem because we _always_ use sparse matrices with
  ``DictVectorizer`` when creating FeatureSets.
  
  Notes
  -----
  If ids, labels, and/or features are not None, the number of rows in
  each array must be equal.
docstr: Retain only the specified features and/or examples from the output.
  
  Parameters
  ----------
  ids : Optional[List[:class:`skll.types.IdType`]], default=None
      Examples to keep in the ``FeatureSet``. If ``None``, no ID
      filtering takes place.
  
  labels : Optional[List[:class:`skll.types.LabelType`]], default=None
      Labels that we want to retain examples for. If ``None``,
      no label filtering takes place.
  
  features : Optional[Collection[str]], default=None
      Features to keep in the ``FeatureSet``. To help with
      filtering string-valued features that were converted
      to sequences of boolean features when read in, any
      features in the ``FeatureSet`` that contain a `=` will be
      split on the first occurrence and the prefix will be
      checked to see if it is in ``features``.
      If `None`, no feature filtering takes place.
      Cannot be used if ``FeatureSet`` uses a FeatureHasher for
      vectorization.
  
  inverse : bool, default=False
      Instead of keeping features and/or examples in lists,
      remove them.
  
  Returns
  -------
  :class:`skll.types.FeatGenerator`
  
      A generator that yields 3-tuples containing:
  
        - :class:`skll.types.IdType`  - The ID of the example.
  
        - :class:`skll.types.LabelType` - The label of the example.
  
        - :class:`skll.types.FeatureDict` - The feature dictionary, with
          feature name as the key and example value as the value.
  
  Raises
  ------
  ValueError
      If the vectorizer is not a ``DictVectorizer``.
  
  ValueError
      If any of the "labels", "features", or "vectorizer" attribute
      is ``None``.
docstr_tok: ["Retain","only","the","specified","features","and\/or","examples","from","the","output",".","Parameters","--","--","--","--","--","ids",":","Optional","[","List","[",":","class",":","`","skll.types.IdType","`","]","]",",","default=None","Examples","to","keep","in","the","``","FeatureSet","``",".","If","``","None","``",",","no","ID","filtering","takes","place",".","labels",":","Optional","[","List","[",":","class",":","`","skll.types.LabelType","`","]","]",",","default=None","Labels","that","we","want","to","retain","examples","for",".","If","``","None","``",",","no","label","filtering","takes","place",".","features",":","Optional","[","Collection","[","str","]","]",",","default=None","Features","to","keep","in","the","``","FeatureSet","``",".","To","help","with","filtering","string-valued","features","that","were","converted","to","sequences","of","boolean","features","when","read","in",",","any","features","in","the","``","FeatureSet","``","that","contain","a","`","=","`","will","be","split","on","the","first","occurrence","and","the","prefix","will","be","checked","to","see","if","it","is","in","``","features","``",".","If","`","None","`",",","no","feature","filtering","takes","place",".","Can","not","be","used","if","``","FeatureSet","``","uses","a","FeatureHasher","for","vectorization",".","inverse",":","bool",",","default=False","Instead","of","keeping","features","and\/or","examples","in","lists",",","remove","them",".","Returns","--","--","--","-",":","class",":","`","skll.types.FeatGenerator","`","A","generator","that","yields","3-tuples","containing",":","-",":","class",":","`","skll.types.IdType","`","-","The","ID","of","the","example",".","-",":","class",":","`","skll.types.LabelType","`","-","The","label","of","the","example",".","-",":","class",":","`","skll.types.FeatureDict","`","-","The","feature","dictionary",",","with","feature","name","as","the","key","and","example","value","as","the","value",".","Raises","--","--","--","ValueError","If","the","vectorizer","is","not","a","``","DictVectorizer","``",".","ValueError","If","any","of","the","``","labels","''",",","``","features","''",",","or","``","vectorizer","''","attribute","is","``","None","``","."]
code: def filtered_iter(
      self,
      ids: Optional[List[IdType]] = None,
      labels: Optional[List[LabelType]] = None,
      features: Optional[Collection[str]] = None,
      inverse: bool = False,
  ) -> FeatGenerator:
      """
      Retain only the specified features and/or examples from the output.
  
      Parameters
      ----------
      ids : Optional[List[:class:`skll.types.IdType`]], default=None
          Examples to keep in the ``FeatureSet``. If ``None``, no ID
          filtering takes place.
  
      labels : Optional[List[:class:`skll.types.LabelType`]], default=None
          Labels that we want to retain examples for. If ``None``,
          no label filtering takes place.
  
      features : Optional[Collection[str]], default=None
          Features to keep in the ``FeatureSet``. To help with
          filtering string-valued features that were converted
          to sequences of boolean features when read in, any
          features in the ``FeatureSet`` that contain a `=` will be
          split on the first occurrence and the prefix will be
          checked to see if it is in ``features``.
          If `None`, no feature filtering takes place.
          Cannot be used if ``FeatureSet`` uses a FeatureHasher for
          vectorization.
  
      inverse : bool, default=False
          Instead of keeping features and/or examples in lists,
          remove them.
  
      Returns
      -------
      :class:`skll.types.FeatGenerator`
  
          A generator that yields 3-tuples containing:
  
            - :class:`skll.types.IdType`  - The ID of the example.
  
            - :class:`skll.types.LabelType` - The label of the example.
  
            - :class:`skll.types.FeatureDict` - The feature dictionary, with
              feature name as the key and example value as the value.
  
      Raises
      ------
      ValueError
          If the vectorizer is not a ``DictVectorizer``.
  
      ValueError
          If any of the "labels", "features", or "vectorizer" attribute
          is ``None``.
      """
      if self.features is not None and not isinstance(
          self.vectorizer, DictVectorizer
      ):
          raise ValueError(
              "FeatureSets can only be iterated through if they"
              " use a DictVectorizer for their feature "
              "vectorizer."
          )
  
      if (
          self.labels is None
          or self.features is None
          or self.vectorizer is None
      ):
          raise ValueError(
              "Cannot filter featureset with no labels, features, or vectorizer."
          )
      else:
          for id_, label_, feats in zip(
              self.ids, self.labels, self.features
          ):
              # Skip instances with IDs not in filter
              if ids is not None and (id_ in ids) == inverse:
                  continue
              # Skip instances with labels not in filter
              if labels is not None and (label_ in labels) == inverse:
                  continue
  
              # reshape to a 2D matrix if we are not using a sparse matrix
              # to store the features
              feats = (
                  feats.reshape(1, -1)
                  if not sp.issparse(feats)
                  else feats
              )
              feat_dict = self.vectorizer.inverse_transform(feats)[0]
              if features is not None:
                  feat_dict = {
                      name: value
                      for name, value in feat_dict.items()
                      if (
                          inverse
                          != (
                              name in features
                              or name.split("=", 1)[0] in features
                          )
                      )
                  }
              elif not inverse:
                  feat_dict = {}
              yield id_, label_, feat_dict
  
imports: from copy import deepcopy
  from typing import Collection, List, Optional, Tuple, Union
  import numpy
  import scipy.sparse
  from pandas import DataFrame
  from sklearn.feature_extraction import DictVectorizer, FeatureHasher
  from skll.data.dict_vectorizer import DictVectorizer
  from skll.types import FeatGenerator, FeatureDictList, IdType, LabelType, SparseFeatureMatrix
label_desc: Use image node_id 8 for calling the FeatureSet obj's underlying member method code with example usage: obj.filtered_iter(ids, labels, features, inverse) without return types