일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- slideshare
- tab
- computer
- text
- cs231n
- Ai
- computer_setting
- gensim
- machinelearning
- error
- pip
- terminal
- cs224n
- github
- git
- deeplearning
- Statistics
- seq2seq
- language_model
- linux
- install
- nlp
- json
- paper_review
- Standford
- review
- Stanford
- code
- natural_language_processing
- Vim
- Today
- Total
NLP/AI/Statistics
AI model test case 본문
x_train, x_test, y_train, y_test = train_test_split(x,y, test_size=0.2)
[ML]
model = DecisionTreeRegression()
model.fit(x_train, y_train)
pred = model.predict(x_test)
score = model.score(x_test, y_test)
[DL]
import tensorflow as tf
from tesnsorflow import keras
from tensorflow.keras import layers
from keras.callbacks import ModelCheckpoint, EarlyStopping
def build_model():
model = keras.Sequential([
layers.Dense(64, activatoin = 'relu', input_shape=[len(x_train.keys())]),
layers.Dense(64, activation = 'relu'),
layers.Dense(1)
])
model.compile(loss='mse', optimizer = 'adam', metrics=['mae','mse'])
return model
model = build_model()
model.summary()
history = model.fit(x_train, y_train, epochs=30,
validation_data = (x_test, y_test),
callbacks = [cb_checkpoint, early_stopping])
result = model.evaluate(x_test, y_test)
print(result)
plt.style.use("ggplot")
plt.figure()
plt.plot(np.arange(0, 30), history.history["loss"], label="train_loss")
plt.plot(np.arange(0, 30), history.history["val_loss"], label="val_loss")
plt.title("Training Loss")
plt.xlabel("Epoch #")
plt.ylabel("Loss")
plt.legend()
plt.show()
# 최적 모델 불러오기 및 저장
model.load_weights(checkpoint_path)
model.save("DeeplearningModel.h5")
'NLP' 카테고리의 다른 글
Attention Mechanism (0) | 2020.12.08 |
---|---|
Sequence to Sequence (0) | 2020.12.08 |
순환신경망: LSTM(Long Short Term Memory) (0) | 2020.11.25 |
순환신경망: RNN(Recurrent Neural Network) (0) | 2020.11.16 |
문서 유사도: 코사인 유사도, 자카드 유사도, 유클리드 거리 (0) | 2020.10.19 |