import pandas as pd
import numpy as np
df = pd.read_csv('/Users/mali/Downloads/multiple_linear_regression_dataset.csv')
x_train = df.iloc[:,:2]
y_train = df.iloc[:,2]
print(f"x_tran shape{x_train.shape}, x_train value {x_train}")
print(f"y_tran shape{y_train.shape}, y_train value {y_train}")
w_init=np.array([0.3,30])
b_init=50
print(f"w_init shape {w_init.shape}, type of b_init {type(b_init)}")
# our multiple linear regression model : f_wb = w1 * x1 + w2 * x2 + b
x_vec = x_train.iloc[0,:]
print(f"x_vec shape {x_vec.shape}, x_vec value {x_vec}")
def predict_single_vector(w,b,x):
m = x.shape[0]
p=0
for i in range(m):
v_d = x[i] * w[i]
p += v_d
p = p + b
return p
# also we can use np.dot() method
def predict_dot(w,b,x):
p = np.dot(x,w) + b
return p
def compute_cost(w,b,x,y):
m=x.shape[0]
cost = 0
for i in range(m):
f_wb = np.dot(x[i],w) + b
cost = cost + (f_wb - y[i])**2
total_cost = 1/(2*m)*cost
return total_cost