[딥러닝 Express] Chapter 05. 퍼셉트론 - [Mini Project: 퍼셉트론으로 분류]

배규리·2024년 1월 7일

AI 기초

목록 보기
9/32
post-thumbnail

Q. 문제

대학생들의 신장과 체중을 받아서 성별을 출력하는 퍼셉트론을 만들어보자.
즉 입력과 출력은 다음과 같다.

  • x1: 학생의 신자
  • x2: 학생의 체중
  • y: 성별(남자/여자)

A. 정답

from sklearn.linear_model import Perceptron
import numpy as np
from matplotlib import pyplot as plt

x = np.array([[160,55],
     [163,43],
     [165,48],
     [170,80],
     [175,76],
     [180,70]])
y = np.array([1,1,1,0,0,0]) 

# 모델 생성 및 학습
clf = Perceptron(tol=1e-2, random_state = 0)
clf.fit(x, y)

# 실제 데이터는 점으로 표시
plt.scatter(x[:,0],x[:,1])

# 예측한 값 출력
prediction = clf.predict(x[:])
print(prediction)

# 내 몸무게랑 키 입력해서 예측값 출력
prediction_me = clf.predict([[162,53]])
print(prediction_me)

prediction_s = clf.predict([[175,69]])
print(prediction_s)
plt.show()


나를 여자로 분류해줬다~
퍼셉트론 땡큐요~><~🥹👍❤️

profile
백엔드 개발은 취미인 AI 개발자🥹

0개의 댓글