Skip to content

Commit 6787da4

Browse files
author
Hobson Lane
committed
make it clear that linear_model.Perceptron is a classifier
1 parent 2ab7e34 commit 6787da4

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

doc/modules/linear_model.rst

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,12 +1233,19 @@ This way, we can solve the XOR problem with a linear classifier::
12331233
>>> import numpy as np
12341234
>>> X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
12351235
>>> y = X[:, 0] ^ X[:, 1]
1236-
>>> X = PolynomialFeatures(interaction_only=True).fit_transform(X)
1236+
>>> y
1237+
array([0, 1, 1, 0])
1238+
>>> X = PolynomialFeatures(interaction_only=True).fit_transform(X).astype(int)
12371239
>>> X
1238-
array([[ 1., 0., 0., 0.],
1239-
[ 1., 0., 1., 0.],
1240-
[ 1., 1., 0., 0.],
1241-
[ 1., 1., 1., 1.]])
1240+
array([[1, 0, 0, 0],
1241+
[1, 0, 1, 0],
1242+
[1, 1, 0, 0],
1243+
[1, 1, 1, 1]])
12421244
>>> clf = Perceptron(fit_intercept=False, n_iter=10, shuffle=False).fit(X, y)
1245+
1246+
And the classifier "predictions" are perfect
1247+
1248+
>>> clf.predict(X)
1249+
array([0, 1, 1, 0])
12431250
>>> clf.score(X, y)
12441251
1.0

0 commit comments

Comments
 (0)