Consider the Python snippet below that simulates some data, runs a linear regression on the simulated data, and plots the predictors of the regression.
This is a poorly written code. It has the following issues:
As an exercise, provide a refactored code as the solution to this problem. You solution needs to fix all the issues mentioned above. Check the slides if you need help.
import numpy as np
import matplotlib.pyplot as plt
a = np.random.rand(100)
b = 5 + 3*a + np.random.normal(size=100)
plt.scatter(a, b, color = 'red')
# import your packages
import numpy as np
import matplotlib.pyplot as plt
# create variables
ind_variable = np.random.rand(100)
intercept = 5
slope = 3
error_term = np.random.normal(size=100)
# simulate the data generation process
dep_variable = intercept + slope*ind_variable + error_term
# plot
plt.scatter(dep_variable, ind_variable, color = 'red')
Create a folder called “Practice” on your local computer. Use the commandline to navigate to that folder. Next, initialize a git repository in that folder. Do all these steps using the commandline
# mkdir practice
# cd practive
# git init
Using the git repository that you created in Question 1. Do the following:
Create a .txt
named notes_about_ds5203
using either the commandline or just make this file yourself and move to the folder.
Add that file to the staging area.
Commit that file with a clear commit message
Check to see if the file is staged using git status;
Now update the file (i.e., make some change to it) and stage and commit that change;
Look at your git log to see the two commits you made.
# create file
touch notes_about_ds5203
# add to the stagging area
git add .
# commit
git commit -m "my notes for dspp"
# go to github and create a repo
vim notes_about_ds5203
# add and stage
# add to the stagging area
git add .
# commit
git commit -m "my notes for dspp"
# log
git log
Create a new repository on your own Github account
Clone the repository at your local machine
Make some changes in your local machine
Push your local changes to your github repository
# example code of what would work
# clone
git clone <repo>
# cd to your new folder
cd repo
# modify something, stage and commit
git add .
git commit -m "something"
# push
git push
# you might need to set up your identity here.
git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"
!jupyter nbconvert _week_02_solution.ipynb --to html --template classic