code: def eval_and_print_metrics(clf, X_train, y_train, X_test, y_test):
      print("Number of training samples:", len(X_train))
      print(
          "Unlabeled samples in training set:",
          sum(1 for x in y_train if x == -1),
      )
      clf.fit(X_train, y_train)
      y_pred = clf.predict(X_test)
      print(
          "Micro-averaged F1 score on test set: %0.3f"
          % f1_score(y_test, y_pred, average="micro")
      )
      print("-" * 10)
      print()
  
file_path: scikit-learn/examples/semi_supervised/plot_semi_supervised_newsgroups.py
imports: import numpy
  from sklearn.datasets import fetch_20newsgroups
  from sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer
  from sklearn.linear_model import SGDClassifier
  from sklearn.metrics import f1_score
  from sklearn.model_selection import train_test_split
  from sklearn.pipeline import Pipeline
  from sklearn.preprocessing import FunctionTransformer
  from sklearn.semi_supervised import LabelSpreading, SelfTrainingClassifier
label_desc: Use image node_id 1 for calling a global function with example usage: eval_and_print_metrics(clf, X_train, y_train, X_test, y_test) without return types