Skip to content

Fix some algorithms running in 32-bit mode #11544

Closed

Description

@jrmlhermitte

Description

Some algorithms don't pass tests in 32-bit mode. They should be investigated.

Steps/Code to Reproduce

To test this, you just need to run (in some temp directory where it is okay to clone a temp repo to):

git clone https://www.github.com/scikit-learn/scikit-learn
cd scikit-learn
# run docker container in interactive mode:
docker run --rm  -it -v`pwd`:/io quay.io/pypa/manylinux1_i686 /bin/bash
export PATH=/opt/python/cp36-cp36m/bin:$PATH
pip install numpy scipy cython pytest; cd /io;python setup.py develop;sed -i '/--doctest-modules/d' setup.cfg;pytest -l sklearn

The building will take a while....

Expected Results

Tests should all pass

Actual Results

Three fail.
See #11515

Versions

Activity

  1. massich commented on Jul 16, 2018

    @massich
    Contributor

    thx for the MWE.
    I started looking at this:

    bash-3.2# pytest sklearn/svm/tests/test_sparse.py -k test_sparse_oneclasssvm
    ========================================= test session starts ==========================================
    platform linux -- Python 3.6.5, pytest-3.6.3, py-1.5.4, pluggy-0.6.0
    rootdir: /io, inifile: setup.cfg
    collected 16 items / 15 deselected                                                                     
    
    sklearn/svm/tests/test_sparse.py F                                                               [100%]
    
    =============================================== FAILURES ===============================================
    _______________________________________ test_sparse_oneclasssvm ________________________________________
    
        def test_sparse_oneclasssvm():
            # Check that sparse OneClassSVM gives the same result as dense OneClassSVM
            # many class dataset:
            X_blobs, _ = make_blobs(n_samples=100, centers=10, random_state=0)
            X_blobs = sparse.csr_matrix(X_blobs)
        
            datasets = [[X_sp, None, T], [X2_sp, None, T2],
                        [X_blobs[:80], None, X_blobs[80:]],
                        [iris.data, None, iris.data]]
            kernels = ["linear", "poly", "rbf", "sigmoid"]
            for dataset in datasets:
                for kernel in kernels:
                    clf = svm.OneClassSVM(gamma='scale', kernel=kernel, random_state=42)
                    sp_clf = svm.OneClassSVM(gamma='scale', kernel=kernel, random_state=42)
    >               check_svm_model_equal(clf, sp_clf, *dataset)
    
    sklearn/svm/tests/test_sparse.py:282: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    dense_svm = OneClassSVM(cache_size=200, coef0=0.0, degree=3, gamma='scale', kernel='poly',
          max_iter=-1, nu=0.5, random_state=42, shrinking=True, tol=0.001,
          verbose=False)
    sparse_svm = OneClassSVM(cache_size=200, coef0=0.0, degree=3, gamma='scale', kernel='poly',
          max_iter=-1, nu=0.5, random_state=42, shrinking=True, tol=0.001,
          verbose=False)
    X_train = <6x2 sparse matrix of type '<class 'numpy.int32'>'
    	with 12 stored elements in LInked List format>
    y_train = None, X_test = array([[-1, -1],
           [ 2,  2],
           [ 3,  2]])
    
        def check_svm_model_equal(dense_svm, sparse_svm, X_train, y_train, X_test):
            dense_svm.fit(X_train.toarray(), y_train)
            if sparse.isspmatrix(X_test):
                X_test_dense = X_test.toarray()
            else:
                X_test_dense = X_test
            sparse_svm.fit(X_train, y_train)
            assert_true(sparse.issparse(sparse_svm.support_vectors_))
            assert_true(sparse.issparse(sparse_svm.dual_coef_))
            assert_array_almost_equal(dense_svm.support_vectors_,
                                      sparse_svm.support_vectors_.toarray())
            assert_array_almost_equal(dense_svm.dual_coef_,
    >                                 sparse_svm.dual_coef_.toarray())
    E       AssertionError: 
    E       Arrays are not almost equal to 6 decimals
    E       
    E       (mismatch 83.33333333333333%)
    E        x: array([[0.993464, 0.258659, 0.264268, 0.212662, 0.270947, 1.      ]])
    E        y: array([[0.993326, 0.263301, 0.259931, 0.216799, 0.266643, 1.      ]])
    
    sklearn/svm/tests/test_sparse.py:53: AssertionError
    ========================= 1 failed, 15 deselected, 4 warnings in 0.49 seconds ==========================

    My initial idea was that it had to do with the random state. I tried the following but is not there.

                     clf = svm.OneClassSVM(gamma='scale', kernel=kernel, random_state=42)
                    sp_clf = svm.OneClassSVM(gamma='scale', kernel=kernel, random_state=42)

    I'll keep working on it (but maybe we need to let it for after 0.20 release)

  2. massich commented on Jul 16, 2018

    @massich
    Contributor

    Can anyone help in tracing the differences between libsvm.fit and libsvm_sparse.libsvm_sparse_train ??

  3. jrmlhermitte commented on Jul 18, 2018

    @jrmlhermitte
    Author

    great thanks! maybe @ogrisel would know?

  4. thomasjpfan commented on Jan 16, 2020

    @thomasjpfan
    Member

    We have 32bit linux testing on the azure CI to catch these types of bugs now. Currently all the tests pass on the 32bit instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions