Comments (2)
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.
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)
- Value of eps() used in new implementation of quadform is too small HOT 2
- typo in logisticloss definition for scalar variables
- Add banner to old versions of Convex.jl docs HOT 1
- Consider (probably) numerically stable way of calculating `logsumexp`
- problem with Convex and new SCS (0.8.1) HOT 7
- First-run after `include(my_file.jl)` is faster than later HOT 8
- Quesitons about how Convex.jl works HOT 3
- Convex does not support broadcasting
- Fix the docs HOT 2
- LASSO/Elastic Net example HOT 4
- When I run EF optimisatios I get this error: Quadratic form only defined for Hermitian matrices
- Different result each time problem is solved HOT 3
- Positive semidefinite constraint still gives small negative eigenvalues HOT 4
- Support for quasiconvex problems HOT 2
- SDP problem 100x slower than matlab CVX HOT 3
- Precompilation failure HOT 2
- Does Convex.jl support "Difference of Convex Algorithm (DCA)"? HOT 1
- Relative Entropy Not in Supported Operations Documentation HOT 2
- trace_mpower with BigFloat HOT 2
- Add excludes MOI and Convex tests with presolve HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from convex.jl.