8000 ENH Improve `plot_semi_supervised_newsgroups.py` example by patel-zeel · Pull Request #21673 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions examples/semi_supervised/plot_semi_supervised_newsgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

"""

import os

import numpy as np

Expand All @@ -26,7 +25,17 @@
from sklearn.semi_supervised import LabelSpreading
from sklearn.metrics import f1_score

data = fetch_20newsgroups(subset="train", categories=None)
# Loading dataset containing first five categories
data = fetch_20newsgroups(
subset="train",
categories=[
"alt.atheism",
"comp.graphics",
"comp.os.ms-windows.misc",
"comp.sys.ibm.pc.hardware",
"comp.sys.mac.hardware",
],
)
print("%d documents" % len(data.filenames))
print("%d categories" % len(data.target_names))
print()
Expand Down Expand Up @@ -98,7 +107,5 @@ def eval_and_print_metrics(clf, X_train, y_train, X_test, y_test):
print("SelfTrainingClassifier on 20% of the training data (rest is unlabeled):")
eval_and_print_metrics(st_pipeline, X_train, y_train, X_test, y_test)

if "CI" not in os.environ:
# LabelSpreading takes too long to run in the online documentation
print("LabelSpreading on 20% of the data (rest is unlabeled):")
eval_and_print_metrics(ls_pipeline, X_train, y_train, X_test, y_test)
print("LabelSpreading on 20% of the data (rest is unlabeled):")
eval_and_print_metrics(ls_pipeline, X_train, y_train, X_test, y_test)
0