When I try to implement in my local environment
Y_train = convert_to_one_hot(Y_train, 10).T
I get :
NameError: name ‘convert_to_one_hot’ is not defined
I have imported all the basic packages and more
What should I install to get convert_to_one_hot working?
Answer to myself. I found resnets_utils, the convert function is there. I also found a more robust conversion routine as follows
def convertToOneHot(vector, num_classes=None):
“”"
Converts an input 1-D vector of integers into an output
2-D array of one-hot vectors, where an i’th input value
of j will set a ‘1’ in the i’th row, j’th column of the
output array.
"""
assert isinstance(vector, np.ndarray)
assert len(vector) > 0
if num_classes is None:
num_classes = np.max(vector)+1
else:
assert num_classes > 0
assert num_classes >= np.max(vector)
result = np.zeros(shape=(len(vector), num_classes))
result[np.arange(len(vector)), vector] = 1
return result.astype(int)