13 Label Propagation
In [1]:
from sklearn.datasets import load_iris
X,y = load_iris(return_X_y = True, as_frame = True)In [2]:
import numpy as np
rng = np.random.RandomState(123)
random_unlabeled_points = rng.rand(len(y)) < 0.7
y[random_unlabeled_points] = -1In [6]:
import matplotlib.pyplot as plt
plt.scatter(X['sepal length (cm)'],X['petal length (cm)'], c=y, cmap='Set1')<matplotlib.collections.PathCollection at 0x7f5ce6f7f550>
In [4]:
from sklearn.semi_supervised import LabelPropagation
label_prop_model = LabelPropagation()
label_prop_model.fit(X, y)LabelPropagation()
In [5]:
y_pred = label_prop_model.predict(X)
plt.scatter(X['sepal length (cm)'],X['petal length (cm)'], c=y_pred)<matplotlib.collections.PathCollection at 0x7f5ce6fe5b90>