Created
June 5, 2019 07:37
-
-
Save jiaxianhua/3442e76aefff8202a6e33532e74d0ae5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sklearn.datasets import make_classification | |
from slmethod.perceptron import Perceptron | |
separable = False | |
while not separable: | |
samples = make_classification(n_samples=100, | |
n_features=2, | |
n_redundant=0, | |
n_informative=1, | |
n_clusters_per_class=1, | |
flip_y=-1) | |
red = samples[0][samples[1] == 0] | |
blue = samples[0][samples[1] == 1] | |
separable = any([ | |
red[:, k].max() < blue[:, k].min() | |
or red[:, k].min() > blue[:, k].max() for k in range(2) | |
]) | |
X = samples[0] | |
y = samples[1] | |
y = np.array([1 if i == 1 else -1 for i in y]) | |
minX = np.min(X[:, 0]) | |
maxX = np.max(X[:, 0]) | |
x_points = np.array([minX, maxX]) | |
origin_clf = Perceptron(dual=False) | |
origin_clf.fit(X, y) | |
print(origin_clf.w) | |
print(origin_clf.b) | |
origin_clf.show2d('slmethod_perceprton.gif') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment