• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Python, SQL 게시판 딥러닝에서 test.csv를 예측하는 방법 질문입니다.

딥러닝에서 test.csv를 예측하는 방법 질문입니다.

3 글 보임 - 1 에서 3 까지 (총 3 중에서)
  • 글쓴이
  • #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 데이터는 어떤식으로 처리하여 사용해야 정상적으로 동작할지 의견을 듣고 싶어서 질문드립니다.
    #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
    #63051

    codingapple
    키 마스터
    acousticness 컬럼에 뭔가 이상한값이 있나 확인해봅시다
3 글 보임 - 1 에서 3 까지 (총 3 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관, 개인정보처리방침
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