The Graphs of Odds and Logit¶
In [12]:
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
plt.style.use('_classic_test_patch')
p_np = np.linspace(0.01, 0.99, 100)
p_tf = tf.linspace(0.01, 0.99, 100)
# 오즈 계산
odds_np = p_np/(1 - p_np)
odds_tf = p_tf/(1 - p_tf)
# 로짓
logit_np = np.log(odds_np)
logit_tf = tf.math.log(odds_tf)
fig, axes = plt.subplots(2, 1, figsize=(15, 10),
sharex=True)
axes[0].plot(p_np, odds_tf.numpy())
axes[1].plot(p_np, logit_tf.numpy())
xticks = np.arange(0, 1.1, 0.1)
axes[0].tick_params(labelsize=15)
axes[0].set_xticks(xticks)
axes[0].set_ylabel('Odds', fontsize=20, color='darkblue')
axes[1].tick_params(labelsize=15)
axes[1].set_xticks(xticks)
axes[1].set_ylabel('Logit', fontsize=20, color='darkblue')
axes[1].set_xlabel('Probability', fontsize=20, color='darkblue')
Out[12]:
Text(0.5, 0, 'Probability')
The Graphs of Sigmoid¶
In [13]:
import tensorflow as tf
from tensorflow.keras.layers import Activation
X = tf.linspace(-30, 30, 100)
sigmoid = Activation("sigmoid")(X)
fig, ax = plt.subplots(figsize=(10, 5))
ax.plot(X.numpy(), sigmoid.numpy())
Out[13]:
[<matplotlib.lines.Line2D at 0x1274274e690>]
Single-variate Logistic Regression Models¶
In [19]:
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.keras.layers import Dense
plt.style.use("_classic_test_patch")
X = tf.random.normal(shape=(100, 1))
dense = Dense(units=1, activation="sigmoid")
Y = dense(X)
print(Y.shape)
fig, ax = plt.subplots(figsize=(7, 7))
ax.scatter(X.numpy().flatten(), Y.numpy().flatten())
(100, 1)
Out[19]:
<matplotlib.collections.PathCollection at 0x127420838f0>
Multi-variate Logistic Regression Models¶
In [21]:
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.keras.layers import Dense
plt.style.use("_classic_test_patch")
X = tf.random.normal(shape=(100, 5))
dense = Dense(units=1, activation="sigmoid")
Y = dense(X)
print(Y.shape)
(100, 1)
Binary Classifier with Dense Layers¶
In [22]:
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
model = Sequential()
model.add(Dense(units=10, activation="relu"))
model.add(Dense(units=5, activation="relu"))
model.add(Dense(units=1, activation="sigmoid"))
In [ ]:
'Deep Learning > Deep learning Bacis Mathematics' 카테고리의 다른 글
| 3-3 Softmax 구현 (0) | 2024.03.29 |
|---|---|
| 3-1 Sigmoid & Softmax 이론 (0) | 2024.03.29 |
| 2-4 Model Implementation with Dense layer 구현 (0) | 2024.03.28 |
| 2-3 Cascaded_Dense_Layers 구현 (0) | 2024.03.28 |
| 2-2 Dense Layer 구현 (0) | 2024.03.28 |
