https://www.tensorflow.org/api_docs/python/tf/keras/utils/to_categorical
tf.keras.utils.to_categorical | TensorFlow v2.15.0.post1
Converts a class vector (integers) to binary class matrix.
www.tensorflow.org
one hot encoding을 아주 쉽게 할 수 있다
def to_one_hot(labels, dimension=46):
results = np.zeros((len(labels), dimension))
for i, label in enumerate(labels):
results[i, label] = 1.
return results
y_train = to_one_hot(train_labels)
y_test = to_one_hot(test_labels)
from tensorflow.keras.utils import to_categorical
test = [1,2,3,4,5,6,7,11,4,200]
y_test = to_categorical()
y_train = to_categorical(train_labels)
y_test = to_categorical(test_labels)
'AI > preprocessing' 카테고리의 다른 글
one hot encoding의 이점 (0) | 2024.05.06 |
---|---|
sklearn.preproccessing (0) | 2024.04.06 |
pandas preproccessing (0) | 2024.04.06 |
pandas 데이터 시각화 (0) | 2024.03.30 |
pandas 데이터 확인 (0) | 2024.03.30 |