Tensorflow 101 - classification

decal·2022년 12월 21일
0

study notes

목록 보기
2/12

I didn't watch much today, but I learned how to fit and predict models that contains non-numerical data in dependent variables.

One new thing that I found out before I dig in:
(Okay, assuming that I've already imported tensorflow and pandas,)
in the data section, let's compare the following two codes:

  • What I did yesterday:
파일경로 = 'https://raw.githubusercontent.com/blackdew/tensorflow1/master/csv/iris.csv'
아이리스 = pd.read_csv(파일경로)
아이리스.head()
  • What I did today:
아이리스 = pd.read_csv('https://raw.githubusercontent.com/blackdew/tensorflow1/master/csv/iris.csv')
아이리스.head()

-> I reduced two lines into one line. Why bother separating!

data

아이리스 = pd.read_csv(’iris.csv’)
아이리스.head()

Onehot-encoding (used to switch categorical data into numerical data)

엔코딩 = pd.get_dummies(아이리스)
엔코딩.head()
print(엔코딩.columns)
독립 = 아이리스[['꽃잎길이', '꽃잎폭', '꽃받침길이', '꽃받침폭']]
종속 = 아이리스[['품종']]
print(독립.shape, 종속.shape)

model

X = tf.keras.layers.Input(shape=[4])
Y = tf.keras.layers.Dense(3, activation='softmax')(X)
model = tf.keras.models.Model(X, Y)
model.compile(loss='categorical_crossentropy',
              metrics='accuracy')

fit

model.fit(독립, 종속, epochs=100, verbose=0)
model.fit(독립, 종속, epochs=10)

predict

  • predict the first five
model.predict(독립[0:5])
  • print answer
print(종속[0:5])
  • predict the last five
model.predict(독립[-5:])
  • print answer
print(종속[-5:])

weight

model.get_weights()

0개의 댓글