Machine Learning
-
지도학습 | Ordinary Least Squares (최소제곱법)Machine Learning/ML with Python Library 2024. 3. 25. 20:31
Linear Regression 또는 Ordinary Least Squares(OLS, 최소제곱법)은 가장 간단하면서도 오래된 Regression Linear Algorithm이라고 한다. Linear Regression은 prediction과 training set target들의 평균제곱오차(Mean Squared Error)를 최소화하는 파라미터 w와 b를 찾는다. 여기서, 평균 제곱오차는 prediction과 target값의 차이를 제곱하고 더한 후에 샘플 개수로 나눈것이다. mglearn의 데이터 샘플을 이용해서 LinearRegression 모델을 만들어보자. from sklearn.linear_model import LinearRegression from sklearn.model_selec..
-
지도학습 | Linear Regression (선형회귀)Machine Learning/ML with Python Library 2024. 3. 25. 20:07
회귀의 경우, 일반화된 예측 함수는 다음과 같다. y = w0x0 + w1x1 + w2x2 + ... + wpxp + b 여기서 w와 x는 특성의 갯수만큼 생기며, 위의 예제에서는 p+1개의 특성이 있다고 생각할 수 있다. 특성이 한개인 Linear Regression 모델은 다음과 나타낼 수 있다. y = w0x0 + b mglearn예시를 가지고 Linear Regression에서 위에서 정의한 선을 어떻게 그려내는지 확인해보자. !pip install mglearn import mglearn mglearn.plots.plot_linear_regression_wave() 위와같은 Linear가 그려졌고, w(weight)과 b(bias)값은 아래와 같이 측정되었다. w[0]: 0.393906 b: -..
-
지도학습 | K-NN Regression (최근접 이웃 회귀)Machine Learning/ML with Python Library 2024. 3. 24. 21:05
KNN을 이용해서 Regression문제도 풀어낼 수 있다. KNN을 이용하게 되면, 예측값은 가장 가까운 이웃의 타겟값이 된다. !pip install mglearn import mglearn mglearn.plots.plot_knn_regression(n_neighbors=1) 이렇게 하면, 가장 가까운 이웃 1개를 골라서 그것이 결과값이 된다. 결과는 다음과 같았다. 각 인풋(test data)별로, 가장 가까운 데이터(training data/target)을 찾아내고, 그 타겟을 결과값으로(test prediction) 나타내었다. 여기서 K-NN은, 1-NN이었는데, 코드를 조금 수정해서 K를 1보다 큰 숫자를 사용해 회귀분석을 할 수 있다. mglearn.plots.plot_knn_regres..
-
Multiclass Classification | Advanced Learning AlgorithmMachine Learning/Stanford ML Specialization 2024. 3. 24. 16:08
Coursera Machine Learning Specialization > Supervised Machine Learning: Advanced Learning Algorithms > Neural Network Intuition Multiclass Multiclass Classification은 분류 문제 중, 여러가지의 Class를 판별하는 문제이다. Logistic Regression을 이용해서 y가 0이거나 1인 확률을 계산하고, threash hold값을 이용해서(예: 0.5) 판별해내는 모델을 배웠었다. 하지만 그 가지수가 2개 이상이라면? 여러 포켓몬이 있다고 가정해보자. 그러면 그래프상으로 각 결과값마다 결정 경계(Decision Boundry)가 생기고, 그 경계선을 갖고 여러가지의 cla..
-
Activation Functions | Advanced Learning AlgorithmMachine Learning/Stanford ML Specialization 2024. 3. 24. 13:57
Coursera Machine Learning Specialization > Supervised Machine Learning: Advanced Learning Algorithms > Neural Network Intuition Alternatives to the sigmoid activation 지금까지는 Activation 함수로 Sigmoid 함수를 써왔다. 티셔츠가 얼마나 팔릴지에대한 Demand Prediction을 계산할 때, price, shipping cost, marketing, material등의 값을 이용해서 여러가지 값을 측정한다고 생각해보자. 그 중, awareness(인지도) 값을 0이나 1인 binary가 아니라, 음수가 아닌 0과 1 사이 숫자로 표현해보자. 이전에는 sigm..
-
TensorFlow Training Details | Advanced Learning AlgorithmMachine Learning/Stanford ML Specialization 2024. 2. 11. 14:54
Coursera Machine Learning Specialization > Supervised Machine Learning: Regression and Classification > Regression with multiple input variables 이전 시간에서 모델을 트레이닝 하는 코드를 써봤는데, 실제로 이 코드가 무엇을 하는지 살펴보자. Neural Network의 세부 사항을 살펴보기 전에, 이전에 Logistic Regression 모델을 어떻게 훈련했었는지 기억해보자. Logistic Regression 먼저 1단계로, Feature들인 x와, weight(w), bias(b)가 주어지면 출력값을 계산하는 방법을 지정해주는 단계였다. W와 X를 dot product한 값에 b를 더한..
-
TensorFlow Implementation | Advanced Learning AlgorithmMachine Learning/Stanford ML Specialization 2024. 2. 11. 13:07
Coursera Machine Learning Specialization > Supervised Machine Learning: Advanced Learning Algorithms > Neural Network Intuition 이 Neural Network를 코드로 표현해보자. 먼저, tensorflow를 import하고, 각 레이어를 Dense를 이용해서 생성하고, Sequential을 이용해서 Neural Network를 생성할 수 있다. import tensorflow as tf from tensorflow.keras import Sequential from tensorflow.keras.layers import Dense 자, 이제 하나하나의 Layer를 만들고, 그것을 순차적으로 갖고있는 모델..
-
Matrix Multiplication Code | Advanced Learning AlgorithmMachine Learning/Stanford ML Specialization 2024. 2. 10. 20:59
Coursera Machine Learning Specialization > Supervised Machine Learning: Advanced Learning Algorithms > Neural Network Intuition 이제 전에 직접 계산했던것을 NumPy를 이용해서 계산해보자. 먼저 A matrix를 아래와 같이 생성할 수 있다. A = np.array([1, -1, 0.1], [2, -2, 0.2]]) 이제 이 matrix를 transpose 한 matrix를 생성해보자. AT = np.array([[1, 2], [-1, -2], [0.1, 0.2]]) 매번 이렇게 직접 쓰지 않아도, 원래의 matrix가 있다면, transpose를 이렇게 할 수 있다. AT = A.T 그리고 W matr..