[AI ์คํฐ๋] Section 2 : ๋จธ์ ๋ฌ๋์ ํ์ํ ๊ธฐ๋ณธ ์ง์ ์ต๋
Python ๋ฌธ๋ฒ
Data type : 8๊ฐ๋ก ๊ตฌ์ฑ
→ ์ด๋๋ ๋ค ์๋ 4๊ฐ (์์ ๋ฐ์ดํฐ ํ์ ) : float, int, string, bool
→ ํ์ด์ฌ์๋ง ์๋ ๋ ํนํ ํ์ : list, tule, dictionary, set
- Numbers : float, int
- ๊ธฐ๋ณธ operation : +, *, /, **, %(๋ชจ๋๋ฌ, ๋๋จธ์ง), ()
- Strings
- ‘’, “” : ๋๊ฐ ์ค ํ๋๋ก ๋ฌถ์ด์ฃผ๋ฉด ๋จ ⇒ ๋ญ๋ ๋๊ฐ์ ⇒ ๋ฌธ์ฅ ์์ ‘’๊ฐ ๋ค์ด์์ผ๋ฉด “” ์ฌ์ฉ ๋ฑ์ผ๋ก ํ๋ฉด ๋จ
- ๋ฐ์ดํฐ ์ฌ๋ผ์ด์ฑ
- a[0], a[-1](๋ค ๋ถํฐ ์์)
- a[0:4] : [ํฌํจ:ํฌํจ์๋จ] ⇒ 0,1,2,3
- ๊ธธ์ด : len(a)⇒ a[len(a)] (x) a[len(a)-1] (o) ⇒ ์ธ๋ฑ์ค๋ 0๋ถํฐ ์์, ๊ธธ์ด๋ ๊ฐ์์ด๋ฏ๋ก ์ฃผ์
- Printing
- Place holder : {}, format()⇒ ex) print(“Num is: {}, and name is: {}”.format(a,b))
- ⇒ ex) print(“Num is: {one}, and name is: {two}”.format(one=a, two=b))
- Lists
- ๊ฐ์ฅ ์ค์ํ ํ์ด์ฌ ๋ฐ์ดํฐ ํ์
- ๋ค๋ฅธ ๋ญ๊ท์ง์ Array์๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ค๋ฆ : ๋ค๋ฅธ ๋ฐ์ดํฐ ํ์ ๋ค์ด ์์ฌ์์ ์ ์์
- ๋ณ์์ ๋ฆฌ์คํธ assign : a = [‘a’, 1, [1, 2]]
- ๋ฆฌ์คํธ์ ์๋ก์ด element ์ถ๊ฐ : append() ๋ฉ์๋ ⇒ a.append(‘d’)
- ์ฌ๋ผ์ด์ฑ : string ์ฌ๋ผ์ด์ฑ๊ณผ ๋์ผ → ์์์ ์ํด ์ธ๋ฑ์ค๋ก ๊ฐ์ ์ฐพ์ ⇒ a[2][0] = 1
- Dictionaries
- Key-value ์์ผ๋ก ๋์ด์์, ์ค๊ดํธ๋ก ํ์ : d = {‘k’:1, ‘k2’:2, ‘k3’:3}
- Key๋ก ๊ฐ์ ๋ฐ๋ก ์ฐพ์๊ฐ๊ฒ ๋์ด์์ : d[‘k3’] = 3
- Booleans
- True, False : ๋๋ฌธ์๋ก ์์ํด์ผํจ
- Tuples
- ๊ฐ์ ๋ฐ๊ฟ ์ ์๋ ๋ฆฌ์คํธ, ์๊ดํธ๋ก ํ์ : t = (1,2,3)
- ⇒ ๋ฆฌ์คํธ์ ์ฌ์ฉํ๋ ๋ฒ์ด ๊ฑฐ์ ๋น์ท
- t[0] = 1
- Sets
- ์งํฉ์ผ๋ก ์ํ์ ์งํฉ๊ณผ ๊ฐ์, ์ค๋ณต ์ ๊ฑฐ ์์ ๋ง์ด ์ฌ์ฉ๋จ
- ์ค๊ดํธ๋ก ํ์ : {1,2,3,2,3,3,3,3,1} ⇒ {1,2,3}
- (์์๊ฐ์๊ฐ ๋ง์๋ ์ค๋ณต ์ ๊ฑฐ๋จ)
Variable Assignment
: ๋ณ์ ์ด๋ฆ ์ค์
๋ณ์ ์ด๋ฆ ๊ท์น
- ์๋ฌธ, ์ซ์, _ ๋ฅผ ์ฌ์ฉํ๋ฉด ๋ญ๋ ์๊ด์์
- ์ซ์๋ก ์์ํ๋ฉด ์๋จ
๋ณ์ ์ด๋ฆ ๋ช ๋ช
- ๋ณ์ ์ด๋ฆ ์ ์ธํ๋ ๋ถ๋ถ์ด ์์ (๋์ ํ์ดํ๋๊ธฐ ๋๋ฌธ) ⇒ ํ์ , ๋ณ์์ ๊ธฐ์ต์ฅ์๊ฐ ๋ค์ด๋๋ฏนํ๊ฒ ์ ํด์ง
- ๋ณ์์ ๊ฐ ํ ๋น : a = 1
- ๋ค์ค ํ ๋น : a, b, c = 1,2,3
Comparison Operators
: >, <, ≥, ≤, ==
Logic Operators
: and, or
If, elif, else Statements
if x<2:
print("ok")
elif x==3:
print("middle")
else :
print("last")
For Loops
seq = ['a','b','c']
# ๊ธฐ๋ณธ ๋ฃจํ : ํ๋์ฉ ์ธ๋ฑ์ค์ ๋ฐ๋ผ ์ฒ๋ฆฌ
for i in seq:
print(i)
# enumerate : ์ธ๋ฑ์ค๋ ๊ฐ์ด ๋ฐํํ๊ฒ ๋จ
# [(0, 'a'), (1,'b'), (2, 'c')]
for i, ei in enumerate(seq):
print(i, ei)
While Loops
while i <5:
print(i)
i = i + 1
Range()
- For๋ฌธ ๋ฑ์ loop๋๋ฆด๋ ์ฌ์ฉ
- for i in range(1, 5): print(i)
- ๋ฐ์ดํฐ ์์ฑ
l = list(range(5))
List comprehension
[item**2 for item in x] # ๋ชจ๋ ์์ ์ ๊ณฑํ๋ ๊ฒ
Fuction
def test_func(x,y):
result = x*y+1
return result
test_func(10, 20) # 201
Lambda expression
: ์ต๋ช ํจ์ ⇒ ๊ฐ๋จํ ํ๋ฒ์ฐ๊ณ ๋ฒ๋ฆด ์ ์๋ ํจ์
(lambda x: x*10)(10) # 100
Map and filter
Map : ๋ฆฌ์คํธ์ ํจ์๋ค์ ํ๋์ฉ ๋งคํํด์ ์ ์ฉํด์ค๋ ์ฌ์ฉ
ํํฐ : ๋๋ค๊ฐ ๋ค์ ์๋ ๋ฆฌ์คํธ์ ์์ ํ๋์ฉ ์ ์ฉ๋๋ ํํ
list(map(times2, seq))
list(map(lambda x: x*2, seq)) # 2,4,6,8
list(filter(lambda x: x%2==0, seq)) #2,4
Methods
: class ์์ ์ ์ธ๋ ํจ์ ⇒ method์ ํจ์๋ ํ์ด์ฌ์์๋ ๋ฌธ๋ฒ์ ์ผ๋ก ์์ ํ ๋์ผ
Numpy
: ํจ์๋ค์ ๋ถ๋ฌ์ ์ฐ๋ ๋ชจ๋ ๊ฒ๋ค์ด ์ ๋ถ numpy๋ก ๋ง๋ค์ด์ ธ์๋ค
1. ์๊ฐ
(1) ๋์ฉ๋ ๋ฐ์ดํฐ ๋ฐฐ์ด(array)์ ํจ์จ์ ์ผ๋ก ๋ค๋ฃฐ ์ ์๊ฒ ์ค๊ณ
(2) ์ ํ๋์, ๋งคํธ๋ฆญ์ค(ํ๋ ฌ) ์ฐ์ฐ ๋ฑ ํจ์ ๋ด์ฅ
(3) ์๋๊ฐ ํ์ํ ์๊ณ ๋ฆฌ์ฆ์ c, c++๋ก ์์ฑ : ํ์ด์ฌ์ glue language
2. Numpy array
: ์ ๋ ฅ๋ฐ์ดํฐ ์ฌ์์ ๋ง์ถ์ด์ผํ๋ฏ๋ก, ๋ง๋ค์ด์ sklearn์ ๋ฃ์ด์ผํ๊ธฐ ๋๋ฌธ

