Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

import numpy as np
from scipy.optimize import minimize
import matplotlib.pyplot as plt
import pickle

#Implement the function calAnaliticalSolution

def calAnaliticalSolution(X,y):
# Inputs:
# X = N x d
# y = N x 1
# Output:
# w = d x 1 (which is the parameter calculated from data X and label y using alalytical solution)

# IMPLEMENT THIS METHOD - REMOVE THE NEXT LINE
w = np.zeros((X.shape[0],1))

return w

#Implement the function calRegressionError

def calRegressionError(w,Xtest,ytest):
# Inputs:
# w = d x 1
# Xtest = N x d
# ytest = N x 1
# Output:
# mse = scalar value (which is the error of the regression model)

# IMPLEMENT THIS METHOD - REMOVE THE NEXT LINE
mse = 0

return mse

Xtrain,ytrain,Xtest,ytest = pickle.load(open('diabetes.pickle','rb'))

x1 = np.ones((len(Xtrain),1))
x2 = np.ones((len(Xtest),1))

Xtrain_i = np.concatenate((np.ones((Xtrain.shape[0],1)), Xtrain), axis=1)
Xtest_i = np.concatenate((np.ones((Xtest.shape[0],1)), Xtest), axis=1)

w = calAnaliticalSolution(Xtrain,ytrain)
w_i = calAnaliticalSolution(Xtrain_i,ytrain)

mse = calRegressionError(w,Xtrain,ytrain)
mse_i = calRegressionError(w_i,Xtrain_i,ytrain)
print('MSE without intercept on train data - %.2f'%mse)
print('MSE with intercept on train data - %.2f'%mse_i)

mse = calRegressionError(w,Xtest,ytest)
mse_i = calRegressionError(w_i,Xtest_i,ytest)
print('MSE without intercept on test data - %.2f'%mse)
print('MSE with intercept on test data - %.2f'%mse_i)

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
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
    Text book image
    Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Text book image
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Text book image
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    Text book image
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Text book image
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Text book image
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education