关键词 > Python代写

Applications of Data Science and Statistical Modelling

发布时间:2022-01-04

Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


Applications of Data Science and Statistical Modelling

Assignment


 

This assignment consist of four sections. Section A requires you to work in Python, while sections B and C have R-based exercises. Section D is a narrated power point presentation on Section C question 4.

 

A. Python [40 marks]

This part of the coursework involves python code, written summaries, and figures.

A useful environment to work on these questions and submit your answers is in a Jupyter notebook.  If you use this format, submit the notebook file, a nd ( optionally, b ut h ighly r ecommended) a n e xport o f your notebook to either pdf or html format. If we end up not being able to open your notebook, and don’t have such an export to look at, we cannot assign any marks.

Using a Jupyter notebook is not strictly necessary.  You may also submit a python source code file (plain text) that contains your python code, your answers to the questions as commented lines in the code, and any figures as separate files with filenames indicating the question they answer.

Do not paste your code into a Word document or similar, the formatting will likely alter the indentation and introduce errors in the code. For the submitted code and written answers, it is important that all text can be highlighted, copied and pasted from your submission - do not submit screenshots of your code and answers.

Always state your answer as complete sentences, not just as the output of python commands. Indicate very clearly which question you answer, using an appropriate markdown heading, or otherwise clarifying it for the marker, for example:

Answer  to  question  1.2:  The  answer  is  3.

Also clearly indicate the code chunks that you used to answer each question.

You may not use any other programming languages than the python language to answer the questions in this part (calling R from within python counts as “using another language”).

 

Trac Accidents

1.  [5 marks] Download and import trac accidents data.

(i)  Download the csv file “accidents2019.csv” from the “week 1” tile of MTHM503 ELE page (on ELE, the file is titled “UK Accidents 2019 data (accidents2019.csv)” - it is the same file that was used in one of the exercises).  You don’t have to use a python command to download the data. The data was originally downloaded from the UK Department of Transport Road Safety data base (“Road Safety Data - Accidents 2019”) (LINK) where further information about the data is available.  Read the csv file into a pandas data frame named accidents, and display the first 2 lines of the data frame.



Unless  stated  otherwise,  all  of the following  questions  related  to  trac  accidents  are  to  be  answered  by

analysing the data frame accidents .

2.  [5 marks] General

(i)  How many accidents happened in 2019?

(ii) What are the column names in the data frame?

(iii)  Report the date  (day/month/year) and coordinates  (longitude and latitude) of the accident in

the 100th row of the data frame.  (The row at the top of the data frame counts as the 1st row.)  (iv)  Does any of the columns contain information about the type of vehicles involved in the accident?

3.  [5 marks] Casualties

(i)  Calculate the total number of casualties.

(ii)  What is the difference in the number of casualties between Lower Layer Super Output area (LSOA)

E01032739 (City of London 001F) and E01033708 (Hackney 027G)?

(iii) What LSOA saw the highest total number of casualties in 2019?

4.  [5 marks] Police ocer attendance

(i) What are the possible values that occur in the column Did_Police_Officer_Attend_Scene_of_Accident, and how often does each value occur?

(ii)  The value Did_Police_Officer_Attend_Scene_of_Accident  =  1 indicates that a police officer attended the accident. What do the other value(s) in that column mean?  (Consult the data web site to answer this question.)

(iii) What fraction of accidents was attended by a police officer?

(iv) What fraction of those accidents that happened on a weekday was attended by a police officer? How does this number compare to the corresponding fraction for accidents on weekends?

5.  [10 marks] Visualisation

(i) Visualise the locations of all accidents by a scatter plot of Latitude vs Longitude.  Annotate the axes, add a plot title, and increase the figure size to 10in by 10in.

(ii)  Create a similar scatter plot as in the previous question 5(i). but zoom in on a 2 by 2 degree area that includes Exeter/Devon, and choose a different color for accidents that happened in a rural area and in an urban area. Include a red marker that indicates the coordinates of Exeter/Devon (as per wikipedia).

(iii)  Are accidents at higher speed limits more likely to be fatal than at lower speed limits?  Answer the question with an appropriate data visualisation and a short written summary.

 

Gym exercise and physiology data

To complete the following questions,  you have to load the  “Linnerud physical exercises data” from the scikit-learn package using the following commands:

 

●  from  sklearn.datasets  import  load_linnerud

●  linnerud  =  load_linnerud()

6.  [10 marks] Regression analysis


(i)  State the author’s last name and year of the study in which that data first appeared.

(ii)  Using the appropriate function from the scikit-learn package, fit a simple linear regression model with number of chinups (Chins) as the target variable, and “Weight” as the covariate. Report the fitted regression coefficients, and interpret the slope coefficient.

(iii) Your lecturer is a middle-aged male, 170 pounds (“Weight”), 32 inch waist size (“Waist”), and a resting heart rate of 70 (“Pulse”)? How many chin-ups (“Chins”) do you think he can do?  (Use linear regression in scikit-learn on the Linnerud data to answer the question.)

7.  [10 marks] Trouble shooting and code adaptation

Imagine you are in a data sciences consulting role. You are tasked with automating the analyses in        part A to browse and run accurately across a socio-economic data base  (netcdf files, csv and excel data types including missing data cells) for multiple regions and countries. Write a 200 word paragraph to   explain how you could automate the analysis and explain in words the summary quantification               information you would provide to give a one page overview.

THE REST OF THE QUESTIONS SHOULD BE SOLVED USING R

 

B. Health Impact Analysis [30 marks]

Chronic obstructive pulmonary disease (COPD) is a type of lung disease with long-term breathing problems. The main symptoms include shortness of breath and cough with phlegm production. COPD is a progressive disease, meaning it typically worsens over time. Tobacco smoking is the most common cause of COPD, with factors such as air pollution and genetics also playing a role.

The aim of this part is to investigate hospital admission rates for COPD in England between 2001–2010. You have been given data collected on the number of hospital admissions due to COPD for each year between 2001 and 2010 in 324 local authority administrative areas in England.

In  addition,  you  are  given  the  corresponding  expected   number   of  cases,   calculated   using   indirect standardisation by applying the age–sex specific rates for the whole of England to the age–sex population profile of each of the local authorities.  The observed counts can be found in copdobserved.csv and the dataset has the following variables:

 

●  name - Name of local authority,

●  Y20XX - Observed number of hospital admissions for COPD in the year 20XX.

 

The expected counts can be found in copdexpected.csv and the dataset has the following variables:

 

●  name - Name of local authority,

●  E20XX - Expected number of hospital admissions for COPD in the year 20XX.

 

You also have shapefiles for England split by local authorities provided in order to produce any maps for

this analysis (englandlocalauthority.shp, englandlocalauthority.dbf, englandlocalauthority.shx and englandlocalauthority.prj)

 

1.  [4 marks] Summarise the number of hospital admissions for COPD in England between 2001 and 2010.


2.  [10 marks] Estimate raw and smoothed standardised morbidity ratios (SMR). You should look for any spatial(!)  patterns and/or extreme values and consider any potential reasons for them.  You should note any differences between raw and the smoothed estimates.   If there are big changes, are they appropriate?

3.  [6 marks] Investigate any changes in the risks of hospitalisation due to COPD in England over time.

4.  [10 marks] Suppose a government minister wants to increase resources to hospitals to cope with admis- sions for COPD. Write a short report (maximum 1 page text) recommending key areas/local authorities in England where these resources should be allocated. In your answer you should explain the key steps of the analysis you have done, providing comment on what conclusions you can draw and any limi- tations associated. You do not need to include every step of the analyses, but should include results, figures and tables that support your findings.  Ensure any plots and/or tables included are labelled clearly and are accompanied with appropriate captions.

 

C. Clustering [80 marks]

 

Aim

The aim of this part of the assignment is to perform clustering on power data recording at substations in order to see whether there are groups that have similar demand profiles and to see whether there are differences between years.

 

Data

There are two types of data: (i) variable - the measurements from the monitors; and (ii) fixed - characteristics of the substations, that include information that may be useful when trying to understand, and name, your clusters.

There are 3 datasets containing the variable data, each relating to a different year

 

●  January_2013.RData

●  January_2014.RData

●  January_2015.RData

You can load each dataset using the load function

# Loading  dataset  for  January  2013

load("January_2013.RData")

 

Within each of the datasets, in each row there is a date, a Station ID, followed by 144 numbers that are the raw power for each ten minutes for that substation.

Even though the dataset contains the raw measurements you will have to work with the scaled version of

these measurements.   The scaled version is the actual measurement  divided by the  daily maximum.   The

idea is that if you perform clustering on the raw data, clusters may be chosen based just on the magnitude rather than on the patterns within days.

The fixed data is in the Characteristics.csv file.


 

This contains the following information:

●  SUBSTATION_NUMBER - so you can link with the measured data

●  TRANSFORMER_TYPE - ground or pole mounted (indicating urban or rural)

●  TOTAL_CUSTOMERS - the number of customers receiving their electricity from this substation

●  Transformer_RATING - indicating the size of the total power being delivered by the substation

●  Percentage_IC - the percentage of industrial and commerical (not domestic) customers

●  LV_FEEDER_COUNT - the number of feeders coming from the substation

●  GRID_REFERENCE - the Ordnance Survey grid reference for the location

(see https://getoutside.ordnancesurvey.co.uk/guides/beginners-guide-to-grid-references/)      Dataset NewSubstations.csv contains raw measurements for five new substations  (for each ten minute period).

1.  [10 marks] Initial data analysis tasks

(i)  Summarise the data in the Characteristics.csv dataset, and plot the distributions for the per- centage of industrial and commercial customers, transformer ratings and pole or ground monitored substations.

(ii)  Using this and other analyses you think appropriate, describe the relationships between the dif- ferent substation characteristics (transformer type, number of customers, rating, percentage of I&C customers and number of feeders).

2.  [20 marks] Initial clustering tasks

Using the scaled daily measurements from the January_2013 dataset perform hierarchical clustering for  the  daily average demand  (that  is  each  10  minute  period  for  the  given  substation  should  be averaged over all days where measurement is available):

(i)  Using your preferred choice of a dissimilarity function, create a distance matrix for these data and produce a dendrogram.

(ii)  Choose an  appropriate number of clusters  and  label each  substation according to  its  cluster membership.

(iii)  For each of your clusters, plot the daily average demand for 1) All days, 2) Weekdays, 3) Saturdays and 4) Sundays.


(iv)  Produce summaries of the variables in Characteristics.csv for each of your clusters.

(v)  Desribe your clusters based on the information in Characteristics.csv and choose names for them. Describe the patterns of their power demands for each cluster.

3.  [20 marks] Allocating new substations

The Dataset NewSubstations.csv contains information for five new substations.

(i)  For each substation, on the same plot, plot the daily average demand for 1) All days, 2) Weekdays,

3) Saturdays and 4) Sundays (one plot per new substation).

(ii)  Using k-means (or other version, i.e. based on medians), allocate these new substations to one of your clusters.

(iii)  Based on your summaries and plots, is the cluster allocation as you expected?

4.  [30 marks] Exploring differences between years

(i)  The power company want to know whether there are any differences between power demands between years.  They are particulary interested in whether the groupings/clusters of substations change between years.   Peform  suitable analyses of the power  demands by year and explore whether the membership of clusters changes between years.  You should write a report to the power distribution company detailing your analyses, results and present a conclusion. Your report

should include plots/tables where appropriate and should be a maximum length of 2 pages. Plots and tables are not included in this limit.

 

D. Presentation [40 marks]

The presentation is based on PartC/Q4 only. You should submit a narrated power-point presentation that should be 5 minutes long, and you should aim for 5 slides in total.

In this you should explain what the problem is, how you approached it, and what your findings are.            You should pay attention to the clarity/pace/coherency of the delivery, the style/information-balance on the slides, clear description of methodology and time management.