3 글 보임 - 1 에서 3 까지 (총 3 중에서)
-
글쓴이글
-
2023년 1월 16일 17:12 #62917
김민관참가자선생님께서 강의하신 '이 사람이 죽을 확률은?' 강의를 보고 다른 csv파일을 사용하여 비슷하게 작업해보았습니다. 받은 train 데이터는 강의 내용과 비슷했기 때문에 feature_column 을 사용하기로 했습니다. 10개의 특징이 있는 데이터를 numeric_column을 사용하여 딕셔너리로 분류했고, 라벨은 모두 정수로 치환하여 데이터 셋을 구성하였습니다.
# ------------ 코드 내용의 일부 ------------------- train = pd.read_csv('./../../../music/train.csv') test = pd.read_csv('./../../../music/test.csv') co_answer = train.pop('genre') ds = tf.data.Dataset.from_tensor_slices( ( dict(train), y_train) ) ds_test = tf.data.Dataset.from_tensor_slices( (dict(test) ) )
feature_columns = [] feature_columns.append(tf.feature_column.numeric_column('danceability')) feature_columns.append(tf.feature_column.numeric_column('energy')) feature_columns.append(tf.feature_column.numeric_column('key')) feature_columns.append(tf.feature_column.numeric_column('loudness')) feature_columns.append(tf.feature_column.numeric_column('speechiness')) feature_columns.append(tf.feature_column.numeric_column('acousticness')) feature_columns.append(tf.feature_column.numeric_column('instrumentalness')) feature_columns.append(tf.feature_column.numeric_column('liveness')) feature_columns.append(tf.feature_column.numeric_column('valence')) feature_columns.append(tf.feature_column.numeric_column('tempo'))
#모델의 형태는 생략했습니다.
model.compile(optimizer = 'adam', loss = 'sparse_categorical_crossentropy', metrics = ['accuracy'])
ds_batch = ds.batch(32) model.fit(ds_batch, shuffle=True, epochs = 100, callbacks = [tensroboard] )
결과로 정확도가 0.73정도로 나오는 모델을 만들었고, 테스트를 하고자 model.predict(ds_test)를 했지만
ValueError: Exception encountered when calling layer 'dense_features' (type DenseFeatures).
We expected a dictionary here. Instead we got:
Call arguments received by layer 'dense_features' (type DenseFeatures): • features=tf.Tensor(shape=(None, 11), dtype=float32) • cols_to_output_tensors=None • training=False 와 같이 오류가 생깁니다. 이런상황에서 predict에 사용할 test 데이터는 어떤식으로 처리하여 사용해야 정상적으로 동작할지 의견을 듣고 싶어서 질문드립니다.
2023년 1월 16일 17:31 #62919
김민관참가자오류내용을 잘못 기재했습니다. 실제 오류내용은 아래와 같습니다.
ValueError: Exception encountered when calling layer 'dense_features' (type DenseFeatures).
Feature (key: acousticness) cannot have rank 0. Given: Tensor("sequential/dense_features/Cast:0", shape=(), dtype=float32)
Call arguments received by layer 'dense_features' (type DenseFeatures): • features={'ID': 'tf.Tensor(shape=(), dtype=string)', 'danceability': 'tf.Tensor(shape=(), dtype=float32)', 'energy': 'tf.Tensor(shape=(), dtype=float32)', 'key': 'tf.Tensor(shape=(), dtype=int64)', 'loudness': 'tf.Tensor(shape=(), dtype=float32)', 'speechiness': 'tf.Tensor(shape=(), dtype=float32)', 'acousticness': 'tf.Tensor(shape=(), dtype=float32)', 'instrumentalness': 'tf.Tensor(shape=(), dtype=float32)', 'liveness': 'tf.Tensor(shape=(), dtype=float32)', 'valence': 'tf.Tensor(shape=(), dtype=float32)', 'tempo': 'tf.Tensor(shape=(), dtype=float32)', 'duration': 'tf.Tensor(shape=(), dtype=int64)'} • cols_to_output_tensors=None • training=False
-
글쓴이글
3 글 보임 - 1 에서 3 까지 (총 3 중에서)
- 답변은 로그인 후 가능합니다.