# Help with Logit NLP problem

**URL:** <https://discourse.julialang.org/t/help-with-logit-nlp-problem/19296>\
**Category:** Optimization (Mathematical)\
**Created:** [January 5, 2019, 7:07am UTC](https://discourse.julialang.org/t/help-with-logit-nlp-problem/19296 "2019-01-05T07:07:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SonLe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sonle/32/9507_2.png) [@SonLe](https://discourse.julialang.org/u/SonLe)\
**Post date:** [January 5, 2019, 7:07am UTC](https://discourse.julialang.org/t/help-with-logit-nlp-problem/19296/1 "2019-01-05T07:07:47Z")

</div>

Hi.  
I found this [thesis](https://dspace.mit.edu/handle/1721.1/119284) online and wanted to reproduce the section Robust both Feature and Label for Logistic Regression. The Logit model here looks like this:

 ![ask](https://global.discourse-cdn.com/julialang/original/3X/e/6/e679b3fa2faeff783eea69d2a043f91655b98210.png)  
My problem is that when i compute the first constraint in the model, It return “Unexpected object in nonlinear expression”.

Could someone point me where i were wrong ? I used the Wisconsin Breast Cancer Dataset from [UCI](https://archive.ics.uci.edu/ml/datasets/Breast+Cancer+Wisconsin+%28Diagnostic%29).  
My code:

```julia
using ScikitLearn
using JuMP
using Ipopt
using PyCall, Pandas
using LinearAlgebra
using ScikitLearn.CrossValidation: train_test_split
@sk_import preprocessing: StandardScaler
@sk_import preprocessing: LabelEncoder

url = "D:/python-machinelearning-datascience/thesis/data/data.csv"
data = read_csv(url)
list = ["Unnamed: 32", "id", "diagnosis"]
x = drop(data, list, axis=1)
y = data.diagnosis

x1 = fit_transform!(StandardScaler(),x)
y1 = fit_transform!(LabelEncoder(),y)
y1 = [(yi == 1.0) ? 1.0 : -1.0 for yi in y1]
X_train, X_test, y_train, y_test = train_test_split(x1, y1, test_size=.3)
n, p = size(X_train)
rho = 0.01
m = Model(solver=IpoptSolver())
@variables m begin
    (v[1:n] <= 0, start = 0.0)
    (μ <= 0, start = 0.0)
    (β[i=1:p], start = zeros(p)[i])
    β0
    (w[1:p] >= 0, start = 0.0)
    hs_norm >= 0
    fx[1:n]
end

@constraint(m, fxcon[i=1:n], fx[i] == sum(X_train[i, j]*β[j] for j=1:p) + β0)
#l1norm constraint
@constraint(m, hs_norm == sum(w[j] for j=2:p))
@constraint(m, pos_abs[i=2:p], w[i] >= β[i])
@constraint(m, neg_abs[i=2:p], w[i] >= -β[i])

#first constraint
@NLconstraint(m, firstcon[i=1:n], μ + v[i] <= log(1+exp(-y_train[i]*fx[i] + rho*hs_norm)) - log(1+exp(y_train[i]*fx[i] + rho*hs_norm)))

@NLobjective(m, Max, -sum(log(1+exp(-y_train[i]*fx[i]+rho*hs_norm)) for i=1:n)+ 0.1*n*μ + sum(v[i] for i=1:n))

solve(m)
beta, beta0 =getValue(β)[:], getValue(β0)

```

I

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [January 8, 2019, 4:06pm UTC](https://discourse.julialang.org/t/help-with-logit-nlp-problem/19296/2 "2019-01-08T16:06:56Z")

</div>

From a quick glance, I can’t see anything unusual. What is the type of `y_train`?

Can you simplify the example? Strip out all the unneeded parts so that the error still occurs. For example, you could use random data for `X_train` etc to remove the dependence on ScikitLearn.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …
