Q3.2 - Linear Regression Classifier Q3.2.1 - Classification Train the Linear Regression classifier on the dataset. You
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 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)
##################################################
Applied Regression Analysis and Other Multivariable Methods
ISBN: 978-1285051086
5th edition
Authors: David G. Kleinbaum, Lawrence L. Kupper, Azhar Nizam, Eli S. Rosenberg