Study_note(zb_data)/Machine Learning
์คํฐ๋๋ ธํธ (ML_Math function)
KloudHyun
2023. 9. 26. 12:23
๐๋คํญํจ์์ ํํ์ด๋ ๊ทธ๋ํ ๊ทธ๋ ค๋ณด๊ธฐ
- ๋คํญํจ์? f(x) = ax^y + b
# ํํ์ด๋
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-3, 2, 100)
y1 = 3 * x ** 2 + 2
y2 = 3 * (x+1) ** 2 + 2
plt.figure(figsize=(12, 8));
plt.plot(x, y1, ls='dashed', label='$y=3x^2+2$')
plt.plot(x, y2, label='$y=3(x+1)^2+2$')
plt.legend(fontsize=15)
plt.grid()
plt.xlabel('$x$', fontsize=25)
plt.ylabel('$y$', fontsize=25)
plt.show()
๐์ง์ ํจ์
- f(x) = a^x
- subplots์ ํ์ฉํ์ฌ ํ ๊ทธ๋ฆผ์ 2๊ฐ์ ๊ทธ๋ํ๋ฅผ ๊ทธ๋ ค๋ณด์.
# ์ง์ ํจ์
fig, ax = plt.subplots(1, 2, figsize=(12, 8))
ax[0].plot(x,y11,color='k', label='$2^x$')
ax[0].plot(x,y12, '--' ,color='k', label='$3^x$')
ax[0].plot(x,y13, ':' ,color='k', label='$4^x$')
ax[0].legend(fontsize=15)
ax[1].plot(x,y21,color='k', label='$1/2^x$')
ax[1].plot(x,y22, '--' ,color='k', label='$1/3^x$')
ax[1].plot(x,y23, ':' ,color='k', label='$1/4^x$')
ax[1].legend(fontsize=15)
plt.show()
๐์์ฐ ์์ e
- (1 + 1/x)**x
- ์ด๋ ํ ํฐ ๊ฐ์ ๋ฃ์ด๋ 2.7182…๋ก ์๋ ดํ๋ค.
x = np.array([10, 100, 1000, 10000, 100000, 1000000])
(1 + 1/x)**x
>>>>
array([2.59374246, 2.70481383, 2.71692393, 2.71814593, 2.71826824, 2.71828047])
๐์์ฐ ์์ e๋ฅผ ์ด์ฉํ ๋ก๊ทธ ํจ์
def log(x, base):
return np.log(x)/np.log(base)
x1 = np.linspace(0.0001, 5, 1000)
x2 = np.linspace(0.01, 5, 100)
y11, y12 = log(x1, 10), log(x2, np.e)
y21, y22 = log(x1, 1/10), log(x2, 1/np.e)
fig, ax = plt.subplots(1, 2, figsize=(12, 8))
ax[0].plot(x1, y11, label="$\log_{10} x$", color='k')
ax[0].plot(x2, y12, '--' ,label="$\log_{e} x$", color='k')
ax[0].set_xlabel('$x$', fontsize=25)
ax[0].set_ylabel('$y$', fontsize=25)
ax[0].legend(fontsize=20, loc='lower right')
ax[1].plot(x1, y21, label="$\log_{1/10} x$", color='k')
ax[1].plot(x2, y22, '--' ,label="$\log_{1/e} x$", color='k')
ax[1].set_xlabel('$x$', fontsize=25)
ax[1].set_ylabel('$y$', fontsize=25)
ax[1].legend(fontsize=20, loc='upper right')
plt.show()
๐ ์๊ทธ๋ชจ์ด๋
- 0๊ณผ 1์ฌ์ด์ ๊ฐ์ ๊ฐ์ง๋ค (์ ๊ทน๋จ์ ์๋ ดํ๋ฉฐ ์ ๋ ๋์ด๊ฐ์ง ์๋๋ค)
z = np.linspace(-10, 10, 100)
sigma = 1/(1+np.exp(-z))
plt.figure(figsize=(12, 8))
plt.plot(z, sigma)
plt.xlabel('$z$', fontsize=25)
plt.ylabel('$\sigma(z)$', fontsize=25)
plt.show()