- ์ฐจ์ : scalar, 1์ฐจ์ ⇒ ๋ฒกํฐ, 2์ฐจ์ ⇒ matrix, 3์ฐจ์ ⇒ tensor
- Shape: X, (2, ). (2,2) (2,2,2)
- dtype : ๋ฐ์ดํฐํ์
- ํ : axis = 0, ์ด : axis = 1, tensor์ ๋์ด : axis=2
3. Matrix์ numpyํํ
np.array([[8,5,3],[1,2,9]]) # 2์ฐจ์
np.array([[[1,2],[3,4]],[[5,6],[7,8]]]) # 3์ฐจ์
4. Join : Concatenate
- ํ๋จ์ : ๋ฐ์ผ๋ก ๋ถ์
- ์ด๋จ์ : ์์ผ๋ก ๋ถ์
5. Slicing
a = np.array([[1,2],[3,4]])
a[1:] # [[3,4],]
์ฝ๋ : ์ค์ต
ndarray
x= np.array([1,2,3])
x.shape # (3,)
# ๊ฐ์ด ๊ฐ์ฅ ํฐ ์ธ๋ฑ์ค
np.argmax(x) # 2 : 3์ ์ธ๋ฑ์ค 2 ์ถ๋ ฅ
x.argmax() # ๋์ผํ ๋ฌธ๋ฒ
Indexing / slice

