parameters: (subset="train", remove=(), data_home=None)
return_statement: return Bunch(data=data, target=target, target_names=target_names)
docstring: Load the 20 newsgroups dataset and transform it into tf-idf vectors.
  
      This is a convenience function; the tf-idf transformation is done using the
      default settings for `sklearn.feature_extraction.text.Vectorizer`. For more
      advanced usage (stopword filtering, n-gram extraction, etc.), combine
      fetch_20newsgroups with a custom `Vectorizer` or `CountVectorizer`.
  
      Read more in the :ref:`User Guide <20newsgroups>`.
  
      Parameters
      ----------
  
      subset : 'train' or 'test', 'all', optional
          Select the dataset to load: 'train' for the training set, 'test'
          for the test set, 'all' for both, with shuffled ordering.
  
      data_home : optional, default: None
          Specify an download and cache folder for the datasets. If None,
          all scikit-learn data is stored in '~/scikit_learn_data' subfolders.
  
      remove : tuple
          May contain any subset of ('headers', 'footers', 'quotes'). Each of
          these are kinds of text that will be detected and removed from the
          newsgroup posts, preventing classifiers from overfitting on
          metadata.
  
          'headers' removes newsgroup headers, 'footers' removes blocks at the
          ends of posts that look like signatures, and 'quotes' removes lines
          that appear to be quoting another post.
  
      Returns
      -------
  
      bunch : Bunch object
          bunch.data: sparse matrix, shape [n_samples, n_features]
          bunch.target: array, shape [n_samples]
          bunch.target_names: list, length [n_classes]
docstring_summary: Load the 20 newsgroups dataset and transform it into tf-idf vectors.
docstring_tokens: Load the 20 newsgroups dataset and transform it into tf - idf vectors .
function: def fetch_20newsgroups_vectorized(subset="train", remove=(), data_home=None):
      """Load the 20 newsgroups dataset and transform it into tf-idf vectors.
  
      This is a convenience function; the tf-idf transformation is done using the
      default settings for `sklearn.feature_extraction.text.Vectorizer`. For more
      advanced usage (stopword filtering, n-gram extraction, etc.), combine
      fetch_20newsgroups with a custom `Vectorizer` or `CountVectorizer`.
  
      Read more in the :ref:`User Guide <20newsgroups>`.
  
      Parameters
      ----------
  
      subset : 'train' or 'test', 'all', optional
          Select the dataset to load: 'train' for the training set, 'test'
          for the test set, 'all' for both, with shuffled ordering.
  
      data_home : optional, default: None
          Specify an download and cache folder for the datasets. If None,
          all scikit-learn data is stored in '~/scikit_learn_data' subfolders.
  
      remove : tuple
          May contain any subset of ('headers', 'footers', 'quotes'). Each of
          these are kinds of text that will be detected and removed from the
          newsgroup posts, preventing classifiers from overfitting on
          metadata.
  
          'headers' removes newsgroup headers, 'footers' removes blocks at the
          ends of posts that look like signatures, and 'quotes' removes lines
          that appear to be quoting another post.
  
      Returns
      -------
  
      bunch : Bunch object
          bunch.data: sparse matrix, shape [n_samples, n_features]
          bunch.target: array, shape [n_samples]
          bunch.target_names: list, length [n_classes]
      """
      data_home = get_data_home(data_home=data_home)
      filebase = '20newsgroup_vectorized'
      if remove:
          filebase += 'remove-' + ('-'.join(remove))
      target_file = _pkl_filepath(data_home, filebase + ".pkl")
  
      # we shuffle but use a fixed seed for the memoization
      data_train = fetch_20newsgroups(data_home=data_home,
                                      subset='train',
                                      categories=None,
                                      shuffle=True,
                                      random_state=12,
                                      remove=remove)
  
      data_test = fetch_20newsgroups(data_home=data_home,
                                     subset='test',
                                     categories=None,
                                     shuffle=True,
                                     random_state=12,
                                     remove=remove)
  
      if os.path.exists(target_file):
          X_train, X_test = joblib.load(target_file)
      else:
          vectorizer = CountVectorizer(dtype=np.int16)
          X_train = vectorizer.fit_transform(data_train.data).tocsr()
          X_test = vectorizer.transform(data_test.data).tocsr()
          joblib.dump((X_train, X_test), target_file, compress=9)
  
      # the data is stored as int16 for compactness
      # but normalize needs floats
      X_train = X_train.astype(np.float64)
      X_test = X_test.astype(np.float64)
      normalize(X_train, copy=False)
      normalize(X_test, copy=False)
  
      target_names = data_train.target_names
  
      if subset == "train":
          data = X_train
          target = data_train.target
      elif subset == "test":
          data = X_test
          target = data_test.target
      elif subset == "all":
          data = sp.vstack((X_train, X_test)).tocsr()
          target = np.concatenate((data_train.target, data_test.target))
      else:
          raise ValueError("%r is not a valid subset: should be one of "
                           "['train', 'test', 'all']" % subset)
  
      return Bunch(data=data, target=target, target_names=target_names)
function_tokens: def fetch_20newsgroups_vectorized ( subset = "train" , remove = ( ) , data_home = None ) : data_home = get_data_home ( data_home = data_home ) filebase = '20newsgroup_vectorized' if remove : filebase += 'remove-' + ( '-' . join ( remove ) ) target_file = _pkl_filepath ( data_home , filebase + ".pkl" ) # we shuffle but use a fixed seed for the memoization data_train = fetch_20newsgroups ( data_home = data_home , subset = 'train' , categories = None , shuffle = True , random_state = 12 , remove = remove ) data_test = fetch_20newsgroups ( data_home = data_home , subset = 'test' , categories = None , shuffle = True , random_state = 12 , remove = remove ) if os . path . exists ( target_file ) : X_train , X_test = joblib . load ( target_file ) else : vectorizer = CountVectorizer ( dtype = np . int16 ) X_train = vectorizer . fit_transform ( data_train . data ) . tocsr ( ) X_test = vectorizer . transform ( data_test . data ) . tocsr ( ) joblib . dump ( ( X_train , X_test ) , target_file , compress = 9 ) # the data is stored as int16 for compactness # but normalize needs floats X_train = X_train . astype ( np . float64 ) X_test = X_test . astype ( np . float64 ) normalize ( X_train , copy = False ) normalize ( X_test , copy = False ) target_names = data_train . target_names if subset == "train" : data = X_train target = data_train . target elif subset == "test" : data = X_test target = data_test . target elif subset == "all" : data = sp . vstack ( ( X_train , X_test ) ) . tocsr ( ) target = np . concatenate ( ( data_train . target , data_test . target ) ) else : raise ValueError ( "%r is not a valid subset: should be one of " "['train', 'test', 'all']" % subset ) return Bunch ( data = data , target = target , target_names = target_names )