.. _example_applications_plot_out_of_core_classification.py: ====================================================== Out-of-core classification of text documents ====================================================== This is an example showing how scikit-learn can be used for classification using an out-of-core approach: learning from data that doesn't fit into main memory. We make use of an online classifier, i.e., one that supports the partial_fit method, that will be fed with batches of examples. To guarantee that the features space remains the same over time we leverage a HashingVectorizer that will project each example into the same feature space. This is especially useful in the case of text classification where new features (words) may appear in each batch. The dataset used in this example is Reuters-21578 as provided by the UCI ML repository. It will be automatically downloaded and uncompressed on first run. The plot represents the learning curve of the classifier: the evolution of classification accuracy over the course of the mini-batches. Accuracy is measured on the first 1000 samples, held out as a validation set. To limit the memory consumption, we queue examples up to a fixed amount before feeding them to the learner. .. rst-class:: horizontal * .. image:: images/plot_out_of_core_classification_001.png :scale: 47 * .. image:: images/plot_out_of_core_classification_002.png :scale: 47 * .. image:: images/plot_out_of_core_classification_003.png :scale: 47 * .. image:: images/plot_out_of_core_classification_004.png :scale: 47 **Script output**:: Test set is 469 documents (49 positive) Passive-Aggressive classifier : 870 train docs ( 58 positive) 469 test docs ( 49 positive) accuracy: 0.932 in 1.48s ( 588 docs/s) Perceptron classifier : 870 train docs ( 58 positive) 469 test docs ( 49 positive) accuracy: 0.906 in 1.48s ( 587 docs/s) SGD classifier : 870 train docs ( 58 positive) 469 test docs ( 49 positive) accuracy: 0.932 in 1.48s ( 585 docs/s) NB Multinomial classifier : 870 train docs ( 58 positive) 469 test docs ( 49 positive) accuracy: 0.896 in 1.51s ( 574 docs/s) Passive-Aggressive classifier : 3643 train docs ( 461 positive) 469 test docs ( 49 positive) accuracy: 0.964 in 4.42s ( 824 docs/s) Perceptron classifier : 3643 train docs ( 461 positive) 469 test docs ( 49 positive) accuracy: 0.951 in 4.42s ( 823 docs/s) SGD classifier : 3643 train docs ( 461 positive) 469 test docs ( 49 positive) accuracy: 0.959 in 4.43s ( 823 docs/s) NB Multinomial classifier : 3643 train docs ( 461 positive) 469 test docs ( 49 positive) accuracy: 0.908 in 4.45s ( 817 docs/s) Passive-Aggressive classifier : 6571 train docs ( 829 positive) 469 test docs ( 49 positive) accuracy: 0.966 in 7.19s ( 913 docs/s) Perceptron classifier : 6571 train docs ( 829 positive) 469 test docs ( 49 positive) accuracy: 0.951 in 7.19s ( 913 docs/s) SGD classifier : 6571 train docs ( 829 positive) 469 test docs ( 49 positive) accuracy: 0.953 in 7.20s ( 912 docs/s) NB Multinomial classifier : 6571 train docs ( 829 positive) 469 test docs ( 49 positive) accuracy: 0.915 in 7.23s ( 909 docs/s) Passive-Aggressive classifier : 9481 train docs ( 1176 positive) 469 test docs ( 49 positive) accuracy: 0.955 in 10.11s ( 937 docs/s) Perceptron classifier : 9481 train docs ( 1176 positive) 469 test docs ( 49 positive) accuracy: 0.938 in 10.12s ( 937 docs/s) SGD classifier : 9481 train docs ( 1176 positive) 469 test docs ( 49 positive) accuracy: 0.940 in 10.12s ( 936 docs/s) NB Multinomial classifier : 9481 train docs ( 1176 positive) 469 test docs ( 49 positive) accuracy: 0.928 in 10.15s ( 934 docs/s) Passive-Aggressive classifier : 11856 train docs ( 1454 positive) 469 test docs ( 49 positive) accuracy: 0.962 in 12.76s ( 928 docs/s) Perceptron classifier : 11856 train docs ( 1454 positive) 469 test docs ( 49 positive) accuracy: 0.934 in 12.77s ( 928 docs/s) SGD classifier : 11856 train docs ( 1454 positive) 469 test docs ( 49 positive) accuracy: 0.966 in 12.77s ( 928 docs/s) NB Multinomial classifier : 11856 train docs ( 1454 positive) 469 test docs ( 49 positive) accuracy: 0.930 in 12.80s ( 926 docs/s) Passive-Aggressive classifier : 14769 train docs ( 1827 positive) 469 test docs ( 49 positive) accuracy: 0.957 in 15.61s ( 946 docs/s) Perceptron classifier : 14769 train docs ( 1827 positive) 469 test docs ( 49 positive) accuracy: 0.945 in 15.61s ( 946 docs/s) SGD classifier : 14769 train docs ( 1827 positive) 469 test docs ( 49 positive) accuracy: 0.951 in 15.61s ( 945 docs/s) NB Multinomial classifier : 14769 train docs ( 1827 positive) 469 test docs ( 49 positive) accuracy: 0.945 in 15.64s ( 944 docs/s) Passive-Aggressive classifier : 17700 train docs ( 2188 positive) 469 test docs ( 49 positive) accuracy: 0.962 in 19.14s ( 924 docs/s) Perceptron classifier : 17700 train docs ( 2188 positive) 469 test docs ( 49 positive) accuracy: 0.951 in 19.14s ( 924 docs/s) SGD classifier : 17700 train docs ( 2188 positive) 469 test docs ( 49 positive) accuracy: 0.964 in 19.14s ( 924 docs/s) NB Multinomial classifier : 17700 train docs ( 2188 positive) 469 test docs ( 49 positive) accuracy: 0.947 in 19.19s ( 922 docs/s) **Python source code:** :download:`plot_out_of_core_classification.py ` .. literalinclude:: plot_out_of_core_classification.py :lines: 25- **Total running time of the example:** 20.98 seconds ( 0 minutes 20.98 seconds)