Question: Load the data stored in the tab - delimited file nyc . txt into a DataFrame named nyc . Use head ( ) to display

Load the data stored in the tab-delimited file nyc.txt into a DataFrame named nyc. Use head() to display the first 10
rows of this DataFrame.
The columns contained in this DataFrame are described below.
Price The average price in US dollars for a meal for two.
Food The Zagat customer rating of the quality of the food. On a scale from 130.
Decor The Zagat customer rating of the quality of the decor. On a scale from 130.
Service The Zagat customer rating of the quality of the service. On a scale from 130.
Wait The average wait time, in minutes, to be seated during dinner rush on a Friday evening.
East A binary variable indicating if the restaurant is East (1) or West (0) of 5th Avenue.
Our goal in this problem will be to create a linear regression model to predict the value of Price using the other five
columns as features.
2
Perform the following steps in a single code cell:
Create a 2D feature array named X1 containing the relevant features, as well as a 1D label array named y1
containing the labels. (Note: These should be arrays, and not DataFrames or Series. See note below.)
Use train_test_split() to split the data into training and testing sets using an 80/20 split. Name the
resulting arrays X_train_1, X_test_1, y_train_1, and y_test_1. Set random state=1.
Print the shapes of X_train_1 and X_test_1. Include text labeling the two results as shown below. Add
spacing to ensure that the shape tuples are left-aligned.
Training Features Shape: xxxx
Test Features Shape: xxxx
Note: You can extract a NumPy array from a pandas DataFrame or series object by adding .values to the end of it. For
example, if df is a DataFrame object, if you run the statement X = df.iloc[:, some_columns].values, then X will
be a 2D array containing the information for the selected columns.
We will now create a linear regression model that can be used to estimate the price at a similar restaurant.
Create a linear regression model named nyc_mod and then fit it to the training data. Display the intercepts and
coefficients for the final model with text labels as shown below. Add spacing to ensure that the values replacing the
xxxx characters are left-aligned. The intercept should appear as a single number, The coefficients should be in the form
of an array and should be displayed on a single line.
Intercept: xxxx
Coefficients: xxxx
We will now calculate the r-squared score for the model on both the training set and the test set.
Calculate and print the training and testing r-squared values for your model, rounded to four decimal places. Include the
text labels explaining which value is which, as shown below. Add spacing to ensure that the scores are left-aligned.
Training r-Squared: xxxx
Testing r-Squared: xxxx
We will now use the model to generate predictions for the restaurants in the test set.
Use your model to generate price estimates based on the feature values in the test set. Store the results in a variable
named test_pred_1. Print the first 10 observed y-values for the test set, and then the first 10 predictions, rounded to
2 decimal places. Include text labels with your output as shown below. Each price array should be displayed on a single
line, and the two arrays should be left-aligned.
Observed Prices: xxxx
Estimated Prices: xxxx
Suppose that you wish to use the model to estimate the price for three new restaurants that were not included in the
original dataset. Assume that the feature values for these restaurants are as follows:
Food Decor Service Wait East
221220150
181922341
252218360
Create a DataFrame named nyc_new that contains the feature values for these 3 restaurants. Pass this DataFrame to
the predict() method of your model, storing the results in a variable named new_pred_1. Print the price predictions
stored in this variable, rounded to 2 decimal places, with a message as shown below.
Estimated Prices: xxxx

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!