[phpBB Debug] PHP Warning: in file [ROOT]/ext/lmdi/autolinks/event/listener.php on line 237: Undefined array key 160
[phpBB Debug] PHP Warning: in file [ROOT]/ext/lmdi/autolinks/event/listener.php on line 237: Trying to access array offset on value of type null
Answer Happy • 6-4 Discussion: Creating a Multiple Regression Model Use the link in the Jupyter Notebook activity to access your Python
Page 1 of 1

6-4 Discussion: Creating a Multiple Regression Model Use the link in the Jupyter Notebook activity to access your Python

Posted: Mon Jun 06, 2022 1:10 pm
by answerhappygod
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 1
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 1 (97.9 KiB) Viewed 62 times
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 2
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 2 (80.86 KiB) Viewed 62 times
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 3
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 3 (37.47 KiB) Viewed 62 times
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 4
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 4 (30.88 KiB) Viewed 62 times
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 5
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 5 (24.89 KiB) Viewed 62 times
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 6
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 6 (22.35 KiB) Viewed 62 times
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 7
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 7 (12.25 KiB) Viewed 62 times
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 8
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 8 (25.18 KiB) Viewed 62 times
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 9
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 9 (30.99 KiB) Viewed 62 times
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 10
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 10 (30.17 KiB) Viewed 62 times
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 11
6 4 Discussion Creating A Multiple Regression Model Use The Link In The Jupyter Notebook Activity To Access Your Python 11 (20.69 KiB) Viewed 62 times
6-4 Discussion: Creating a Multiple Regression Model Use the link in the Jupyter Notebook activity to access your Python script. Once you have made your calculations, complete this discussion. The script will output answers to the questions given below. You must attach your Python script output as an HTML file and respond to the questions below. In this discussion, you will apply the statistical concepts and techniques covered in this week's reading about multiple regression. Last week's discussion involved a car rental company that wanted to evaluate the premise that heavier cars are less fuel efficient than lighter cars. The company expected fuel efficiency (miles per gallon) and weight of the car (often measured in thousands of pounds) to be correlated. The company also expects cars with higher horsepower to be less fuel efficient than cars with lower horsepower. They would like you to consider this new variable in your analysis. In this discussion, you will work with a cars data set that includes the three variables used in this discussion: • Miles per gallon (coded as mpg in the data set) • Weight of the car (coded as wt in the data set) Horsepower (coded as hp in the data set)

The random sample will be drawn from a CSV file. This data will be unique to you, and therefore your answers will be unique as well. Run Step 1 in the Python script to generate your unique sample data. In your initial post, address the following items: 1. Check to be sure your scatterplots of miles per gallon against horsepower and weight of the car were included in your attachment. Do the plots show any trend? If yes, is the trend what you expected? Why or why not? See Steps 2 and 3 in the Python script. 2. What are the coefficients of correlation between miles per gallon and horsepower? Between miles per gallon and the weight of the car? What are the directions and strengths of these coefficients? Do the coefficients of correlation indicate a strong correlation, weak correlation, or no correlation between these variables? See Step 4 in the Python script. 3. Write the multiple regression equation for miles per gallon as the response variable. Use weight and horsepower as predictor variables. See Step 5 in the Python script. How might the car rental company use this model?

Module Six Discussion: Multiple Regression ¶ This notebook contains the step-by-step directions for your Module Six discussion. It is very important to run through the steps in order. Some steps depend on the outputs of earlier steps. Once you have completed the steps in this notebook, be sure to answer the questions about this activity in the discussion for this module. Reminder: If you have not already reviewed the discussion prompt, please do so before beginning this activity. That will give you an idea of the questions you will need to answer with the outputs of this script. Initial post (due Thursday) Step 1: Generating cars dataset This block of Python code will generate the sample data for you. You will not be generating the data set using numpy module this week. Instead, the data set will be imported from a CSV file. To make the data unique to you, a random sample of size 30, without replacement, will be drawn from the data in the CSV file. The data set will be saved in a Python dataframe that will be used in later calculations. Click the block of code below and hit the Run button above.

In [1]: import pandas as pd from IPython.display import display, HTML # read data from mtcars.csv data set. cars_df_orig = pd. read_csv("https://s3-us-west-2.amazonaws.com/data ... /mtcars.cs #randomly pick 30 observations from the data set to make the data set unique to you. cars_df = cars_df_orig. sample(n=30, replace=False) # print only the first five observations in the dataset. print("Cars data frame (showing only the first five observations)\n") display (HTML (cars_df.head().to_html())) Cars data frame (showing only the first five observations) Unnamed: 0 mpg cyl disp hp drat wt 3 2 21 Dodge Challenger Mazda RX4 Wag 1 qsec vs am gear carb 15.5 8 318.0 150 2.76 3.520 16.87 0 0 21.0 6 160.0 110 3.90 2.875 17.02 0 1 15.8 351.0 264 4.22 3.170 14.50 0 275.8 180 4 4 28 Ford Pantera L 1 5 4 8 8 12 Merc 450SL 17.3 3.07 3.730 17.60 0 0 17 Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 3 4 3 1

