logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
StatAnalytica ExpertNursing
(5/5)

912 Answers

Hire Me
expert
Adarsh Vikram RaiComputer science
(/5)

865 Answers

Hire Me
expert
Joann DomettCriminology
(5/5)

695 Answers

Hire Me
expert
Jeremiah BennetttEconomics
(5/5)

607 Answers

Hire Me
Others
(5/5)

This problem asks you to plot data points, then apply linear regression and quadratic regression to predict the engin efficiency in the requested years

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

"""

This problem asks you to plot data points, then apply linear regression and quadratic regression to predict the engin efficiency in the requested years

"""

 

import numpy as np

import scipy.linalg as linalg import matplotlib.pyplot as plt

 

 

#---------------------------------------------------------------------

# note: LS is essentially solving Ax=b. all you need are A and b from the input data.

# for this problem the LS solution x will be the coefficients of polynomials

#

 

 

def eigen_linear(xData, yData, years): #

# add code to genetate A and b for linear-LS, then solve it to get the solution

# x = [c0, c1].

# here x contains only two components, from which you can construct the LS line

# (the line equation should be a function of year, you can use it to generate

# prediction for any input years, from which you can do plotting etc.

#

# for this one: solve the LS problem via solving the normal equation (A.T*A)*x = A.T*b

# you first form the A.T*A and A.T*b (note: * do not work for numpy array multiplication),

# after that you can call linalg.solve() to get the solution #

# this problem asks you to return the linear function eveluated on the input years,

# i.e. c0 + c1* years #

L=len(xData) G=np.ones((L,2))

 

G[:,1]=xData

z,_,_,_ = linalg.lstsq (G, yData)

 

return (z[0]+z[1]*years)

 

 

 

 

def eigen_quadratic(xData, yData, years): #

# add code to genetate A and b for quadratic-LS, then solve it to get the solution

# x = [c0, c1, c2].

# here x contains only three components, from which you can construct the LS curve

# (the curve should be a function of year, you can use it to generate

# prediction for any input years, from which you can do plotting etc.

#

# for this one: solve the LS problem by calling the scipy linalg.lstsq() function

# note this function has 4 outputs, you only need the 1st one to get the solution,

# a call like x, _, _, _ = linalg.lstsq(A, b) should get the LS solution for Ax=b

# if your A and b are correct #

# return the quadratic function eveluated on the input years, # i.e. c0 + c1* years + c2* years**2

#

n=len(xData) A=np.ones((n,3))

A[:,1]=xData

for i in range(1,3): A[:,i] = A[:, i-1] *xData c,_, _ , _ = linalg.lstsq (A, yData)

return c[0]+c[1]*years +c[2]*years**2

 

 

 

 

def engin_eff(xData, yData, years):

 

# add code to plot your data points,

# plot also the linear LS line, the quadratic LS curve, evaluated on the input years

# (the data from plotting should be by calling your defined functions above)

# set the labels and lengends etc. save your plot to an image file for upload

 

 

 

 

 

 

 

2022

 

 

#

# find the predicted values that are for years 2005, 2015, and

 

# you can simply pass predic_years=np.array([2005, 2015, 2022])

 

to your above functions to get

# the predictions for all these three years.

# (round your results to exactly 5 decimal points, including possible ending zeros,

# for canvas input) #

 

 

 

 

 

#=====================================================================

===================

# if your code above is correct, you do not need to modify anything below

#

if  name ==' main ':

 

#

# input the data from the table, make them to be np.array so that they can be operated componentwisely

#

xData = np.array([1718, 1767, 1774, 1775, 1792, 1816, 1828, 1834,

1878, 1906, 2000 ])

yData = np.array([0.005, 0.008, 0.014, 0.027, 0.045, 0.075, 0.12,

0.17, 0.172, 0.23, 0.46 ])

 

years = np.arange(1718, 2030, 1) #step=1 should make all integer years be included

 

engin_eff(xData, yData, years)

 

(5/5)
Attachments:

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme