Issue
I have successfully encoded my data like this:
reviewerLe = LabelBinarizer()
reviewerIDs = reviewerLe.fit_transform(df['reviewerID'])
and
print(reviewerIDs[1])
reviewerIDs[1].shape
outputs
[0 0 0 ... 0 0 0]
(4975,)
I am wondering how to inverse transform only one or a couple of predicted values.
reviewerLe.inverse_transform(reviewerIDs[1])
outputs
axis 1 is out of bounds for array of dimension 1
I don't quite understand what the function exprects. In the docs is stated :
inverse_transform(Y, threshold=None) Y{ndarray, sparse matrix} of shape (n_samples, n_classes)
Target values. All sparse matrices are converted to CSR before inverse transformation.
Does that mean that i should reshape my array to (1,4975)? If yes, how?
Solution
inverse_transform() expects a 2D array, but you're passing a 1D array to it.
You can reshape your 1D array into a 2D
reviewerIDs_2D = reviewerIDs[1].reshape(1, -1)
reviewerLe.inverse_transform(reviewerIDs_2D)
Answered By - Alperen Tahta
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.