1

I have the following code:

# Load model
with open('text_classifier.pkl', 'rb') as f:
    countVec, model = pickle.load(f)

#Convert to bag of words
results = countVec.transform(commentsInput)

# predict converted text with the trained model
predictionsNew = model.predict(results)

print(predictionsNew)

The output from the print(predictionsNew) is as follows: [[1 0 1 0 1 0]]

When I do type(predictionsNew) it returns the type of output as numpy.ndarray

Each value in that array corresponds to a label from my dataset, and tells me if the input matches that label. For example, lets say each value corresponds to this array labels = ['a','b','c','d','e','f'].

I would like to loop through the first array and second array and produce an output as follows:

a = 1
b = 0
c = 1
d = 0
e = 1
f = 0

What is the easiest way I can achieve this?

UPDATE: I believe the array of numbers contains just one element. So basically I would like to split this single element into 6 different elements which correspond to my labels array.

pogba123
  • 79
  • 1
  • 3
  • 9
  • Variable and function names should follow the `lower_case_with_underscores` style. Can you be more specific about what you're struggling with? – AMC Jan 23 '20 at 21:26
  • Does this answer your question? [Zip lists in Python](https://stackoverflow.com/questions/13704860/zip-lists-in-python) – AMC Jan 23 '20 at 21:28

1 Answers1

1

You are looking for the zip function.

a = ["a", "b", "c", "d", "e"]
b = np.ndarray((5,), buffer=np.array([0, 1, 0, 1, 0]), dtype=int) 

for x, y in zip(a, b):
    print(f"{x} = {y}")

Outputs:

a = 0
b = 1
c = 0
d = 1
e = 0
felipe
  • 7,324
  • 2
  • 28
  • 37