일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- YOLOv5
- react native
- STT
- 졸프
- C++
- javascript
- Loss Function
- @Transactional
- 커스텀 데이터 학습
- Spring
- 순환참조
- matplotlib
- skt fellowship 3기
- oauth
- google cloud
- google login
- 2021 제9회 문화공공데이터 활용경진대회
- 양방향 매핑
- idToken
- Spring Boot
- pandas
- google 로그인
- 코드업
- JPA
- html
- OG tag
- yolo
- AWS
- Expo
- marksense.ai
- Today
- Total
민팽로그
9월 30일 언어 지능 실습 본문
실습 내용
- 전 시간 실습 리뷰: 한글 데이터를 토큰으로 분리하여 train 데이터셋 만들기, 정수 인코딩
- sklearn : train, test split, 전처리한 train과 test로 분리
- 학습 진행 : vocab size, sequence 길이 조절
sklearn을 사용하여 train과 test로 분리
from sklearn.model_selection import train_test_split
#sklearn를 사용하여 train과 test 분리
x = [0,1,2,3,4,5,6,7,8,9,10]
y = [0,1,2,3,4,5,6,7,8,9,10]
x_train, x_test , y_train , y_test = train_test_split(x,y,test_size = 0.2)
- x, y : 각각 input 데이터와 ouput 데이터 리스트(train 데이터, label 데이터)
- test_size : train과 test의 비율을 0.8 : 0.2 로 하여 분리
-> 리스트 타입으로 반환됨
https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html
sklearn.model_selection.train_test_split
Examples using sklearn.model_selection.train_test_split: Release Highlights for scikit-learn 0.23 Release Highlights for scikit-learn 0.23, Release Highlights for scikit-learn 0.24 Release Highligh...
scikit-learn.org
핵심 코드
from sklearn.model_selection import train_test_split
from keras.preprocessing import sequence
from keras import layers, models
import numpy as np
# 3-1: sklearn를 사용하여 train과 test 분리
x_train, x_test , y_train , y_test = train_test_split(train,label,test_size = 0.2)
#자료형 변환(없어도 실행되나 확인)
y_train = np.array(y_train, dtype=list)
y_train = y_train.astype('int32')
y_test = np.array(y_test, dtype=list)
y_test = y_test.astype('int32')
max_features=20000
maxlen=80
# 3-2: 학습 진행
x_train = sequence.pad_sequences(x_train, maxlen=maxlen)
x_test = sequence.pad_sequences(x_test, maxlen=maxlen)
x = layers.Input((maxlen,))
h = layers.Embedding(max_features, 128)(x)
h = layers.SimpleRNN(128)(h)
y = layers.Dense(1, activation='sigmoid')(h)
model = models.Model(x, y)
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
batch_Size=32
epochs=10
model.fit(x_train, y_train,
batch_size=batch_Size,
epochs=epochs,
validation_data=(x_test, y_test))
- sequence.pad_sequences : input 데이터의 길이를 동일하게 만들어주기 위해 사용. 길이가 maxlen보다 길다면 자르고, maxlen보다 짧다면 공백으로 채움.
-> 감정 분석 모델을 만들어야 하므로 좋은 감정은 1, 나쁜 감정은 0인 2진 분류가 필요하여 손실 함수로는 binary_crossentropy, 출력함수의 활성화 함수로는 sigmoid를 사용하기에 적합함.
코랩 실습 파일
-> 전 시간 실습 피드백 코드 + 이번 시간 실습 코드
'머신러닝&딥러닝' 카테고리의 다른 글
10월 1일 언어 지능 실습 (0) | 2021.10.02 |
---|---|
optimizer (0) | 2021.10.01 |
9월 29일 언어 지능 실습 (0) | 2021.09.29 |
9월 28일 언어 지능 실습 정리 (0) | 2021.09.28 |
Recurrent Neural Network(RNN) (0) | 2021.09.28 |