๐Ÿ Python

[Python]๋”ฅ๋Ÿฌ๋‹ ์˜ˆ์ œ์‹ค์Šต

๋‰ด์ด NUEY 2024. 5. 22. 01:13
๋ฐ˜์‘ํ˜•

 

์ด์ง„ ๋ถ„๋ฅ˜๋ž€?
๊ฒฐ๊ณผ๊ฐ’์ด ์ ํžŒ data๋ฅผ ํ•™์Šตํ•œ ํ›„
์ž…๋ ฅ๋œ ๋ฐ์ดํ„ฐ๊ฐ€ ์–ด๋–ค group์— ์†ํ•˜๋Š” ์ง€ ์ฐพ์•„๋‚ด๋Š” ๋ฐฉ๋ฒ•
ํŠนํžˆ ๋‘˜ ์ค‘ ํ•˜๋‚˜๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ๊ฑธ ์ด์ง„ ๋ถ„๋ฅ˜๋ผ๊ณ  ํ•œ๋‹ค.
ex)์ŠคํŒธ๋ฉ”์ผ์ธ๊ฐ€ ์•„๋‹Œ๊ฐ€

 

ํ•„์š”ํ•œ Library

  • numpy : data ์ƒ์„ฑํ•  ๋•Œ ํ•„์š”(๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜)
  • tensorflow : google์—์„œ ์ œ๊ณต
    โ—‹ keras : model์„ ๊ตฌ์„ฑํ•˜๋Š”๋ฐ ํ•„์š”
  • matplotlib : ๊ทธ๋ž˜ํ”„๋ฅผ ๋งŒ๋“œ๋Š”๋ฐ ํ•„์š”
import numpy as np
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras import optimizers

%matplotlib inline
import matplotlib.pyplot as plt

x = np.array( [-20, -10, -5, 0, 5, 10, 20, 25, 30] )
y = np.array( [0, 0, 0, 0, 0, 0, 1, 1, 1] )

model=Sequential()
model.add(Dense(1, input_dim=1, activation='sigmoid'))

sgd=optimizers.SGD(lr=0.01)
model.compile(optimizer=sgd, loss='binary_crossentropy', metrics=['binary_accuracy'])

model.fit(x, y, batch_size=1, epochs=300, shuffle=False)

plt.plot(x, model.predict(x), 'b', x, y, 'k.')

print(model.predict([1, 23, 50]))

 

 

๋ฐ˜์‘ํ˜•