Training a Linear Regression Model Let's now begin to train our regression modell We will first need to spit up our data into an x dataframe that contains the features we want to train on, and a y a series with the desired target variable (in this case Price). For this part, we will ignore the Address column because it contains strings which the linear regression model can't use. Defining the X and y arrays x = USAhousing[['Avg. Area Income", 'Avg. Area House Age', 'Avg. Area Number of Rooms', "Avg. Area Number of Bedrooms', 'Area Population']] y = USAhousing[ 'Price'] Question 9 1 Spit both the features x and the target y into training sets x_train, and y_train, respectively, and and into testing sets, x_test and y_test. This is done so that we can train our model on the training sets x_train, and y_train, and then test it on the testing sets x_test and y_test. Split both x and y so that 30% of the data is used for testing, and the remaining 70% for training. Important: Use the function train_test_split and set the random_state equal to 101. from sklearn.model_selection import train_test_split #** GRADED #** YOUR SOLUTION HERE X_train = None X_test - None y_train - None y_test = None #** YOUR CODE HERE #** Answer check print("Train features shape: {)".format(X_train.shape)) print("Train labels shape: {}*.format(y_train.shape)) print("Test features shape: ()".format (X_test.shape)) print("Test features shape: {j".format (y_test.shape)) Question 10 Create and fit a Linear Regression model using x_train and y_train. Save the fitted model in a variable called model. Make sure to import the module LinearRegression from sklearn. Use LinearRegression using the default parameters. *** GRADED from sklearn.linear_model import LinearRegression *** VOUR SOLUTION HERE model - None #** YOUR CODE HERE #** Answer check print("Model intercept: {)".format(model.intercept_)) print("Hodel coefficients: {}".format(model.coef_))

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Training a Linear Regression Model
Let's now begin to train our regression model! We will first need to split up our data into an x dataframe that contains the features we want to train on, and a y a
serles with the desired target variable (in this case Price).
For this part, we will gnore the Address column because it contains strings which the linear regression model can't use.
Defining the X and y arrays
x = USAhousing[['Avg. Area Income', 'Avg. Area House Age', 'Avg. Area Number of Rooms',
y = USAhousing[ 'Price']
Avg. Area Number of Bedrooms', 'Area Population']]
Question 9 1
Split both the features x and the target y into training sets x_train, and y_train, respectively, and and into testing sets, x_test and y_test. This is done so
that we can train our model on the training sets x_train, and y_train, and then test it on the testing sets x_test and y_test. Split both x and y so that 30%
of the data is used for testing, and the remaining 70% for training.
Important: Use the function train_test_split and set the random_state equal to 101.
from sklearn.model_selection import train_test_split
#*# GRADED
#** YOUR SOLUTION HERE
X_train = None
X_test - None
y_train - None
y_test = None
#** YOUR CODE HERE
#** Answer check
print("Train features shape: ()".format(x_train.shape))
print("Train labels shape: {}".format(y_train.shape))
print("Test features shape: {}".format (X_test.shape))
print("Test features shape: {}".format (y_test.shape))
Question 10
Create and fit a Linear Regression model using x_train and y_train. Save the fitted model in a variable called model.
Make sure to import the module LinearRegression from sklearn. Use LinearRegression using the default parameters.
#** GRADED
from sklearn.linear_model import LinearRegression
#** YOUR SOLUTION HERE
model - None
#w* YOUR CODE HERE
www Answer check
print("Model intercept: ()".format (model.intercept_))
print("Model coefficients: {)".format(model.coef_))
Transcribed Image Text:Training a Linear Regression Model Let's now begin to train our regression model! We will first need to split up our data into an x dataframe that contains the features we want to train on, and a y a serles with the desired target variable (in this case Price). For this part, we will gnore the Address column because it contains strings which the linear regression model can't use. Defining the X and y arrays x = USAhousing[['Avg. Area Income', 'Avg. Area House Age', 'Avg. Area Number of Rooms', y = USAhousing[ 'Price'] Avg. Area Number of Bedrooms', 'Area Population']] Question 9 1 Split both the features x and the target y into training sets x_train, and y_train, respectively, and and into testing sets, x_test and y_test. This is done so that we can train our model on the training sets x_train, and y_train, and then test it on the testing sets x_test and y_test. Split both x and y so that 30% of the data is used for testing, and the remaining 70% for training. Important: Use the function train_test_split and set the random_state equal to 101. from sklearn.model_selection import train_test_split #*# GRADED #** YOUR SOLUTION HERE X_train = None X_test - None y_train - None y_test = None #** YOUR CODE HERE #** Answer check print("Train features shape: ()".format(x_train.shape)) print("Train labels shape: {}".format(y_train.shape)) print("Test features shape: {}".format (X_test.shape)) print("Test features shape: {}".format (y_test.shape)) Question 10 Create and fit a Linear Regression model using x_train and y_train. Save the fitted model in a variable called model. Make sure to import the module LinearRegression from sklearn. Use LinearRegression using the default parameters. #** GRADED from sklearn.linear_model import LinearRegression #** YOUR SOLUTION HERE model - None #w* YOUR CODE HERE www Answer check print("Model intercept: ()".format (model.intercept_)) print("Model coefficients: {)".format(model.coef_))
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Hash Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education