.argmax(axis =1) not working on a numpy array

Viewed 424

Hi I am trying to use argmax function on a numpy array but it shows an error.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-25-914c12a3a737> in <module>()
      5 # TODO - Check for data issues
      6 # Hint: You can convert from one-hot to integers with argmax
----> 7 train_df1 = train_df1.argmax(axis = 1)
      8 
      9 # Initialise

AttributeError: 'function' object has no attribute 'argmax'

code:


train_df1

<bound method DataFrame.to_numpy of      MEL   NV  BCC  AKIEC  BKL   DF  VASC
0    0.0  1.0  0.0    0.0  0.0  0.0   0.0
1    0.0  1.0  0.0    0.0  0.0  0.0   0.0
2    0.0  1.0  0.0    0.0  0.0  0.0   0.0
3    0.0  1.0  0.0    0.0  0.0  0.0   0.0
4    1.0  0.0  0.0    0.0  0.0  0.0   0.0
..   ...  ...  ...    ...  ...  ...   ...
194  0.0  1.0  0.0    0.0  0.0  0.0   0.0
195  0.0  1.0  0.0    0.0  0.0  0.0   0.0
196  0.0  1.0  0.0    0.0  0.0  0.0   0.0
197  0.0  1.0  0.0    0.0  0.0  0.0   0.0
198  0.0  0.0  1.0    0.0  0.0  0.0   0.0

[199 rows x 7 columns]>


train_df1 = train_df1.argmax(axis = 1)

does anyone understand why I am getting this?

Thanks

1 Answers

You'll need to post more code for us to duplicate that behaviour, but we can see from the error messages what's going on.

train_df1 is a function. You need to call the function:

my_values = train_df1()
my_max = my_values.argmax(axis = 1)

The main clue is when you type train_df1 at the prompt and it tells you it's a "bound method" that's another name for a function you need to call.

I'm also assuming your train_df1 function returns a numpy array, such that the argmax function call will work.

In one line, it's just:

my_max = train_df1().argmax(axis = 1)

You'll definitely not want to redefine "train_def1" as a variable, so be sure to pick a new named variable to hold the max values returned.

Related