fetch_20newsgroups
- sklearn.datasets.fetch_20newsgroups(*, data_home=None, subset='train', categories=None, shuffle=True, random_state=42, remove=(), , , ,
Load the filenames and data from the 20 newsgroups dataset (classification).
Download it if necessary.
Classes | 20 |
Samples total | 18846 |
Dimensionality | 1 |
Features | text |
Read more in the User Guide.
Specify a download and cache folder for the datasets. If None, all scikit-learn data is stored in ‘~/scikit_learn_data’ subfolders.
Select the dataset to load: ‘train’ for the training set, ‘test’ for the test set, ‘all’ for both, with shuffled ordering.
If None (default), load all the categories. If not None, list of category names to load (other categories ignored).
Whether or not to shuffle the data: might be important for models that make the assumption that the samples are independent and identically distributed (i.i.d.), such as stochastic gradient descent.
Determines random number generation for dataset shuffling. Pass an int for reproducible output across multiple function calls. See Glossary.
BunchDictionary-like object, with the following attributes.
The data list to learn.
The target labels.
The path to the location of the data.
The full description of the dataset.
The names of target classes.
return_X_y=True>>> from sklearn.datasets import fetch_20newsgroups
>>> cats = ['alt.atheism', 'sci.space']
>>> newsgroups_train = fetch_20newsgroups(subset='train', categories=cats)
>>> list(newsgroups_train.target_names)
['alt.atheism', 'sci.space']
Topic extraction with Non-negative Matrix Factorization and Latent Dirichlet Allocation
Biclustering documents with the Spectral Co-clustering algorithm
Column Transformer with Heterogeneous Data Sources
Sample pipeline for text feature extraction and evaluation
Classification of text documents using sparse features
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.
‘headers’ follows an exact standard; the other filters are not always correct.
If False, raise an OSError if the data is not locally available instead of trying to download the data from the source site.
If True, returns (data.data, data.target) instead of a Bunch
object.
Number of retries when HTTP errors are encountered.
Number of seconds between retries.
A tuple of two ndarrays. The first contains a 2D array of shape (n_samples, n_classes) with each row representing one sample and each column representing the features. The second array of shape (n_samples,) contains the target samples.