2012/1/30 Mathias Verbeke <[email protected]>: > Hi all, > > Yet another question: now I want to do some plotting, for which I used the > code from > http://scikit-learn.org/stable/auto_examples/svm/plot_separating_hyperplane.html#example-svm-plot-separating-hyperplane-py > > but I get the following error: > > > Traceback (most recent call last): > File "./svm_sklearn.py", line 82, in <module> > test(test_file_name, model_file_name, output_file_name) > File "./svm_sklearn.py", line 42, in test > plot(clf, X_test, y_test) > File "./svm_sklearn.py", line 52, in plot > a = -w[0] / w[1] > File "/usr/lib/python2.6/dist-packages/scipy/sparse/csr.py", line 260, in > __getitem__ > return self[key,:] #[i] or [1:2] > File "/usr/lib/python2.6/dist-packages/scipy/sparse/csr.py", line 221, in > __getitem__ > return self._get_row_slice(row, col) #[i,1:2] > File "/usr/lib/python2.6/dist-packages/scipy/sparse/csr.py", line 299, in > _get_row_slice > raise IndexError('index (%d) out of range' % i ) > IndexError: index (1) out of range > > Could this have something to do with the sparse vectors?
Maybe. Try to do: >>> print clf.coef_ and >>> clf.coef_[0] if coef_ is sparse the latter will return a matrix with shape (1, n_features). You can define: w = clf.coef_.toarray() in that case and the should solve your issue (if the dense array representation of the coef fits in memory). However if you are using sparse inputs that probably means that you have high dimensional data, hence I don't see the case for plotting the decision function on the first 2 dimensions. I don't think it will provide you with any particular insight. -- Olivier http://twitter.com/ogrisel - http://github.com/ogrisel ------------------------------------------------------------------------------ Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2 _______________________________________________ Scikit-learn-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
