You need to write three functions in util.py. When they are done correctly, linreg_mi.py will un unchanged. The three functions are: • read_excel_data which reads in the excel file and returns X, Y, and labels. Y is a 1- dimentional numpy array containing the last column of the spreadsheet. X is a 2-dimensional numpy array that contains the data in the other columns and the first column is filled with 1s. labels is a list of strings from the header in the spreadsheet. format_prediction which takes B (the vector of coefficients) and labels that you created in read_excel_data. Then it returns a string like this: predicted price = $32,362.85+ ($85.61 x sqft_hvac) + ($2.73 x sqft_yard) + ($59,195.07 x bedrooms) + ($9,599.24 x bathro ($-17,421.84 x miles_to_school)} • score that takes B, X, and Y and returns the R² score.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question
4.1 util.py
You need to write three functions in util.py. When they are done correctly, linreg_mi.py will
run unchanged. The three functions are:
read_excel data which reads in the excel file and returns X, Y, and labels. Y is a 1-
dimentional numpy array containing the last column of the spreadsheet. X is a 2-dimensional
numpy array that contains the data in the other columns and the first column is filled with
1s. labels is a list of strings from the header in the spreadsheet.
• format_prediction which takes B (the vector of coefficients) and labels that you created
in read_excel_data. Then it returns a string like this:
predicted price = $32,362.85+ ($85.61 x sqft_hvac) + ($2.73 x sqft_yard) +
($59,195.07 x bedrooms) + ($9,599.24 x bathrooms)
($-17,421.84 x miles_to_school)}
score that takes B, X, and Y and returns the R² score.
When util.py is done, you should be able to run linreg_mi.py and linreg_scikit.py.
4
Transcribed Image Text:4.1 util.py You need to write three functions in util.py. When they are done correctly, linreg_mi.py will run unchanged. The three functions are: read_excel data which reads in the excel file and returns X, Y, and labels. Y is a 1- dimentional numpy array containing the last column of the spreadsheet. X is a 2-dimensional numpy array that contains the data in the other columns and the first column is filled with 1s. labels is a list of strings from the header in the spreadsheet. • format_prediction which takes B (the vector of coefficients) and labels that you created in read_excel_data. Then it returns a string like this: predicted price = $32,362.85+ ($85.61 x sqft_hvac) + ($2.73 x sqft_yard) + ($59,195.07 x bedrooms) + ($9,599.24 x bathrooms) ($-17,421.84 x miles_to_school)} score that takes B, X, and Y and returns the R² score. When util.py is done, you should be able to run linreg_mi.py and linreg_scikit.py. 4
12:21
Share
Business card Sep 11, 2022
Done
linreg_mi (3 of 6)
import numpy as np
import pandas as pd
import sys
import util
# Check command line
if len(sys.argv) != 2:
print (f"{sys.argv[0]} <xlsx>")
exit (1)
#Read in the argument
infilename = sys.argv[1]
# Read the spreadsheet
X, Y, labels util.read_excel_data(infilename)
n, d= X. shape
print (f"Read {n} rows, {d-1} features from
{infilename)",")
# Find the coefficients for the linear
regression
B = np.linalg.inv(X.T @ X) @ X.T @ Y
# Pretty print them
print (util.format_prediction (B, labels))
R2 = util.score (B, X, Y)
print (f"R2 (R2: f}")
Done
import pandas as pd
import numpy as np.
util (6 of 6)
#Read in the excel file
# Returns:
#X: first column is 1s, the rest are from the
spreadsheet
#Y: The last column from the spreadsheet
#
labels: The list of headers for the columns
of X from the spreadsheet
def read_excel_data(infilename):
## Your code here
return X, Y, labels
Make it pretty
def format prediction (B, labels):
## Your code here
return pred_string
Modify
# Return the R2 score for coefficients B
#Given inputs X and outputs Y
def score (B, X, Y):
## Your code here
return R2
EK
Text actions
20
Save contact
More
Transcribed Image Text:12:21 Share Business card Sep 11, 2022 Done linreg_mi (3 of 6) import numpy as np import pandas as pd import sys import util # Check command line if len(sys.argv) != 2: print (f"{sys.argv[0]} <xlsx>") exit (1) #Read in the argument infilename = sys.argv[1] # Read the spreadsheet X, Y, labels util.read_excel_data(infilename) n, d= X. shape print (f"Read {n} rows, {d-1} features from {infilename)",") # Find the coefficients for the linear regression B = np.linalg.inv(X.T @ X) @ X.T @ Y # Pretty print them print (util.format_prediction (B, labels)) R2 = util.score (B, X, Y) print (f"R2 (R2: f}") Done import pandas as pd import numpy as np. util (6 of 6) #Read in the excel file # Returns: #X: first column is 1s, the rest are from the spreadsheet #Y: The last column from the spreadsheet # labels: The list of headers for the columns of X from the spreadsheet def read_excel_data(infilename): ## Your code here return X, Y, labels Make it pretty def format prediction (B, labels): ## Your code here return pred_string Modify # Return the R2 score for coefficients B #Given inputs X and outputs Y def score (B, X, Y): ## Your code here return R2 EK Text actions 20 Save contact More
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Query Syntax
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education