Python error solve
0
0
Entering edit mode
2.9 years ago

Hii, I ran a script called defrag.py (https://github.com/VUmcCGP/wisecondor/blob/legacy/defrag.py) and found this error:

Traceback (most recent call last):
  File "defrag.py", line 265, in <module>
    prediction = gnb.predict[(getYPerc[testSamplesPickle[testSample]])]
TypeError: 'function' object has no attribute '__getitem__'

I changed this line numerous times but it didnt work out. I have changed the brackets because the error is due to brackets only (I guess), but I dont know how to fix it. I have already searched in google and tried but didnt get the right answer. Please help me regarding this.

python • 902 views
ADD COMMENT
0
Entering edit mode

Hi, the script seems old (circa 2014) and probably requires Python v2.x, whereas you may be using Python v3.x. Can you confirm your Python version?

Indeed, please see Requirements: https://github.com/VUmcCGP/wisecondor/tree/legacy#requirements

If needed, you could create a new miniconda environment using Python 2.7 and try the script there.

ADD REPLY
0
Entering edit mode

my python version is 2.7 only. I created new conda environment for running this in older version.

ADD REPLY
0
Entering edit mode

This is the first error before changing the parantheses:

Traceback (most recent call last):
  File "defrag.py", line 265, in <module>
    prediction = gnb.predict(getYPerc(testSamplesPickle[testSample]))
  File "/home/mdrcubuntu/anaconda3/envs/wisecondor/lib/python2.7/site-packages/sklearn/neighbors/classification.py", line 147, in predict
    X = check_array(X, accept_sparse='csr')
  File "/home/mdrcubuntu/anaconda3/envs/wisecondor/lib/python2.7/site-packages/sklearn/utils/validation.py", line 545, in check_array
    "if it contains a single sample.".format(array))
ValueError: Expected 2D array, got scalar array instead:
array=0.000588992650289.
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

I dont know how to fix it. Do you have any idea about this?

ADD REPLY
0
Entering edit mode

Hi, please do not add comments and information via the answer field. That messes up the logic of the thread. You can use ADD REPLY/COMMENT or the edit button to add details to your toplevel question. Thank you.

ADD REPLY

Login before adding your answer.

Traffic: 3383 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6