Hello. I'm DVM who talk about tensorflow certification
Today, I will explain the basic Concept about Multinomial classification.
If you haven't seen the previous lecture,
I recommend that watch the previous lecture.
First. What is the Multinomial Classification
Wikipedia said that
Multinomial classification is the problem of classifying instances into one of three or more classes.
Second. How to make Multinomial Classification.
The softmax function is used for multinomial classification.
The softmax function converts the scores to probabilities
Third. What is the one-hot encoding
one-hot encoding is choosing the max value and represent as 1.
So It is possible to learn the id of the thing classified.
Fourth. .Binary Versus Multinomial classification
Genarally,
Binary classification use sigmoid as hypothesis function and binary cross entropy as cost function
However,
Multinomial classification use softmax as hypothesis function and cross entropy as cost function
The main difference is that binary classification uses sigmoid and multinomial classification use softmax as hypothesis function or output layer in deep learning.
FIfth. Practice using tensorflow,
Let's make multinomial classification¶
In [0]:
import tensorflow as tf
Let's make an train data¶
In [0]:
x_data = [[0,0,0],[1,1,1],[2,2,2],[3,3,3],[4,4,4],[5,5,5],[6,6,6],[7,7,7]]
y_data = [[0,0,1],[0,0,1],[0,0,1],[0,1,0],[0,1,0],[0,1,0],[1,0,0],[1,0,0]]
Let's make a node¶
In [0]:
X = tf.placeholder("float",[None,3]) # 3 dimension
Y = tf.placeholder("float",[None,3]) # 3 dimension
Let's make a hyper parameter such as weight and bias¶
In [0]:
multiclass =3
w = tf.Variable(tf.random_normal([3,multiclass]),name="weight")
b = tf.Variable(tf.random_normal([multiclass]),name="bias")
Let's make a cost function of cross entropy for multinomial classification¶
In [0]:
hypothesis = tf.nn.softmax(tf.matmul(X,w)+b)
cost = tf.reduce_mean(-tf.reduce_sum(Y*tf.log(hypothesis),axis=1))
Let's make a train method of gradient descent opimizer¶
In [0]:
optimizer=tf.train.GradientDescentOptimizer(learning_rate=0.001).minimize(cost)
Let's launch the graph using tf.seesion() and optimize hyper parameter¶
In [86]:
sess = tf.Session()
sess.run(tf.global_variables_initializer())
for step in range(10000):
sess.run(optimizer,feed_dict = {X:x_data,Y:y_data})
if step%100 ==0:
print(step, sess.run(cost,feed_dict={X:x_data,Y:y_data}))
Let's see the accuracy using test data¶
In [87]:
answer = sess.run(hypothesis,feed_dict={X:test_x})
print(answer)
Let's using the arg_max which express max value as 1¶
In [88]:
t_predict = sess.run(tf.arg_max(answer,1))
t_answer = sess.run(tf.arg_max(test_y,1))
print(t_predict)
print(t_answer)
Let's calculate the accuracy¶
In [89]:
accuracy=tf.reduce_mean(tf.cast(tf.equal(t_predict,t_answer),dtype=tf.float32))
print(sess.run(accuracy*100),"%")
Let`s make Multinomial Classification
sixth. Exam.
Let's solve the problem and if wrong,
please watch this video again from the beginnig untill get 100 points.
First. What is the Multinomial Classification
Multinomial classification is the problem of classifying instances into one of three or more classes.
Second. The softmax function converts the probabilities to scores
The softmax function converts the scores to probabilities
Third. What is called the largest value of probability as 1 and the rest as 0
one hot encoding
Fourth, Multinomial Classification used to sigmoid hypothesis function
Multinomial Classificaiton used to softmax hypothesis function.
No comments:
Post a Comment