본문 바로가기

미국유학/Andrew En ML Coursera

7.20 (SAT) : Supervised Learning

 

-Supervised Learning 

      -give "right answers"

 

      -Regression : Housing price prediction 

            -predict numbers. infinitely many possible outputs 

 

      -Classification : Beast cancer detection 

           -predict categories. small niumberof possibile outputs 

 

 

 

 

 

-Unsupervised Learning

      -to find pattern 

      -clustering algorithm : used in Google news , DNA microarray clustering 

      -another example : Grouping customers 

 

      -anomaly detection : find unusual data points 

      -demensionality reduction : compress data using fewer numbers 

 

 

 

Regression Model

Linear Regression 

       -predicts numbers  

 

Terminology 

     -Training set : Data used to train the model 

     - Notation :  x="input" variable feature   

                           y="output" variable, "target" variable 

                           m  = number of training example 

                           (x,y) = single training example 

                           괄호 안의 첨자(승)으로써 몇번째 값인지 나타낸다. 

 

       -"y-hat" 

       - x=model   

       - How to represent f?  fw,b(X) = wx + b 

                                              f(X)

 

       - Univariate linear regression     =  one variable 

 

 

(Hands On Lab) 

x_train.shape[0] is the length of the array

len()  can also be used 

 

 

i = 0  

x_i = x_train[i]

y_i = y_train[i]

print(f"(x^({i}), y^({i})) = ({x_i}, {y_i})")

 

 

# Plot the data points

plt.scatter(x_train, y_train, marker='x', c='r') 

#Set the title

plt.title("Housing Prices")

#Set the y-axis label

plt.ylabel('Price (in 1000s of dollars)')

#Set the x-axis label

plt.xlabel('Size (1000 sqft)')

plt.show() 

 

 

 

def compute_model_output(x, w, b):

    m = x.shape[0]

    f_wb = np.zeros(m)

    for i in range(m):

        f_wb[i] = w* x[i] + b 

    return f_wb 

 

 

 

tmp_f_wb = compute_model_output(x_train, w, b)

#Plot our model prediction

plt.plot(x_train, tmp_f_wb, c='b', label='Our Prediction')

#Plot the data points

plt.scatter(x_train, y_train, marker='x', c='r', label='Actual Values')

#Set the title

plt.title("Housing Prices")

#Set the y-axis label

plt.ylabel('Price (in 1000s of dollars)')

#Set the x-axis label

plt.xlabel('Size (1000 sqft)')

plt.legend()

plt.show() 

 

w=200

b=100

x_i = 1.2

cost_1200sqft = w* x_i + b 

print(f"${cost_1200sqft:.0f} thousand dollars") 

 

 

 

Cost function formula 

w,b : parameters, coefficients, weights  

 

 

 

 

 

 

'미국유학 > Andrew En ML Coursera' 카테고리의 다른 글

7.21 Regression Model  (0) 2024.07.22