ACTU PS5841 Data Science in Finance & Insurance - Spring 2022
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
ACTU PS5841 Data Science in Finance & Insurance - Spring 2022
Assignment - 1
Problem 1. Base Python, Method of Least Squares
Let base python refer to the python distribution from www.python.org. Please use only base python to complete the following tasks and submit a functioning python script, SLR.py.
[1] Generate a training set containing 50 observations according to
Yi = 10 + 0.5xi + ✏i or y = 10 + 0.5x + ✏
where xi 2 ( −200, 200) and E(✏i) = 0,Var(✏i) = 400 and ✏i are independent random variables.
[2] Adopt the model E(Yi) = β0 +β1xi and apply the method of least squares to the training set to estimate the model parameters and produce the fitted values:
[3] Calculate the coefficient of determination R2 of the fitted model.
[4] Use turtle graphics to present a scatter plot of the training set, the fitted regression line, and the related annotation, similar to the one below.
You may find the following resources useful.
random — Generate pseudo-random numbers
https://docs.python.org/release/3.10.2/library/random.html
random.uniform(a, b)
random.gauss(mu, sigma)
turtle — Turtle graphics
https://docs.python.org/release/3.10.2/library/turtle.html
turtle.write()
ClassFolder/U1-BasePy/Lib-standard-turtle.py
data structures
ClassFolder/U1-BasePy/BasePython-DataStructures.html
program control
ClassFolder/U1-BasePy/BasePython-ControlFlow.html
unicode character table
https://unicode-table.com/en/
2022-01-22