Giter Club home page Giter Club logo

Comments (2)

madeleineudell avatar madeleineudell commented on June 7, 2024

Hi Daisy,

It looks like you need to use labels +-1, rather than 0 and 1. There's also
an easier way of writing logistic regression in Convex.jl. If you pull the
most recent version from master, this should work:

using DataFrames
using RDatasets
using Convex
using SCS

iris = dataset("datasets", "iris")
iris[:Y] = [species == "versicolor" ? 1.0 : -1.0 for species in
iris[:Species]]
X = [ones(size(iris, 1)) iris[:SepalLength] iris[:SepalWidth]
iris[:PetalLength] iris[:PetalWidth]]
Y = array(iris[:Y])

Solve the NLP using Convex.jl and SCS packages

reference:

http://cvxr.com/cvx/examples/cvxbook/Ch07_statistical_estim/html/logistics.html
n, p = size(X)
beta = Variable(p)
problem = minimize(sum([logistic_loss(-Y[i]_(X[i,:]_beta)) for i=1:n])) #
-0.01*norm(beta,1)

scs = SCSSolver()
solve!(problem, scs)

and you can plot the solution like this:

using Gadfly
perm = Base.Sort.sortperm(vec(X_beta.value))
set_default_plot_size(25cm, 12cm)
plot(layer(x=1:n,y=(Y[perm]+1)/2,Geom.point),layer(x=1:n,y=logistic(X_beta.value)[perm],Geom.line))

[image: Inline image 1]

Best,
Madeleine

On Wed, Jan 7, 2015 at 10:09 AM, Daisy Zhuo [email protected]
wrote:

Hello!

I am using convex.jl to test and see if it works on a simple maximum
likelihood estimator for logistic regression. It is giving me unbounded
results though - I am not sure if it's an issue with my formulation or
something else. Would you be able to take a quick look and let me know
where I may have made a mistake? Thank you very much in advance!

using DataFramesusing RDatasetsusing Convexusing SCS

iris = dataset("datasets", "iris")
iris[:Y] = [species == "versicolor" ? 1.0 : 0.0 for species in iris[:Species]]
X = [ones(size(iris, 1)) iris[:SepalLength] iris[:SepalWidth] iris[:PetalLength] iris[:PetalWidth]]
Y = array(iris[:Y])

Solve the NLP using Convex.jl and SCS packages# reference: http://cvxr.com/cvx/examples/cvxbook/Ch07_statistical_estim/html/logistics.html

n, p = size(X)
beta = Variable(p)
problem = maximize(Y'_X_beta-sum(logsumexp([X_beta zeros(n)]))) # -0.01_norm(beta,1)

scs = SCSSolver()solve!(problem, scs)

Output:

Setup time: 8.27e-04s

Iter | pri res | dua res | rel gap | pri obj | dua obj | kap/tau | time (s)

 0|      inf       inf       nan      -inf       inf       inf  3.44e-03
40|      inf       inf       nan      -inf      -inf       inf  5.09e-03

Status: Unbounded


Reply to this email directly or view it on GitHub
#46.

Madeleine Udell
PhD Candidate in Computational and Mathematical Engineering
Stanford University
www.stanford.edu/~udell

from convex.jl.

daisy12321 avatar daisy12321 commented on June 7, 2024

Hi Madeleine,

This works like a charm. Logistic loss and using +1/-1 labels does make it look neater and run correctly.

Thank you very much!

Cheers,
Daisy

from convex.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.