⇒ arr[1, :2] : shape = vector
⇒ arr[1:2, :] : shape์ด ๋ฐ๋๋ ๊ฒ์, ๋ฐ์ดํฐ๋ ๋ฐ๋๋๊ฒ ์์ (matrix ํํ)
๋ฒกํฐ์ ๋ด์ (= ์ ๊ณฑ)
: ๋ฅ๋ฌ๋ ๋ด๋ถ์์ ํด์ฃผ๋ฏ๋ก ์ง์ ํ ํ์๋ ๊ฑฐ์ ์์
- ์๋ฆฌ
- ๋ ๋ฒกํฐ์ dimension์ด ๊ฐ์์ผํจ
- ๋ด์ ์ ๊ฐ ์์์ ๊ณฑ์ ๋ชจ๋ ๋ํ๊ฒ
- ์ฝ๋

np.dot(a,b.T) # 28
Matrix ๊ณฑ์ (ํ๋ ฌ ๊ณฑ์ , dot product)
- ์๋ฆฌ

- A ์ B์ ๊ณฑ์ ์, A์ ์ด ๊ฐ์ == B์ ํ ๊ฐ์ ์ฌ์ผํจ
- ๊ฒฐ๊ณผ ํ๋ ฌ์ shape : A์ ํ x B์ ์ด2
- ์ฝ๋
np.matmul(a,b)
์ ์น ํ๋ ฌ
: ํ, ์ด์ด ์๋ก ๋ฐ๋๋๊ฒ ⇒ ์ ๋ ฅ ์ฌ์๋ค์ ๋ง์ถ๋๋ฐ ๋ง์ด ์ฌ์ฉ๋จ
- ์ฝ๋
# ์
๋ค ๋๊ฐ์ ๊ฐ
a.T
np.transpose(a)
a.transpose()
*์ํ๋ shape๋ก ๋ฐ๊พธ๊ณ ์ถ๋ค๋ฉด
a.reshape(3,3) # 3,3 ์ผ๋ก ๋ฐ๋
Pandas
: series data type + dataframe data type๋ก ๊ตฌ์ฑ๋จ
์๊ฐ
1. Series (1์ฐจ์) : numpy array์ ์ ์ฌ
(1) ์ฐจ์ด์
- Series : axis์ label ๋ถ์ฌ ๊ฐ๋ฅ → label ๋ช ์ผ๋ก ์ธ๋ฑ์ฑ ๊ฐ๋ฅ
์ซ์ ์ด์ธ์ ๋ค๋ฅธ ๊ฒ๋ค๋ ์์๋ก ๊ฐ์ง ์ ์์
- numpy : ์ซ์๋ง ์์ด ๋ ์ด๋ธ ๋ถ์ฌ ๋ถ๊ฐ๋ฅ → ์ธ๋ฑ์ค๋ง์ผ๋ก ์ธ๋ฑ์ฑ
์ซ์๋ง ์์๋ก ๊ฐ์ง
2. Dataframe (2์ฐจ์, table) : ์ฌ๋ฌ๊ฐ์ series๋ฅผ ๊ฐ์ index๊ธฐ์ค์ผ๋ก ๋ชจ์ ํ ์ด๋ธ์ ๋ง๋ ๊ฒ
→ series ๋จ์๋ก ๊ด๋ฆฌ ๊ฐ๋ฅ

