6

I am trying to check if the train data is linearly separable or not. For that I am using the following code.

try:
        import os
        import random
        import traceback
        import numpy as np
        import scipy.io as sio
        from scipy.optimize import linprog
        os.system('cls')
        dicA  = sio.loadmat('A.mat')
        A = dicA.get('A')
        lengthA = int(len(A)/1000)
        aRange = range(0,lengthA)
        selectedIndexes = random.sample(aRange,lengthA)
        A1 = A[selectedIndexes]
        del A
        b = -1*np.ones(len(A1),np.int64)
        c = np.zeros(11,np.int64)
        del dicA
        res = linprog(c, A_ub=A1, b_ub=b, bounds=(-float('inf'), float('inf')),options={"disp": True})
        print(res)
except:
        print('exception')
        tb = traceback.format_exc()
        print(tb)
finally:

        print('reached finally')

I am using the equation mentioned at this link. I get following output when I run the script.

Iteration limit reached.
     fun: -0.0
 message: 'Iteration limit reached.'
     nit: 1000
  status: 1
 success: False
       x: nan
reached finally

So, does the iteration limit reached means that data is not linearly separable, if not then how do I increase the limit.

1 Answer 1

6

I think you can add maxiter to options.

options = {"disp": True, "maxiter": 5000}
res = linprog(c, A_ub=A1, b_ub=b, bounds=(None, None), options=options)

According with documentation you can use None in bounds to specify no bounds in the given direction.

Sign up to request clarification or add additional context in comments.

1 Comment

"maxiter": 5000 did not work for me and when I increase 5000 to 50000, it worked well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.