• 카테고리

    질문 & 답변
  • 세부 분야

    딥러닝 · 머신러닝

  • 해결 여부

    미해결

더미처리 후 model.fit() 에서 오류가 납니다.

22.07.03 07:55 작성 조회수 470

0

# 범주형 데이터의 카테고리 
df_out['weather_code'] = df_out['weather_code'].astype('category') 
df_out['season'] = df_out['season'].astype('category') 
df_out['year'] = df_out['year'].astype('category') 
df_out['month'] = df_out['month'].astype('category') 
df_out['hour'] = df_out['hour'].astype('category') 
df_out['dayofweek'] = df_out['dayofweek'].astype('category') # dayofweek 추가됨 


# 더미처리 
df_out = pd.get_dummies(df_out, columns=['weather_code','season','year','month','hour','dayofweek']) # dayofweek 추가됨 

# 종속변수 'cnt', 독립변수('나머지 컬럼')을 분리하는 작업 
df_y = df_out['cnt'] # 종속변수 Y 
df_x = df_out.drop(['timestamp', 'cnt'], axis = 1) # 독립변수 X 

# 훈련용, 테스트용 데이터 분리 
from sklearn.model_selection import train_test_split 
x_train, x_test, y_train, y_test = train_test_split(df_x, df_y, random_state=66, test_size=0.3, shuffle=False) # 매번 동일한 래덤값을 고정하여 값 변경되지 않게, shuffle=False는 시계열 데이터 이므로 

## .... 이후 

model.compile(loss='mae', optimizer='adam', metrics=['mae']) 
early_stopping = EarlyStopping(monitor='loss', patience=5, mode='min') 
history = model.fit(x=x_train, y=y_train, epochs=50, batch_size=1, validation_split=0.1, callbacks=[early_stopping])

 

train 데이터 오류로 인해 딥러닝이 되지 않습니다. 

선생님 강좌와 차이점은 dayofweek을 추가한 내용입니다. 

왜? dayofweek을 카테고리 & 더미 처리를 하면 딥러닝이 되지 않는지? 궁금합니다.

답변 1

답변을 작성해보세요.

0

김지현님의 프로필

김지현

2023.05.21

model.add(Dense(units=160, activation='relu', input_dim=52))
이 코드에서 input_dim 에 입력한 값이 df_out.shape 을 봤을 때 열의 값과 동일한지 한번 체크해보세요!