Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question: Implement Linear regression using NumPy. You should implement your code in the provided linear _ regression.py file. This python file takes a csv file

Question:
Implement Linear regression using NumPy. You should implement your code in the provided linear_regression.py file. This python file takes a csv file and a list of features as input. From these list of features, the last feature will be the target label and the remaining ones will be your training inputs. For example, in the following usage scenario, linear.csv is the csv file and Writing is the target label, while Math and Reading are training inputs.
$python3 linear_regression.py linear.csv Math Reading Writing
Output the RMSE score of prediction.
-provided linear_regression.py file,is as follow:
import numpy as np
import pandas as pd
import math
import sys
import os
#Todo : define necessary functions
def linear_regression(data):
"""
data: input data matrix
return: rmse value
"""
#Todo : fill code here
return -1
# do not modify this function
def load_data():
filename = sys.argv[1]
feature_matrix = pd.read_csv(filename)
feature_matrix = feature_matrix.dropna()
features = sys.argv[2:]
#print(feature_matrix[features])
return feature_matrix
if __name__=="__main__":
data = load_data()
RMSE_SCORE = linear_regression(data)
print("RMSE score is : ", RMSE_SCORE)
-
linear.csvcontains in the following format: Math, Reading, Writing. There are 1001 lines of data structured in this way.also the image of inear.csv has been attched
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 17th International Conference Dasfaa 2012 Busan South Korea April 2012 Proceedings Part 1 Lncs 7238

Authors: Sang-goo Lee ,Zhiyong Peng ,Xiaofang Zhou ,Yang-Sae Moon ,Rainer Unland ,Jaesoo Yoo

2012 Edition

364229037X, 978-3642290374

More Books

Students also viewed these Databases questions

Question

Solve each equation by factoring. 15x 2 = 16 - 8x

Answered: 1 week ago