#Input Tensor 선언
input = torch.ones(5, 3) # seq_size, input_dim
# input = torch.ones(11, 5, 3) # batch_size, seq-size, input_dim
RNN Layer 정의
# RNN Layer 선언
rnn_layer = nn.RNN (input_size=3, hidden_size=10)
Output shape
# output 출력
output, hidden = rnn_layer(input0
print(output.shape)
print(hidden.shape)
웹 크롤링
code = '005930' # 삼성전자 종목코드
url = ' 어쩌고 '
header ' = { 'User-agent ' : 'Mozilla/5.0' }
req = requests.get(url, headers = header)
html = BeautifulSoup(req.text, "lxml")
# df 전처리
df.dropna( inplace = True)
# 컬럼명 변경
df.columns = ['Date', 'Close', 'Gap', 'Open']
# 불필요 컬럼 제거
df.drop(['Gap'], axis = 1, inplace = True)
#시간순 정렬
df.sort_values(['Date'], inplace = True)
# train / test 분리 (train 만 이용해서 학습 및 추론하고 test는 모델에 input이기에 사용하지 않는다. (미래값)
train_df = df.loc[df.Date < '2024.04.03] #여기까지만 사용
test_df = df.loc[df.Date >= '2024.04.03] #모델 학습이 끝난 뒤에 성능 평가용으로
train_df.drop(['Date'], axis=1, inplace=True)
#scaling
scaler = StandardScaler()
scaler.fit(train_df)
#Define the window sizes
input_window = 30
output_windo = 5
#Create the dataset
data = torch.tensor(s_train_df, dtype = torch.float32)
target = torch.tensor(s_train_df.T[0], dtype= torch.float32)
print(dataset[0][0].shape)
print(dataset[0][1].shape)