I have this dataframe that is called xTest and this vector x
both of type numpy.ndarray
x length is 197
xtest's shape is (25000, 197).
I am trying of generate a new column for xTest called prediction by getting the dot product of xTest and x.
I tried:
xTest["pred"] = np.dot(xTest,x)
and
xTest["pred"] = xTest.dot(x)
I keep getting this error:
IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices.
xTest is already one hot encoded.
UPDATE : Thanks to the great person who pointed it out below I was able to solve it like this
df = pd.DataFrame()
df["pred"] = np.dot(xTest,x)
CodePudding user response:
Beacuse xTest is a numpy array and not a dataframe, you cannot use strings to index it. You're trying to access pred on xTest assuming xTest is a dataframe, but it's only a single column from a dataframe.
