Question
Q3.2 - Linear Regression Classifier Q3.2.1 - Classification Train the Linear Regression classifier on the dataset. You will provide the accuracy for both the test
Q3.2 - Linear Regression Classifier
Q3.2.1 - Classification
Train the Linear Regression classifier on the dataset. You will provide the accuracy for both the test and train sets. Make sure that you round your predictions to a binary value of 0 or 1. Do not use np.round function as it can produce results that surprise you and not meet your needs (see the official numpy documentation for details). Instead, we recommend you custom round function using if-else. See the Jupyter notebook for more information. Linear regression is most commonly used to solve regression problems. The exercise here demonstrates the possibility of using linear regression for classification (even though it may not be the optimal model choice).
#export
class LinearRegressionModel():
# points [2]
def linearClassifier(self,x_train, x_test, y_train):
# TODO: Create a LinearRegression classifier and train it.
# args: pandas dataframe, pandas dataframe, pandas series
# return: numpy array, numpy array
# -------------------------------
# ADD CODE HERE
# -------------------------------
return y_predict_train, y_predict_test
# points [1]
def lgTrainAccuracy(self,y_train,y_predict_train):
# TODO: Return accuracy (on the training set) using the accuracy_score method.
# Note: Round the output values greater than or equal to 0.5 to 1 and those less than 0.5 to 0. You can use any method that satisfies the requriements.
# args: pandas series, numpy array
# return: float
# -------------------------------
# ADD CODE HERE
# -------------------------------
return train_accuracy
# points [1]
def lgTestAccuracy(self,y_test,y_predict_test):
# TODO: Return accuracy (on the testing set) using the accuracy_score method.
# Note: Round the output values greater than or equal to 0.5 to 1 and those less than 0.5 to 0. You can use any method that satisfies the requriements.
# args: pandas series, numpy array
# return: float
# -------------------------------
# ADD CODE HERE
# -------------------------------
return test_accuracy
##################################################
##### Do not add anything below this line ########
tests.linearTest(Data,LinearRegressionModel)
##################################################
Step by Step Solution
3.44 Rating (147 Votes )
There are 3 Steps involved in it
Step: 1
from sklearnlinearmodel import Linear Regression from sklearnmetrics im...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started