반응형

DeepLearining 15

Label Encoding and One Hot Encoding

숫자가 아닌 단어나 글자를, 숫자로 바꿔줘야 딥러닝이 학습할 수 있다. 이럴때, 글자를 숫자로 바꿔주는 것을 Label Encoding 이다. 예를들어, 데이터셋에서 어떤 컬럼이 국가명으로 되어있다고 하자. ... country name (컬럼명) ... KR ... US ... UK ... CN 위의 국가 코드를 숫자로 바꿔주기 위해서는 다음과 같이 한다. 12345678from sklearn.preprocessing import LabelEncoder # encode class values as integersencoder = LabelEncoder()encoder.fit(Y)encoded_Y = encoder.transform(Y) 그러면, KR => 0, US => 1, UK => 2, CN =>..

DeepLearining 2017.10.29

딥러닝의 모델 성능 평가2 - manual 로 varification dataset 만들기

train_test_split 함수를 이용해서, training dataset 과 test dataset 을 나누어 줄 수 있다. 이때, 꼭 scikit-learn 라이브러리를 임포트 하는것을 잊으면 안된다. from sklearn.model_selection import train_test_split 마지막으로, Sequential 클래스의 fit 함수의 파라미터인, validation_data 에 test dataset 의 data와 label 값을 설정해 주면 된다.validation_data=(X_test,y_test) 12345678910111213# Splitting the dataset into the Training set and Test setfrom sklearn.model_select..

DeepLearining 2017.10.29

딥러닝의 모델 성능 평가 1 - Keras의 validation_split 이용하는 방법

Sequential 클래스의 fit 함수를 보면, 파라미터로 validation_split 이 있다. 여기에 원래 주어진 데이터셋을 얼마의 비율로 나워서 트레이닝 데이터셋과 테스트 데이터셋으로 사용할 지 결정할 수 있다. 예를 들면, 원래 데이터셋이 1000개 이고, fit 함수의 validation_split = 0.2 로 하면, training dataset 은 800개로 하여, training 시키고, 나머지 200개는 test dataset 으로 사용하여, 모델을 평가하게 된다. 123456789# create modelclassifier = Sequential()classifier.add(Dense(100, input_dim=8, activation='relu'))classifier.add(De..

DeepLearining 2017.10.29

모델을 fit 한 후, accuracy 와 epoch 를 그래프로 나타내는 Keras Python Code

모델을 fit 한 결과를 그래프로 보여주고자 할 때. x축을 epoch, y축을 accuracy 또는 loss 로 나타내는 코드. 12345678910111213141516171819202122import matplotlib.pyplot as plt # Fit the modelresults = model.fit(X, Y, validation_split=0.33, epochs=150, batch_size=10, verbose=0)# list all data in historyprint(results.history.keys())# summarize history for accuracyplt.plot(results.history['acc'])plt.plot(results.history['val_acc'])pl..

DeepLearining 2017.10.29
반응형