cjlin1 / liblinear

LIBLINEAR -- A Library for Large Linear Classification
https://www.csie.ntu.edu.tw/~cjlin/liblinear/
BSD 3-Clause "New" or "Revised" License
1k stars 343 forks source link

Problem running the example for testing LIBLINEAR with instance weight support #83

Closed ksong4 closed 2 years ago

ksong4 commented 2 years ago

I recently installed the LIBLINEAR and was testing the example scripts that were part of the README.weight

The following codes work until the problem() command

from liblinear.liblinearutil import *
import csv
y, x = svm_read_problem('./heart_scale', return_scipy=True)
W = [1] * len(y)
W[0] = 10
prob = problem(W, y, x) # Error occurs here 

The error code is shown here:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ksong4/miniconda3/lib/python3.7/site-packages/liblinear/liblinear.py", line 194, in __init__
    tmp_xi, tmp_idx = gen_feature_nodearray(xi)
  File "/home/ksong4/miniconda3/lib/python3.7/site-packages/liblinear/liblinear.py", line 106, in gen_feature_nodearray
    raise TypeError('xi should be a dictionary, list, tuple, 1-d numpy array, or tuple of (index, data)')
TypeError: xi should be a dictionary, list, tuple, 1-d numpy array, or tuple of (index, data)

The imported x and y are both lists using the provided example heart_scale file.

cjlin1 commented 2 years ago

Looks like you already have liblinear in the system but would like to use the liblinear "weight" extension?

If you run this example in the directory liblinear-weights-2.45/python I believe the weight code instead of the system package will be called first

On 2022-08-24 12:41, Kuncheng Song wrote:

I recently installed the LIBLINEAR and was testing the example scripts that were part of the README.weight

The following codes work until the problem() command

from liblinear.liblinearutil import import csv y, x = svm_read_problem('./heart_scale', return_scipy=True) W = [1] len(y) W[0] = 10 prob = problem(W, y, x) # Error occurs here

The error code is shown here:

Traceback (most recent call last): File "", line 1, in File "/home/ksong4/miniconda3/lib/python3.7/site-packages/liblinear/liblinear.py", line 194, in init tmp_xi, tmp_idx = gen_feature_nodearray(xi) File "/home/ksong4/miniconda3/lib/python3.7/site-packages/liblinear/liblinear.py", line 106, in gen_feature_nodearray raise TypeError('xi should be a dictionary, list, tuple, 1-d numpy array, or tuple of (index, data)') TypeError: xi should be a dictionary, list, tuple, 1-d numpy array, or tuple of (index, data)

The imported x and y are both lists using the provided example heart_scale file.

-- Reply to this email directly, view it on GitHub [1], or unsubscribe [2]. You are receiving this because you are subscribed to this thread.Message ID: @.> [ { @.": "http://schema.org", @.": "EmailMessage", "potentialAction": { @.": "ViewAction", "target": "https://github.com/cjlin1/liblinear/issues/83", "url": "https://github.com/cjlin1/liblinear/issues/83", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { @.***": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

Links:

[1] https://github.com/cjlin1/liblinear/issues/83 [2] https://github.com/notifications/unsubscribe-auth/ABI3BHTDZFK3YBTZLVKJVRDV2WRYLANCNFSM57NZYF2A

ksong4 commented 2 years ago

Thank you so much for your prompt and helpful commands; I was indeed in the wrong directory when running the example.