import numpy as np
from sklearn.datasets import load_iris
from sklearn.linear_model import Perceptron

iris = load_iris()
X = iris.data[:, (2, 3)]  # petal length, petal width
y = (iris.target == 0).astype(int) # 'setosa'

clf = Perceptron(max_iter=1000, tol=1e-3, random_state=42)
clf.fit(X, y)
clf.score(X, y) # 1
clf.decision_function(X) # only first 50 elements are positive
sum(clf.decision_function(X) > 0) # 50
clf.predict(X) # first 50 elements are ones 

a = -clf.coef_[0][0] / clf.coef_[0][1]
b = -clf.intercept_ / clf.coef_[0][1]

# =============================================================================
# different dataset
# =============================================================================
# from sklearn.datasets import load_digits
# from sklearn.linear_model import Perceptron
# X, y = load_digits(return_X_y=True)
# clf = Perceptron(tol=1e-3, random_state=0)
# clf.fit(X, y)

# clf.score(X, y)