I can confirm that the Perceptron is super non-robust and the result
varies widely with the ``n_iter`` parameter.
I am not super confident about the Perceptron, does it only converge for
separable data?
Scaling the data helps, but this is not really what I expected:
from sklearn.datasets import load_iris
from sklearn.linear_model import Perceptron
iris = load_iris()
X = iris.data[:, [0,2]]
y = iris.target
clf = Perceptron(shuffle=True, n_iter=100).fit(X, y)
clf.predict(X)
array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 2, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
With scaling:
from sklearn.preprocessing import StandardScaler
X_scaled = StandardScaler().fit_transform(X)
clf = Perceptron(shuffle=True, n_iter=100).fit(X_scaled, y)
clf.predict(X_scaled)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2])
Is a perceptron without scaling really that bad?
If so, we should really think about adding standard scaling into the
SGDClassifier....
On 02/10/2015 06:29 PM, Andy wrote:
Hi.
You don't need the OneVsRest classifier for the Perceptron.
Perceptron has penalty=None, so changing alpha doesn't change
anything. Enlarging n_iter should help.
Can you give the full code to reproduce your plots?
Thanks.
Andy
On 02/10/2015 05:53 PM, Sebastian Raschka wrote:
Hi, all,
I have a question about the multiclass perceptron in scikit-learn. I
noticed, that I only get one decision boundary
(http://i.imgur.com/CfyxPbt.png) in a simple 3 class setting.
iris = datasets.load_iris()
X = iris.data[:, [0,2]]
y = iris.target
I tried the perceptron with and without the OneVsRestClassifier
e.g.,
OneVsRestClassifier(estimator=Perceptron(alpha=1e-05,
class_weight=None, eta0=1.0, fit_intercept=True,
n_iter=20, n_jobs=1, penalty=None, random_state=123, shuffle=False,
verbose=0, warm_start=False),
n_jobs=1)
I also tried GridSearch on the alpha and n_iter parameter space.
However, the results didn't improve. Now, I am wondering why that is.
Shouldn't the multiclass perceptron produce something similar (but
worse) like the linear SVM? When the weights are updated at each
iteration, shouldn't there be a second hyperplane somewhat separating
the green and red class (in the figure) -- due to minimizing the cost
function (i.e., minimizing number of misclassifications) ?
Thanks,
Sebastian
------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now.http://goparallel.sourceforge.net/
_______________________________________________
Scikit-learn-general mailing list
Scikit-learn-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Scikit-learn-general mailing list
Scikit-learn-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general