.. _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 878 documents (108 positive) SGD classifier : 962 train docs ( 132 positive) 878 test docs ( 108 positive) accuracy: 0.911 in 4.54s ( 211 docs/s) NB Multinomial classifier : 962 train docs ( 132 positive) 878 test docs ( 108 positive) accuracy: 0.877 in 4.58s ( 210 docs/s) Perceptron classifier : 962 train docs ( 132 positive) 878 test docs ( 108 positive) accuracy: 0.921 in 4.59s ( 209 docs/s) Passive-Aggressive classifier : 962 train docs ( 132 positive) 878 test docs ( 108 positive) accuracy: 0.908 in 4.60s ( 209 docs/s) SGD classifier : 3911 train docs ( 517 positive) 878 test docs ( 108 positive) accuracy: 0.918 in 11.23s ( 348 docs/s) NB Multinomial classifier : 3911 train docs ( 517 positive) 878 test docs ( 108 positive) accuracy: 0.885 in 11.27s ( 346 docs/s) Perceptron classifier : 3911 train docs ( 517 positive) 878 test docs ( 108 positive) accuracy: 0.926 in 11.28s ( 346 docs/s) Passive-Aggressive classifier : 3911 train docs ( 517 positive) 878 test docs ( 108 positive) accuracy: 0.958 in 11.29s ( 346 docs/s) SGD classifier : 6821 train docs ( 891 positive) 878 test docs ( 108 positive) accuracy: 0.956 in 17.68s ( 385 docs/s) NB Multinomial classifier : 6821 train docs ( 891 positive) 878 test docs ( 108 positive) accuracy: 0.899 in 17.72s ( 384 docs/s) Perceptron classifier : 6821 train docs ( 891 positive) 878 test docs ( 108 positive) accuracy: 0.949 in 17.73s ( 384 docs/s) Passive-Aggressive classifier : 6821 train docs ( 891 positive) 878 test docs ( 108 positive) accuracy: 0.960 in 17.74s ( 384 docs/s) SGD classifier : 9759 train docs ( 1276 positive) 878 test docs ( 108 positive) accuracy: 0.964 in 24.74s ( 394 docs/s) NB Multinomial classifier : 9759 train docs ( 1276 positive) 878 test docs ( 108 positive) accuracy: 0.909 in 24.78s ( 393 docs/s) Perceptron classifier : 9759 train docs ( 1276 positive) 878 test docs ( 108 positive) accuracy: 0.950 in 24.78s ( 393 docs/s) Passive-Aggressive classifier : 9759 train docs ( 1276 positive) 878 test docs ( 108 positive) accuracy: 0.954 in 24.79s ( 393 docs/s) SGD classifier : 11680 train docs ( 1499 positive) 878 test docs ( 108 positive) accuracy: 0.945 in 30.42s ( 383 docs/s) NB Multinomial classifier : 11680 train docs ( 1499 positive) 878 test docs ( 108 positive) accuracy: 0.916 in 30.46s ( 383 docs/s) Perceptron classifier : 11680 train docs ( 1499 positive) 878 test docs ( 108 positive) accuracy: 0.951 in 30.47s ( 383 docs/s) Passive-Aggressive classifier : 11680 train docs ( 1499 positive) 878 test docs ( 108 positive) accuracy: 0.954 in 30.47s ( 383 docs/s) SGD classifier : 14625 train docs ( 1865 positive) 878 test docs ( 108 positive) accuracy: 0.965 in 37.07s ( 394 docs/s) NB Multinomial classifier : 14625 train docs ( 1865 positive) 878 test docs ( 108 positive) accuracy: 0.926 in 37.11s ( 394 docs/s) Perceptron classifier : 14625 train docs ( 1865 positive) 878 test docs ( 108 positive) accuracy: 0.956 in 37.12s ( 394 docs/s) Passive-Aggressive classifier : 14625 train docs ( 1865 positive) 878 test docs ( 108 positive) accuracy: 0.967 in 37.13s ( 393 docs/s) SGD classifier : 17360 train docs ( 2179 positive) 878 test docs ( 108 positive) accuracy: 0.960 in 43.48s ( 399 docs/s) NB Multinomial classifier : 17360 train docs ( 2179 positive) 878 test docs ( 108 positive) accuracy: 0.932 in 43.54s ( 398 docs/s) Perceptron classifier : 17360 train docs ( 2179 positive) 878 test docs ( 108 positive) accuracy: 0.957 in 43.56s ( 398 docs/s) Passive-Aggressive classifier : 17360 train docs ( 2179 positive) 878 test docs ( 108 positive) accuracy: 0.967 in 43.57s ( 398 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:** 48.30 seconds ( 0 minutes 48.30 seconds)