hi, it works if you change the tolerance of the optimality check.
Set tol=1e-9: >>> clf = svm.OneClassSVM(nu=0.1, kernel="rbf", gamma=0.1, tol=1e-9) Alex PS : next time use a gist on github to avoid pasting code in an email. On Wed, Dec 21, 2011 at 7:36 PM, <[email protected]> wrote: > Hi All, > first thing I would like to say that I'm not so experienced with python > therefore I might do something really stupid which I cannot see. > Nevertheless I don't manege to understand why the following script throw > an assertion error. > Indeed, training the one class svm with a dataset or with a shuffled one > seems to give two different results. > > > Thanks for your help > > > print __doc__ > > import numpy as np > import pylab as pl > from sklearn import svm > > xx, yy = np.meshgrid(np.linspace(-7, 7, 500), np.linspace(-7, 7, 500)) > X = 0.3 * np.random.randn(100, 2) > X = np.r_[X + 2, X - 2] > > # Add 10 % of outliers (leads to nu=0.1) > X = np.r_[X, np.random.uniform(low=-6, high=6, size=(20, 2))] > > # fit the model to the data for the first time > clf = svm.OneClassSVM(nu=0.1, kernel="rbf", gamma=0.1) > clf.fit(X) > y_pred = clf.predict(X) > > > #reshuffle the trainig set > indexes=range(X.shape[0]) > import random > random.shuffle(indexes) > X2=X.copy() > X2=np.take(X2,indexes,axis=0) > > > #fit the shuffled training set > clf2 = svm.OneClassSVM(nu=0.1, kernel="rbf", gamma=0.1) > clf2.fit(X2) > > > > #predict on the normal data > y_pred2 = clf2.predict(X) > np.testing.assert_array_equal(y_pred,y_pred2) > > ------------------------------------------------------------------------------ > RSA(R) Conference 2012 > Mar 27 - Feb 2 > Save $400 by Jan. 27 > Register now! > http://p.sf.net/sfu/rsa-sfdev2dev2 > _______________________________________________ > Scikit-learn-general mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/scikit-learn-general ------------------------------------------------------------------------------ RSA(R) Conference 2012 Mar 27 - Feb 2 Save $400 by Jan. 27 Register now! http://p.sf.net/sfu/rsa-sfdev2dev2 _______________________________________________ Scikit-learn-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
