Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribedimage text in transcribed

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?
image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
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 humpy 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 . csy data set. cars of orig - pd.read cav( https://s3-us west-2. amazonaws. com/data-analytics. zybooks.com/mtcars . csy") # randomly pick 30 observations from the data set to make the data set unique to you cars df - cars of 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) \ ") display (HTML( cars_df. head( ) . to_html()) ) Cars data frame (showing only the first five observations) Unnamed: 0 mpg cyl disp hp drat wt qsec vs am gear carb 4 Hornet Sportabout 18.7 8 360.0 175 3 15 3 44 17.02 0 21 Dodge Challenger 15 5 8 318 0 150 276 3.52 16 87 0 13 2 12 Merc 450SL 17 3 8 275 8 180 3 07 3,73 17 60 O 3 13 Merc 280 19.2 6 167 6 123 3,92 3 44 18 30 4 Merc 240D 24.4 4 1467 62 3 69 3 19 20.00 2Step 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. In [3] : import matplotlib. pyplot as plt # create scatterplot of variables mpg against wt. pit. plot(cars_df["wt"], cars_df["mpg"], "o , color- red') # set a title for the plot, x-axis, and y-axis. pit. title('MPG against Weight') pit.xlabel( 'Weight (1000s 1bs) ') pit . ylabel( 'MPG') # show the plot. pit . show( ) MPG against Weight 35 MPG 15 15 2.0 25 30 35 4.0 45 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 mog 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. In [4]: import matplotlib. pyplot as pit # create scatterplot of variables mog against hp. pit.plot (cars_df ["hp"], cars_df["mpg"], o , color- blue") # set a title for the plot, x-axis, and y-axis. pit. title( "MPG against Horsepower]) pit. xlabel( 'Horsepower") pit .ylabel( "MPG ) # show the plot. pit . show() MPG against Horsepower 35 25 MPG 20 10 50 100 150 200 250 300 Horsepower Cjupyter Module Six Discussion Last Checkpoint. 09/12/2019 (autosaved) File Edit View Insert Cell Kernel Widgets Help Trusted Python 3 0 TA H Run Code SU 2UU 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. Click the block of code below and hit the Run button above In [5] : # create correlation matrix for mpg, wt, and ap. # The correlation coefficient between mpg and wt is contained in the cell for mog row and wt column (or wt row and mpg column). # The correlation coefficient between mog and he is contained in the cell for mog row and hp column (or hp row and mpg column). mpg wt corr - cars of [[ impg , wt , he il . corr() print (mpg_wt_corn) mpg wt hp Impg 1.000000 -0.872545 -0. 784310 wt -0. 872545 961799 0 090060 T hp -0 . 784310 0 . 662196 006000 Tjupyter Module Six Discussion Last Checkpoint 09/12/2019 (autosaved) File Edit View Insert Cell Kernel Widgets Help Trusted Python 3 0 + C Code 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 mog as the response variable, weight and horsepower as predictor variables. model - ols ( mog ~ withp , data-cars of) . fit() print ( model . summary ()) OLS Regression Results Dep. Variable: mpg R- squared: 0.837 Model: OLS Adj. R-squared: 0. 825 Method : Least Squares F-statistic: 69.47 Date: Mon, 05 Dec 2022 Prob (F-statistic) - 2. 26e-11 Time : 02:53 : 24 Log-Likelihood : 69.359 No. Observations 130 AIC: 144 . 7 of Residuals: 27 BIO 148.9 of Model: 2 covariance Type: nonrobust coet std err t Palt 10.025 0.975] Intercept 37 - 2580 1 589 23. 441 0.0ee 33.997 40 . 519 3 . 8324 9631 6.071 -5 .128 -2.537 hp 0.0321 3. 550 0.001 -0 . 051 -0.014 Omnibus : 5. 639 Durbin-Watson: 2. 294 Prob ( Omnibus) 0. 060 Jarque-Bera (JB); 4.401 Skew: 0. 928 Prob ( JB): 0.111 Kurtosis 3. 277 Cond . No. 576- Warnings: [1] Standard Errors assume that the covariance matrix of the errors is correctly specified

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Calculus

Authors: Jon Rogawski, Colin Adams

3rd Edition

1319116442, 9781319116446

More Books

Students also viewed these Mathematics questions