I would use elastic-net with y = -1 or 1 such that np.mean(y) == 0 and then when you predict threshold the predictions at 0.
Alex On Mon, Feb 27, 2012 at 10:06 AM, Matthias Ekman <[email protected]> wrote: > thanks Alexandre and Olivier. Indeed I don't expect to get better > performance in comparison to logistic regression with L1 regularization. > I guess my question was more on how to force the fit method to learn a > binary output. Using my code below, it assumes a regression problem. How > do I use Elastic Net for classification in practice? > > Thanks, > Matthias > > > from sklearn.linear_model import ElasticNet > from sklearn import datasets > > iris = datasets.load_iris() > X = iris.data > y = iris.target > > idx=np.where(y!=2)[0] # select only labels 0 & 1 > X=X[idx,:] > y=y[idx,:] > X /= X.std(0) > > clf = ElasticNet(alpha=0.1, rho=0.7) > clf.fit(X,y) > > In [53]: clf.predict(X) > Out[53]: > array([ 0.06641272, 0.11714499, 0.08138986, 0.12246076, 0.05626627, > 0.12908023, 0.1049925 , 0.0920214 , 0.12729145, 0.09402743, > 0.06158204, 0.10748362, 0.08871166, 0.04232499, -0.01524399, > 0.04742352, 0.06723134, 0.09484605, 0.11079336, 0.07986891, > 0.12294584, 0.1184487 , -0.00558262, 0.21839229, 0.15387029, > 0.14806944, 0.16435028, 0.08187494, 0.07655918, 0.12777653, > 0.13792298, 0.14888806, -0.00743711, -0.00461246, 0.09402743, > 0.06592764, 0.0509505 , 0.09402743, 0.10168277, 0.0920214 , > 0.07938383, 0.20114128, 0.08138986, 0.21107048, 0.17015113, > 0.14557832, 0.06689781, 0.09685208, 0.06158204, 0.08670563, > 0.94830539, 0.94581427, 1.01780962, 0.90295459, 1.00186231, > 0.92953343, 0.9950256 , 0.69927258, 0.9348492 , 0.87533988, > 0.77078285, 0.91972051, 0.82780105, 0.97874475, 0.78022697, > 0.91206518, 0.96610718, 0.79253101, 1.04727881, 0.8103328 , > 1.07750093, 0.85222232, 1.07868834, 0.93202455, 0.88846253, > 0.92221163, 1.00435343, 1.10028496, 0.97625364, 0.70990412, > 0.80501703, 0.76112148, 0.81847322, 1.11775321, 0.96610718, > 0.9539547 , 0.98688517, 0.96480348, 0.84739163, 0.88266168, > 0.90593079, 0.95313608, 0.8440819 , 0.70941904, 0.89329322, > 0.83442053, 0.87300031, 0.88846253, 0.67117279, 0.86768454]) > > > > On 2/26/12 5:27 PM, [email protected] > wrote: >> ------------------------------ >> >> Message: 5 >> Date: Fri, 24 Feb 2012 18:18:15 +0100 >> From: Alexandre Gramfort<[email protected]> >> Subject: Re: [Scikit-learn-general] ElasticNet for classification? >> To: [email protected] >> Message-ID: >> <cadeotzqprrh0qwfomr7yascp99zmthjxl54no9swo391ku4...@mail.gmail.com> >> Content-Type: text/plain; charset=ISO-8859-1 >> >> hi, >> >> you could even if the squared loss is not really natural for >> classification settings. >> >> I'd be surprised if it gives a better result that a sparse logistic >> regression for example. >> >> Alex >> >> On Fri, Feb 24, 2012 at 6:13 PM, Matthias Ekman >> <[email protected]> wrote: >>> Hi, >>> >>> I was wondering is it possible to use the current implementation of >>> ElasticNet or LARS also for classification instead of regression? >>> >>> Thanks, >>> ?Matthias >>> >>> ------------------------------------------------------------------------------ >>> Virtualization& Cloud Management Using Capacity Planning >>> Cloud computing makes use of virtualization - but cloud computing >>> also focuses on allowing computing to be delivered as a service. >>> http://www.accelacomm.com/jaw/sfnl/114/51521223/ >>> _______________________________________________ >>> Scikit-learn-general mailing list >>> [email protected] >>> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general >> >> >> ------------------------------ >> >> Message: 6 >> Date: Fri, 24 Feb 2012 19:22:38 +0100 >> From: Olivier Grisel<[email protected]> >> Subject: Re: [Scikit-learn-general] ElasticNet for classification? >> To: [email protected] >> Message-ID: >> <CAFvE7K6S=n_qp22mictvy4hoqo1hxoglmn+pznueuqbff3b...@mail.gmail.com> >> Content-Type: text/plain; charset=UTF-8 >> >> Yes and if you want multi class support you can use the >> sklearn.multiclass wrappers on them too. >> >> I would be interested to learn about any feedback where those models >> perform better / faster than the other sklearn classfiers. >> > > ------------------------------------------------------------------------------ > 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 ------------------------------------------------------------------------------ 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
