<jupyter_start><jupyter_text>Here we import the important modules<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline<jupyter_output><empty_output><jupyter_text>We create a dataset of 2 circles, inner circle and outer circle<jupyter_code>from sklearn.datasets import make_circles

n_samples = 200
X, y = make_circles(n_samples=n_samples, shuffle=False)
outer, inner = 0, 1
labels = -np.ones(n_samples)
labels[0] = outer
labels[-1] = inner<jupyter_output><empty_output><jupyter_text>We create our semi-supervised method label_prop and out classifier clf<jupyter_code>from sklearn import svm
from sklearn.semi_supervised import label_propagation

label_prop = label_propagation.LabelSpreading(kernel='knn', alpha=0.8, max_iter=1)
label_prop.fit(X, labels)
clf = svm.SVC(kernel='poly')
output_labels = label_prop.transduction_
plt.figure(figsize=(6, 6)) # todo have 2 propagations
plt.scatter(X[labels == outer, 0], X[labels == outer, 1], color='navy',
            marker='s', lw=0, label="outer labeled", s=10)
plt.scatter(X[labels == inner, 0], X[labels == inner, 1], color='c',
            marker='s', lw=0, label='inner labeled', s=10)
plt.scatter(X[labels == -1, 0], X[labels == -1, 1], color='darkorange',
            marker='.', label='unlabeled')
plt.legend(scatterpoints=1, shadow=False, loc='upper right')
plt.title("Raw data (2 classes=outer and inner)")
plt.figure(figsize=(6, 6))
output_label_array = np.asarray(output_labels)
outer_numbers = np.where(output_label_array == outer)[0]
inner_numbers = np.where(output_label_array == inner)[0]
plt.scatter(X[outer_numbers, 0], X[outer_numbers, 1], color='navy',
            marker='s', lw=0, s=10, label="outer learned")
plt.scatter(X[inner_numbers, 0], X[inner_numbers, 1], color='c',
            marker='s', lw=0, s=10, label="inner learned")
plt.legend(scatterpoints=1, shadow=False, loc='upper right')
plt.title("Labels learned with Label Propagation")

plt.subplots_adjust(left=0.07, bottom=0.07, right=0.93, top=0.92)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14912280701754385, 'fraction_numerical': 0.027777777777777776, 'mean_word_length': 6.254416961130742, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '332113', 'license': 'MIT', 'n_tokens_mistral': 779, 'n_tokens_neox': 723, 'n_words': 164, 'path': 'visualize label propagation.ipynb', 'repo_name': 'lukastencer/CFA-Semi-Supervised-Learning-Tutorial', 'size': '2052'}