""" 'perceptron_demo.py' David Pan, UAH """ import numpy as np from sklearn.linear_model import Perceptron x1 = np.array([3, 3]) x2 = np.array([1, 1]) X = np.vstack((x1, x2)) # Features are along the row y = np.array([1,2]) clf = Perceptron() clf.fit(X, y) clf.coef_ clf.intercept_ clf.score(X, y) # Classify handwritten digits from sklearn.datasets import load_digits digits = load_digits() print(digits.data.shape) % Display the images import matplotlib.pyplot as plt plt.gray() plt.matshow(digits.images[9]) X, y = load_digits(return_X_y=True) clf = Perceptron(tol=1e-3, random_state=0) clf.fit(X, y) clf.score(X, y)