Step 2: Scatterplot of miles per gallon against weight The block of code below will create a scatterplot of the variables "miles per gallon" (coded as mpg in the data set) and "weight" of the car (coded as wt). Click the block of code below and hit the Run button above. NOTE: If the plot is not created, click the code section and hit the Run button again. # create scatterplot of variables mpg against wt. plt.plot(cars_df["wt"], cars_df["mpg"], 'o', color='red') # set a title for the plot, x-axis, and y-axis. plt.title('MPG against Weight') plt.xlabel('Weight (1000s lbs)') plt.ylabel('MPG') # show the plot. plt.show() MRC sinct Weight In [3]: import matplotlib.pyplot as plt

MPG against Weight 15 2.0 2.5 5.5 3.0 3.5 4.0 4.5 5.0 Weight (1000s lbs) Step 3: Scatterplot of miles per gallon against horsepower The block of code below will create a scatterplot of the variables "miles per gallon" (coded as mpg in the data set) and "horsepower" of the car (coded as hp). Click the block of code below and hit the Run button above. NOTE: If the plot is not created, click the code section and hit the Run button again. MPG 35 30 25 20 15 10

In [4]: import matplotlib.pyplot as plt # create scatterplot of variables mpg against hp. plt.plot(cars_df["hp"], cars_df["mpg"], 'o', color='blue') # set a title for the plot, x-axis, and y-axis. plt.title('MPG against Horsepower') plt.xlabel('Horsepower') plt.ylabel('MPG') # show the plot. plt.show()

MPG against Horsepower 50 100 150 250 300 200 Horsepower Step 4: Correlation matrix for miles per gallon, weight and horsepower Now you will calculate the correlation coefficient between the variables "miles per gallon" and "weight". You will also calculate the correlation coefficient between the variables "miles per gallon" and "horsepower". The corr method of a dataframe returns the correlation matrix with the correlation coefficients between all variables in the dataframe. You will specify to only return the matrix for the three variables. MPG 35 30 25 20 15 10

In [5]: Click the block of code below and hit the Run button above. # create correlation matrix for mpg, wt, and hp. # The correlation coefficient between mpg and wt is contained in the cell for mpg row and wt colum # The correlation coefficient between mpg and hp is contained in the cell for mpg row and hp columr mpg_wt_corr cars_df [['mpg', 'wt', 'hp']]. corr() print(mpg_wt_corr) = mpg wt hp mpg 1.000000 -0.858218 -0.769713 wt -0.858218 1.000000 0.655805 hp 0.769713 0.655805 1.000000 Step 5: Multiple regression model to predict miles per gallon using weight and horsepower This block of code produces a multiple regression model with "miles per gallon" as the response variable, and "weight" and "horsepower" as predictor variables. The ols method in statsmodels.formula.api submodule returns all statistics for this multiple regression model. Click the block of code below and hit the Run button above.

In [6]: from statsmodels.formula.api import ols # create the multiple regression model with mpg as the response variable; weight and horsepower as model = ols('mpg ~ wt+hp', data=cars_df).fit() print(model.summary()) OLS Regression Results ====== ====== ===== mpg R-squared: Dep. Variable: Model: 0.812 0.798 OLS Adj. R-squared: F-statistic: Method: Least Squares 58.17 Date: Sun, 05 Jun 2022 1.63e-10 Prob (F-statistic): Log-Likelihood: Time: 15:02:54 -70.541 No. Observations: 30 AIC: 147.1 151.3 Df Residuals: 27 BIC: Df Model: 2 Covariance Type: nonrobust ===== t P>|t| 0.975] Intercept 21.217 0.000 41.123 wt -5.605 0.000 -2.539 hp -3.281 0.003 -0.012 Omnibus: Durbin-Watson: 2.004 DL/A 21... - \ . coef 37.4971 -4.0053 -0.0311 std err 1.767 0.715 0.009 5.129 [0.025 33.871 -5.471 -0.051

147.1 No. Observations: Df Residuals: Df Model: 151.3 Covariance Type: P>|t| 0.975] Intercept 0.000 41.123 wt 0.000 -2.539 hp 0.003 -0.012 ==== Omnibus: 5.129 Durbin-Watson: 2.004 Prob (Omnibus): 0.077 Jarque-Bera (JB): 3.953 Skew: 0.882 Prob(JB): 0.139 Kurtosis: 3.222 Cond. No. 610. ===== Warnings: [1] Standard Errors assume that the covariance matrix of the errors is correctly specified. coef 37.4971 -4.0053 -0.0311 AIC: BIC: t 21.217 -5.605 -3.281 std err 1.767 0.715 0.009 30 27 2 nonrobust [0.025 33.871 -5.471 -0.051