Home Page > > Details

Week 10 - Assessed Exercises

Data Programming with Python

In this set of exercises we will fit some regression models and create a stepwise AIC function. As

we learnt in lectures to fit a regression model, we need to create a DataFrame X and Series y.

X should contain the standardised version of all of the explanatory/ exogenous variables and y

should contain the standardised version of the response/ endogenous variable. To fit the intercept,

X must have an additional column of ones.

Each question asks you to write a function with a specific set of input arguments. The .py template

defines the function name and inputs for each question, do not change these. Be sure you test

your functions before you submit your code to make sure that they are outputting the correct

answer. Unless otherwise stated, all functions must have a return value. This week you should test

your code using both the prostate and diamonds datasets. Testing your functions with multiple

datasets should catch any error related to leaving the DataFrame names inside your function.

Include the import statements for all packages used within your code. Additionally, please include

the package prefixes (pd, np, etc.) for functions/methods from these packages, even if the command

runs in Canopy without the prefix. .

1. Write a function to create X and y for a given DataFrame df The function inputs are the

DataFrame df and the label of the response/endogenous variable rescol. The function should

return two objects, X and y (in that order), where X and why are both standardised and

the column of ones is the first column of X. (You may assume that none of the variables are

categorical)

2. Write a function that takes X and y as inputs and fits a linear regression model. The function

should return the rsquared value rounded to 4 decimal places

AIC is the Akaike information criterion. It’s designed to penalise models with lots of explanatory

variables so that we pick models which fit the data well but aren’t too complicated. In general, if

you have two models fitted to the same data, the model with the lowest AIC is preferable. The

AIC is given as part of the model summary with OLS .

The steps to run a forward selection AIC regression are:

(a) Run a linear regression with just the intercept column. Get the AIC

(b) Add in the explanatory variables individually, run a linear regression for each one and determine

how much they decreases the AIC

(c) Find the variable with the biggest decrease in AIC and include it in your linear model

(d) Repeat step (b)-(c) with this new linear model and remaining explanatory variables

(e) Repeat this process until none of the remaining explanatory variables reduce the AIC

The explanatory variables that have been included up to the stopping point are considered the

variables that produce a good fit without overcomplicating the model.

3. Write a function that performs the AIC algorithm for a given DataFrame X and Series y.

The function should return the names of the columns used for the model that gives the lowest

AIC. This question is worth 2 marks

All of your code should be written into the .py template. Save your filled .py file with the following

name structure SurnameFirstname Week10.py (where Surname and Firstname should be replaced

with your name) and upload it to Brightspace. You must also upload a PDF of your code.

Contact Us(Ghostwriter Service)

- QQ：99515681
- WeChat：codinghelp2
- Email：99515681@qq.com
- Work Time：8:00-23:00

- Tsp Course Assignmentghostwriter ,Help... 2020-06-23
- Kit107 Assignmenthelp With ,C++ Progra... 2020-06-23
- Sta302h1f Assignmenthelp With ,Ghostwr... 2020-06-22
- Ghostwriter Seng 474 Assignment,Help W... 2020-06-22
- Cmpsci 187 Binary Search Trees 2020-06-21
- Comp226 Assignment 2: Strategy 2020-06-21
- Math 504 Homework 12 2020-06-21
- Math4007 Assessed Coursework 2 2020-06-21
- Optimization In Machine Learning Assig... 2020-06-21
- Homework 1 – Math 104B 2020-06-20
- Comp1000 Unix And C Programming 2020-06-20
- General Specifications Use Python In T... 2020-06-20
- Comp-206 Mini Assignment 6 2020-06-20
- Aps 105 Lab 9: Search And Link 2020-06-20
- Aps 105 Lab 9: Search And Link 2020-06-20
- Mech 203 – End-Of-Semester Project 2020-06-20
- Ms980 Business Analytics 2020-06-20
- Cs952 Database And Web Systems Develop... 2020-06-20
- Homework 4 Using Data From The China H... 2020-06-20
- Assignment 1 Build A Shopping Cart 2020-06-20

Contact Us - Email：99515681@qq.com WeChat：codinghelp2

© 2014 www.asgnhelp.com

Programming Assignment Help！