Question: Just solve 1-(a) for me mport csv import numpy as np class LinearRegression(): def __init__(self, x, y): self.x = x self.y = y self.num_data =

Just solve 1-(a) for meJust solve 1-(a) for me mport csv import numpy as np class

LinearRegression(): def __init__(self, x, y): self.x = x self.y = y self.num_data

mport csv import numpy as np class LinearRegression(): def __init__(self, x, y): self.x = x self.y = y self.num_data = self.x.shape[0] self.num_feature = self.x.shape[1] self.w = np.zeros(self.num_feature) def predict(self, x): ################################################# # write your code ################################################# return result def train(self, lr, epoch): for i in range(0, epoch): ################################################# # write your code ################################################# def data_load(dana_name, tr_te): y = [] x = [] if dana_name == 'BloodPressure': if(tr_te == 'train'): file = './data/bloodPressure/train.csv' elif(tr_te == 'test'): file = './data/bloodPressure/test.csv' with open(file, 'r') as csvfile: csv_reader = csv.reader(csvfile) next(csv_reader) for row in csv_reader: x.append([1, float(row[0])]) y.append(float(row[1])) if dana_name == 'House': if(tr_te == 'train'): file = './data/house/train.csv' elif(tr_te == 'test'): file = './data/house/test.csv' with open(file, 'r') as csvfile: csv_reader = csv.reader(csvfile) next(csv_reader) for row in csv_reader: x.append([1, float(row[1]), float(row[2]), float(row[3]), float(row[4])]) y.append(float(row[0])) return np.array(x), np.array(y) def eval(prediction, y): inner = np.power((prediction - y), 2) return np.sqrt(np.sum(inner) / len(y)) def main(): X_train, Y_train = data_load('BloodPressure', 'train') model = LinearRegression(X_train, Y_train) model.train(0.0, 1) # learning rate, epoch X_test, Y_test = data_load('BloodPressure', 'test') prediction = model.predict(X_test) rmse = eval(prediction, Y_test) print("%.2f"%(rmse)) X_train, Y_train = data_load('House', 'train') model = LinearRegression(X_train, Y_train) model.train(0.0, 1) # learning rate, epoch X_test, Y_test = data_load('House', 'test') prediction = model.predict(X_test) rmse = eval(prediction, Y_test) print("%.2f"%(rmse)) if __name__ == "__main__": main() 

(1) [10 ptsl (Linear regression) Predict the house price given four attributes, and the systolic blood pressure for given age, respectively. Blood pressure Age Systolic Blood Pressure House price price bedrooms: # of bedrooms / House bathrooms: # of bathrooms / bedrooms sft living: the total house square footage of the house sgft above: sqftliving - size of the basement (a) Implement the predict0 and train0 in the LinearRegression class and explain how you implemented the code. (1) [10 ptsl (Linear regression) Predict the house price given four attributes, and the systolic blood pressure for given age, respectively. Blood pressure Age Systolic Blood Pressure House price price bedrooms: # of bedrooms / House bathrooms: # of bathrooms / bedrooms sft living: the total house square footage of the house sgft above: sqftliving - size of the basement (a) Implement the predict0 and train0 in the LinearRegression class and explain how you implemented the code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!