(1) ๊ตฌํ
# ๋ฐ์ดํฐ ์์ฑ -> ๋ฐ์ดํฐ ํ๋ ์์ผ๋ก ๋ณํ
data = np.random.randn(5,4) # ๋๋ค์ผ๋ก 5,4 ํ๋ ฌ ์์ฑ
df = pd.Dataframe(data) # column ์ด๋ฆ์ ์์๋ก 0 1 2 3...
# ๋ฐ์ดํฐ ๋ถ๋ฌ์ค๊ธฐ
df = pd.read_csv("ํ์ผ๋ช
.csv") # ์ฝค๋ง๋ก ๋ถ๋ฅ๋ ๊ฒฝ์ฐ๊ฐ default
df = pd.read_csv("ํ์ผ๋ช
.csv", sep=',')
# ์ปฌ๋ผ ์ด๋ฆ ์ง์
df = pd.DataFrame(data, columns=['W','X','Y','Z'])
# df์ ์ ๋ณด ํ์ธ
df.head(5) # 5๊ฐ์ ํ์ ๋ณผ ์ ์์
df.columns # ์ด ์ด๋ฆ ์ถ๋ ฅ
df.info() # df์ ์ ๋ณด ์ถ๋ ฅ : entry, column, non-null ๊ฐ์ ๋ฑ
df.describe() # ๋ฐ์ดํฐํ๋ ์์ ๊ธฐ์ ํต๊ณ ์ถ๋ ฅ : count, mean ๋ฑ
(2) ์ธ๋ฑ์ฑ
df['W'] # ์ด๋ณ๋ก ์ธ๋ฑ์ฑ -> series ์ถ๋ ฅ
df[['W', 'X', 'Y']] # dataframe์ด ์ถ๋ ฅ
(3) ์นผ๋ผ ์ถ๊ฐ / ์ญ์
df['new'] = df['X'] + df['Y'] # df์ new๋ผ๋ ์นผ๋ผ ์์ฑ : x, y ์ด ๋ํ๊ฒ
df.drop('new') # ์๋ฌ ๋ฐ์ : ๊ธฐ๋ณธ์ด axis = 0์ด๋ฏ๋ก ์ค๋ฅ
df.drop('new', axis=1) # ๋ฉ๋ชจ๋ฆฌ์ ๋ฐ๋๊ฑฐ๊ณ ์๋ณธ์ ์๋ฐ๋
# ์๋ณธ๋ ์
๋ฐ์ดํธ ํ๋ ค๋ฉด ์๋์ ๋ ๋ฐฉ๋ฒ ์ฌ์ฉ
df.drop('new', axis=1, inplace=True)
df = df.drop('new', axis=1)
(4) ๊ฒฐ์ธก์น ์ฒ๋ฆฌ
→ ์์ ํ ์ญ์ : dropna() / ์์์ ๊ฐ์ผ๋ก ๋์ฒด : fillna()
# ๊ฒฐ์ธก์น ํฌํจ๋ ๋ชจ๋ ํ ์ญ์
df.dropna()
# ๊ฒฐ์ธก์น ํฌํจ๋ ๋ชจ๋ ์ด ์ญ์
df.dropna(axis=1)
# ์์์๊ฐ์ผ๋ก ๋์ฒด
df.fillna(0) # 0์ผ๋ก ์ฑ์์ง
df.fillna(value=0)
df.fillna(df['X'].mean()) # X์ด์ ํ๊ท ๊ฐ์ผ๋ก ์ฑ์(nan์ ์ ์ธ๋๊ณ ํ๊ท ๊ณ์ฐ)
Matplotlib
์ฌ์ฉ ๋ฐฉ๋ฒ : 2๊ฐ์ง ์คํ์ผ
1. Functional programming style
import matplotlib.pyplot as plt
plt.plot(x,y)
2.OOP style
flg, ax = plt.subplots()
ax.plot(x,y)
ํํ

๊ธฐ๋ณธ ์ , ์
plt.plot(3,2,'o',c=r) # ์ ์ฐ๊ธฐ : x๊ฐ, y๊ฐ, ๋ชจ์, ์
plt.plot([1,2,3],[4,5,1]) # ์ ๊ธ๊ธฐ : x๊ฐ๋ค, y๊ฐ๋ค
๊ทธ๋ํ ๋ ๊ฐ ๊ทธ๋ฆฌ๊ธฐ

plt.title("์ ๋ชฉ") # ์ ๋ชฉ
plt.xlabel("x์ถ ์ด๋ฆ")
plt.ylabel("y์ถ ์ด๋ฆ")
Bar chart
plt.bar(x,y,label="์ด๋ฆ1") # ์ด๊ฒ๋ง ์ฐ๋ฉด ๋ง๋ 1๊ฐ, ์๋๋ ํ๋ฉด 2๊ฐ
plt.bar(x2,y2,label="์ด๋ฆ2")
plt.legend() # ๋ ์ด๋ธ ๋ฒ๋ก ๊ทธ๋ฆฌ๊ธฐ
Scatter plot : ์ฐ์ ๋
plt.scatter(x,y,label="์ด๋ฆ1") # ์ด๊ฒ๋ง ์ฐ๋ฉด ์ข
๋ฅ 1๊ฐ, ์๋๋ ํ๋ฉด ์ข
๋ฅ 2๊ฐ
plt.scatter(x2,y2,label="์ด๋ฆ2")
plt.legend()
Histogram
plt.hist(x) # array ๊ฐ๋ค์ด ํ์คํ ๊ทธ๋จ์ผ๋ก ํํ๋จ
# ์์ ์ ๋ณด๋ค ์์ ๊ณ ํ์คํ ๊ทธ๋จ ๊ทธ๋ํ๋ง ๋ณด์ด๊ฒ ํ๋ ์ธ๊ฐ์ง ๋ฐฉ๋ฒ
plt.show()
None
plt.hist(x);
# ๋ ์ด๋ธ๋ช
์ง์
plt.xlabel("random number")
plt.ylabel("frequency")
# ๊ฐ๊ฒฉ
plt.hist(x, bins=10)
OOP style
# ๊ทธ๋ฆผํ ์ ์ธ, ๋ํ์ง 2๊ฐ = row ๊ฐ์, ์ด ๊ฐ์, ๊ทธ๋ฆผ ์ฌ์ด์ฆ
fig, (ax1, ax2) = plt.subplots(1,2,figsize=(8,4))
# ์ฒซ๋ฒ์งธ ๊ทธ๋ํ : ์ผ์ชฝ
ax1.scatter(x,y,c='r',marker='o', edgecolor='k')
ax1.set_title("์ฒซ๋ฒ์งธ ๊ทธ๋ํ ์ ๋ชฉ")
ax1.set_xlabel("์ฒซ๋ฒ์งธ ๊ทธ๋ํ x์ถ ์ด๋ฆ")
ax1.set_ylabel("์ฒซ๋ฒ์งธ ๊ทธ๋ํ y์ถ ์ด๋ฆ")
# ๋๋ฒ์งธ ๊ทธ๋ํ : ์ค๋ฅธ์ชฝ
ax2.hist(data, bins=20)
ax2.set_title("๋๋ฒ์งธ ๊ทธ๋ํ ์ ๋ชฉ")
ax2.set_xlabel("๋๋ฒ์งธ ๊ทธ๋ํ x์ถ ์ด๋ฆ")
ax2.set_ylabel("๋๋ฒ์งธ ๊ทธ๋ํ y์ถ ์ด๋ฆ")
์ด๋ฏธ์ง : imshow
→ image data ์ฒ๋ผ ํ๋ ฌ ํํ์ 2์ฐจ์ ๋ฐ์ดํฐ๋ imshow๋ก ํ์
from sklearn.datasets import load_digits
x = load_digits()
img = x['images']
img = x['images'][0] # ํ์ฅ๋ง ๊ทธ๋ ค๋ณด๊ธฐ ์ํจ
plt.imshow(img, cmap='gray') # ํ๋ฐฑ์ผ๋ก ๊ทธ๋ ค์ง
plt.xticks([]) # ์์ ์ซ์ ์ญ์
plt.yticks([])
Feature scaling
: raw data๋ฅผ ์ ์ฒ๋ฆฌํ์ฌ input data์ ๊ตฌ๊ฐ์ ํ์คํ (ํฌ๊ธฐ๊ฐ ๋น์ทํ๊ฒ !)
→ ํฌ๊ธฐ๊ฐ ํต์ผ๋์ง ์๊ณ ์ ๋ถ ์ ์ฝ์ด ๋ค๋ฅธ ๊ฒฝ์ฐ, ๋จธ์ ๋ฌ๋์ ์ ๋ ฅ์ ์ฃผ๊ธฐ ์ ์ ์ฌ์ด์ฆ๋ฅผ ์ ๋ถ ๋ง์ถ๋ ์์ ์ด ํ์
⇒ ๋น์ทํ ํฌ๊ธฐ๋ก ๋ฐ๊พธ๊ธฐ : ๋น์ทํ ์์์ ๋จ์ ๋ฑ
→ ํน์ ํผ์ฒ์ value๊ฐ ๋ค๋ฅธ ํผ์ฒ๋ค ๋ณด๋ค ํจ์ฌ ํฌ๋ฉด ๊ทธ ๊ฐ์ด ๋ชฉ์ ํจ์๋ฅผ ์ง๋ฐฐํ๋ฏ๋ก ์ ํํ ํ์ต์ด ๋ถ๊ฐํจ
์ข ๋ฅ
1. Simple Scaling
: ์ด๋ค ํผ์ฒ์ ์ต๋๊ฐ์ ๊ฐ์ง๊ณ ์ผ๊ด์ ์ผ๋ก ๋๋ ์ค
→ ์ด๋ฏธ์ง ์ฒ๋ฆฌ์์ ๋ง์ด ์ฌ์ฉ : 255๋ก ๋๋๋ฉด ์๋์ ์ผ๋ก ์ ๋๊ธฐ ๋๋ฌธ
$$x_{new}= \frac{x_{old}}{X_{max}}$$
2. Standard Scaling (Z-score)
: ํ๊ท ๊ณผ ํ์คํธ์ฐจ๋ฅผ ์ด์ฉํด ์ค์ผ์ผ๋ง
→ ํ๊ท ์ 0์ผ๋ก ํ๊ณ 0์ฃผ๋ณ์ ๋ถ์ฐ๋ ์ข ๋ชจ์ ํํ๋ก ๋ณํ
$$ z = (x-\mu)/s $$
3. Min-max Scaling
: ์ด๋ค ๋ฐ์ดํฐ๊ฐ์์ ์ต์๊ฐ์ ๋นผ๊ณ , ๋ฐ์ดํฐ์ ๊ตฌ๊ฐ์ผ๋ก ๋๋ ๊ฐ์ผ๋ก ๋ณํ
→ ์ต์๊ฐ = 0 ~ ์ต๋๊ฐ = 1 ์ฌ์ด์ ๊ฐ๋ค๋ก ์ค์ผ์ผ๋ง ๋จ
→ x=min ⇒ 0, max ⇒ 1
$$ x_{new} = \frac{x_i-min(x)}{max(x)-min(x)} $$
from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import StandardScaler
# ์ฌํ ์ค์ผ์ผ๋ง
X_simple = X / X.max()
# min max
x_minmax = (x-x.min())/(x.max()-x.min())
sc = MinMaxScaler()
X_minmax2 = sc.fit_transform(X)
# fit : ์ต๋๊ฐ, ์ต์๊ฐ์ ๋ฏธ๋ฆฌ ๊ทธํด๋๋๊ฒ
# transform : ๊ตฌํํ ์ต๋ ์ต์๋ฅผ ์ด์ฉํด ๊ณต์์ ์ ์ฉํ๋ ๊ฒ
#Standard scaling
X_standard = (X - X.mean())/X.std()
sc = StandardScaler()
X_standard2 = sc.fit_transform(X)
์๊ฐํ
plt.figure(figsize=(14,4))
plt.subplot(1,4,1)
plt.hist(X, bins =50)
plt.title("original data")
plt.subplot(1,4,2)
plt.hist(X_simple, bins =50)
plt.title("simple data")
plt.subplot(1,4,3)
plt.hist(X_minmax, bins =50)
plt.title("minmax data")
plt.subplot(1,4,4)
plt.hist(X_standard, bins =50)
plt.title("standard data")
# ๋ถํฌ๋ ๋ฐ๋์ง ์์ผ๋ ๋ฒ์๋ง ๋ฐ๋