본문 바로가기

Study/ML3

[ML] 혼동 행렬(Confusion matrix) 직접 구현하기 본 포스트에서는 confusion matrix를 matplotlib.pyplot 라이브러리를 사용하여 직접 구현해 볼 것입니다.seaborn 라이브러리를 사용하면 훨씬 쉽고 빠르게 구현할 수 있지만, 내부 원리를 정확히 공부하기 위해 seaborn은 사용하지 않겠습니다.  라이브러리 가져오기from sklearn.metrics import confusion_matrix # confusion matrix 계산from sklearn.metrics import accuracy_score # accuracy 계산from sklearn.metrics import classification_report # 각 성능지표에 대한 분류 보고서 출력 confusion matrix의 출력 방식을 확인해보기 위해 먼저 .. 2024. 3. 26.
[ML] 로지스틱 회귀(Logistic Regression) 직접 구현하기 본 포스트에서는 Tensorflow에서 로지스틱 회귀를 구현해볼 것입니다. 먼저 필요한 라이브러리들을 가져옵니다. 라이브러리 가져오기import tensorflow as tfimport numpy as npimport matplotlib.pyplot as plt 훈련 데이터 생성x_train = np.array([[1., 1.], [1., 2.], [2., 1.], [3., 2.], [3., 3.], [2., 3.]], dtype=np.float32)y_train = np.array([[0.], .. 2024. 3. 25.
[ML] 선형 회귀(Linear Regression) 직접 구현하기 본 포스트에서는 Simple linear regression과 Non-linear regression을 tensorflow를 이용하여 구현해 볼 것입니다. 먼저 tensorflow와 numpy 라이브러리를 가져오도록 합니다. 라이브러리 가져오기import tensorflow as tfimport numpy as np# 버전 확인 (1.xx 버전일 경우 속도는 빠르지만 더 복잡하고 어려움)print(tf.__version__) Simple Linear Regressiony = ax + b 형태의 모델을 구현해 볼 것입니다. 데이터 생성X = [1,2,3,4,5] # 입력 데이터Y = [1,2,3,4,5] # 결과 데이터 먼저 모델에 들어가게 될 데이터 X와 Y를 생성해줍니다. 가설 정의W = tf.Vari.. 2024. 3. 25.