SlideShare a Scribd company logo
I just need answers for all TODO. I do not need any explanation or any other details. Just
only answer for all TODO.
TODO 6
To complete the TODO finish the below AddPolynomialFeatures class. The below class works
by computing the polynomial feature transform from the passed data and creating/returning a
new DataFrame containing both old and new polynomial features. The class takes in an
argument called degree which determines the degree of the polynomial that will be computed.
Compute the polynomial for the current feature column_name based on the current degree d. To
do so, you need to index data X at the current column using the name of the column stored in
column_name. Once you index the current feature's/column's data, you need to raise data to the
current power determined by d. Store the output into degree_feat.
Hint: To raise data to a given power you can use the ** syntax (ref) or you can use NumPy's
power() function (docs).
Append the degree_name to the column_names list using its append() method.
Append the degree_feat to the features list using its append() method.
Concatenate our old and new polynomial features into a new DataFrame using Panda's concat()
function (docs).
Hint: Be sure to specify the correct axis for the axis argument! We want to concatenate our
features so that they are side-by-side. Meaning, they are stacked column-wise!
class AddPolynomialFeatures(BaseEstimator, TransformerMixin):
def __init__(self, degree):
self.feature_names = None
self.degree = degree
def fit(self, X: pd.DataFrame) -> None:
return self
def transform(self, X: pd.DataFrame) -> pd.DataFrame:
# Return if the degree is only 1 as no transform
# needs to be computed.
if self.degree <= 1:
return X
column_names = []
features = []
for idx, column_name in enumerate(X.columns):
for d in range(1, self.degree+1):
# TODO 6.1
degree_feat =
# Determines the column name for our
# new DataFrame which contains the Polynomial
# and original features.
if d > 1:
degree_name = column_name+f"^{d}"
else:
degree_name = column_name
# TODO 6.2
# TODO 6.3
# TODO 6.4
poly_X =
# Set column names for our new polynomial DataFrame
poly_X.columns = column_names
# Set the new feature names
self.feature_names = poly_X.columns
return poly_X
def get_feature_names_out(self, name=None) -> pd.Series:
return self.feature_names
TODO 7
Complete the TODO by finishing the feature_pipeline() function.
Take note that this function is a little different from our target_pipeline() function. Notice, we
have to use the Sklearn Pipeline class in conjunction with our DataFrameColumnTransformer
class. This is because we want the AddBias and Standardization classes to apply to our entire
data while we want the AddPolynomialFeatures and OneHotEncoding classes to only apply to
certain columns/features.
Recall, we use our DataFrameColumnTransformer class to apply certain data cleaning and
transformations to certain columns. We use Sklearn's Pipeline class to apply certain data
cleaning and transformations to ALL the columns.
To begin, we need to construct our column transformer's data cleaning and transformation stages.
These stages will consist of AddPolynomialFeatures, OneHotEncoding for 'month', and
OneHotEncoding for 'day'. We separate the 'month' and 'day' one-hot encodings in case we want
to drop one of these two features. When encoding them both at the same time we could break the
ColumnTransformer class if we dropped either 'month' or 'day' as it wouldn't be able to find the
feature.Create the polynomial transform stage by appending a tuple to our list col_trans_stages.
The tuple should be defined as follows :
Element 1 should be set to the string 'poly_transform'.
Element 2 should be set an instance of our AddPolynomialFeatures class and pass the
poly_degree argument to determine the degree of the polynomial.
Element 3 should be the names of the features we want the polynomial transform to be applied
to. This is given by the poly_col_names argument.
Next, create the one-hot encoding stage for 'month' by appending a tuple to our list
col_trans_stages. The tuple should be defined as follows
Element 1 should be set to the string 'one_hot_month'.
Element 2 should be set an instance of our OneHotEncoding class.
Element 3 should be set to a list containing the 'month' feature name.
Lastly, create the one-hot encoding stage for 'day' by appending a tuple to our list
col_trans_stages. The tuple should be defined as follows
Element 1 should be set to the string 'one_hot_day'.
Element 2 should be set an instance of our OneHotEncoding class.
Element 3 should be set to a list containing the 'day' feature name.
def feature_pipeline(
X_trn: pd.DataFrame,
X_vld: pd.DataFrame,
X_tst: pd.DataFrame,
poly_degree: int = 1,
poly_col_names: List[str] = []) -> List[pd.DataFrame]:
""" Creates column transformers and pipelines to apply data clean and
transfornations to the input features of our data.
Args:
X_trn: Train data.
X_vld: Validation data.
X_tst: Test data.
poly_degree: Polynomial degrees which is passed to
AddPolynomialFeatures.
poly_col_names: Name of features to apply polynomial
transform to.
"""
col_trans_stages = []
if poly_degree > 1:
col_trans_stages.append(
# TODO 7.1.A
)
if 'month' in X_trn.columns:
col_trans_stages.append(
# TODO 7.1.B
)
if 'day' in X_trn.columns:
col_trans_stages.append(
# TODO 7.1.C
)
# Create DataFrameColumnTransformer that takes in col_trans_stages
feature_col_trans = DataFrameColumnTransformer(col_trans_stages)
# Create a Pipeline that calls our feature_col_trans and
# other transformation classes that apply to ALL data.
feature_pipe = Pipeline([
('col_transformer', feature_col_trans),
('scaler', Standardization()),
('bias', AddBias()),
])
# Fit and transform data
X_trn_clean = feature_pipe.fit_transform(X_trn)
X_vld_clean = feature_pipe.transform(X_vld)
X_tst_clean = feature_pipe.transform(X_tst)
return X_trn_clean, X_vld_clean, X_tst_clean
TODO 8
def reshape_labels(y: np.ndarray) -> np.ndarray:
if len(y.shape) == 1:
y = y.reshape(-1, 1)
return y
def error(y: np.ndarray, y_hat: np.ndarray) -> np.ndarray:
y = reshape_labels(y)
y_hat = reshape_labels(y_hat)
# TODO 8.1
pass # Replace this line with your code
def mse(y: np.ndarray, y_hat: np.ndarray) -> np.ndarray:
y = reshape_labels(y)
y_hat = reshape_labels(y_hat)
# TODO 8.2
pass # Replace this line with your code
def rmse(y: np.ndarray, y_hat: np.ndarray) -> np.ndarray:
y = reshape_labels(y)
y_hat = reshape_labels(y_hat)
# TODO 8.3
pass # Replace this line with your code
def performance_measures(y: np.ndarray, y_hat: np.ndarray) -> Tuple[np.ndarray]:
y = reshape_labels(y)
y_hat = reshape_labels(y_hat)
err = error(y=y, y_hat=y_hat)
sse = np.sum(err**2)
mse_ = mse(y=y, y_hat=y_hat)
rmse_ = rmse(y=y, y_hat=y_hat)
return err, sse, mse_, rmse_
TODO 12
Complete the TODO by getting our data, training the OrdinaryLeastSquares class and making
predictions for our training and validation data.
Call the data_prep() function to get our cleaned and transformed data. Store the output into data.
Make sure to pass forestfire_df and the arguments corresponding to the following descriptions:
Return all data as NumPy arrays.
Drop the features 'day', 'ISI', 'DC', 'RH', and 'FFMC' from the data using the drop_features
keyword argument.
Create an instance of the OrdinaryLeastSquares and pass the =10=10 to the model using the lamb
keyword argument. Store the output into ols.
# TODO 12.1
data =
X_trn, y_trn, X_vld, y_vld, _, _, feature_names = data
# TODO 12.2
ols =
ols.fit(X_trn, y_trn)
y_hat_trn = ols.predict(X_trn)
_, trn_sse, trn_mse, trn_rmse = analyze(
y=y_trn,
y_hat=y_hat_trn,
title="Training Predictions Log Transform",
dataset="Training",
xlabel="Data Sample Index",
ylabel="Predicted Log Area"
)
todo_check([
(isinstance(X_trn, np.ndarray), 'X_trn is not of type np.ndarray'),
(np.isclose(trn_rmse, 1.34096, rtol=.01), "trn_rmse value is possibly incorrect!"),
(np.all(np.isclose(ols.w[:3].flatten(), [ 1.1418, -0.03522, -0.0148 ], rtol=0.01)), 'ols.w weights
possibly contain incorrect values!')
])
Complete the following TODO by finishing the , , functions. 1. Compute the error (difference)
between our predictions and . Return the output. 2. Compute the MSE between our predictions
and y . Return the output. A. Hint: Use the function to compute the mean of the squared error!
MSE = m 1 i = 0 m ( y ^ y ) 2 3. Compute the RMSE between our predictions y _ hat and y .
Return the output. RMSE = m 1 i = 0 m ( y ^ y ) 2 Below we also define a function called
performance_measures () which will compute and return our errors, SSE, MSE, and RMSE!

More Related Content

PDF
Data Preprocessing Cheatsheet for learners
PDF
Python Cheat Sheet for Data Analysis.pdf
PDF
Machine Learning Algorithms
PDF
AI&BigData Lab.Руденко Петр. Automation and optimisation of machine learning ...
PDF
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
PDF
python sheat sheet for Data analysis.pdf
PDF
Python Cheat Sheet for Data Analysis.pdf
PDF
Machine Learning with Python
Data Preprocessing Cheatsheet for learners
Python Cheat Sheet for Data Analysis.pdf
Machine Learning Algorithms
AI&BigData Lab.Руденко Петр. Automation and optimisation of machine learning ...
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
python sheat sheet for Data analysis.pdf
Python Cheat Sheet for Data Analysis.pdf
Machine Learning with Python

Similar to I just need answers for all TODO- I do not need any explanation or any.pdf (20)

PPTX
Python Cheat Sheet Presentation Learning
PDF
Assessing the Stability and Performance of Linear and Polynomial Regression M...
PPTX
Unit 4_Working with Graphs _python (2).pptx
PDF
Converting Scikit-Learn to PMML
PDF
TDC2017 | São Paulo - Trilha Java EE How we figured out we had a SRE team at ...
DOCX
AIMLProgram-6 AIMLProgram-6 AIMLProgram-6 AIMLProgram-6
PPTX
Working with Graphs _python.pptx
PPTX
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
PDF
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
PPTX
wk5ppt1_Titanic
DOC
0_ML lab programs updated123 (3).1687933796093.doc
PDF
Cheat-Sheets. Model Development in Python.pdf
PPTX
Data Preprocessing
PDF
pandas dataframe notes.pdf
PDF
Introduction to Spark ML Pipelines Workshop
PDF
Machinelearning Spark Hadoop User Group Munich Meetup 2016
PDF
lab program 6.pdf
PPTX
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scala
PDF
Data science using python, Data Preprocessing
PDF
Data Analytics ,Data Preprocessing What is Data Preprocessing?
Python Cheat Sheet Presentation Learning
Assessing the Stability and Performance of Linear and Polynomial Regression M...
Unit 4_Working with Graphs _python (2).pptx
Converting Scikit-Learn to PMML
TDC2017 | São Paulo - Trilha Java EE How we figured out we had a SRE team at ...
AIMLProgram-6 AIMLProgram-6 AIMLProgram-6 AIMLProgram-6
Working with Graphs _python.pptx
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
wk5ppt1_Titanic
0_ML lab programs updated123 (3).1687933796093.doc
Cheat-Sheets. Model Development in Python.pdf
Data Preprocessing
pandas dataframe notes.pdf
Introduction to Spark ML Pipelines Workshop
Machinelearning Spark Hadoop User Group Munich Meetup 2016
lab program 6.pdf
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scala
Data science using python, Data Preprocessing
Data Analytics ,Data Preprocessing What is Data Preprocessing?
Ad

More from MattU5mLambertq (20)

PDF
I want you to add the output of the F1 score- Precision- ROC AUC- and.pdf
PDF
I would appreciate it if you can explain how you got the answers- Than (3).pdf
PDF
I use the below scapy code to sniff and then spoof on the IP addresses.pdf
PDF
I try to change the port number ut this error appears(MongoServerError.pdf
PDF
I tried graphing each function on Desmos but I'm still confused as to.pdf
PDF
I need some help with part A and B- Thank you! 4) Use truth tables to.pdf
PDF
I need help with the moveStudentsFromChairToLine() method- This method.pdf
PDF
If fur color in mice is determined polygenicly by the alleles A and B-.pdf
PDF
If MX(t)---70-(1-3et)-5 what is the distribution of X -.pdf
PDF
if I had a merge sort function in python and I wish to count each time.pdf
PDF
If Clare has no T-helper cells- she would have Impaired cell-mediated.pdf
PDF
if arbitrageurs notice a price discrepancy between the dollar and the.pdf
PDF
If Bowen Co- has a return on assets of 11 percent and also a return on.pdf
PDF
If a fly landed on animal feces- picked up Salmonella on its feet- and.pdf
PDF
If a patient is found to have Lynch syndrome- what are the chances tha.pdf
PDF
Identification and Documentation of a Business Process 1- Identify a b.pdf
PDF
Identify each image- Header Footer Page Layout View Normal View.pdf
PDF
identify rocks Metamorphic Grade- Foliated Only Classification I- Met.pdf
PDF
Identify the inference rule- U+ABUU(A)+BIdentify the inference rule-.pdf
PDF
identify which bone is displayed below-.pdf
I want you to add the output of the F1 score- Precision- ROC AUC- and.pdf
I would appreciate it if you can explain how you got the answers- Than (3).pdf
I use the below scapy code to sniff and then spoof on the IP addresses.pdf
I try to change the port number ut this error appears(MongoServerError.pdf
I tried graphing each function on Desmos but I'm still confused as to.pdf
I need some help with part A and B- Thank you! 4) Use truth tables to.pdf
I need help with the moveStudentsFromChairToLine() method- This method.pdf
If fur color in mice is determined polygenicly by the alleles A and B-.pdf
If MX(t)---70-(1-3et)-5 what is the distribution of X -.pdf
if I had a merge sort function in python and I wish to count each time.pdf
If Clare has no T-helper cells- she would have Impaired cell-mediated.pdf
if arbitrageurs notice a price discrepancy between the dollar and the.pdf
If Bowen Co- has a return on assets of 11 percent and also a return on.pdf
If a fly landed on animal feces- picked up Salmonella on its feet- and.pdf
If a patient is found to have Lynch syndrome- what are the chances tha.pdf
Identification and Documentation of a Business Process 1- Identify a b.pdf
Identify each image- Header Footer Page Layout View Normal View.pdf
identify rocks Metamorphic Grade- Foliated Only Classification I- Met.pdf
Identify the inference rule- U+ABUU(A)+BIdentify the inference rule-.pdf
identify which bone is displayed below-.pdf
Ad

Recently uploaded (20)

PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
RMMM.pdf make it easy to upload and study
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
Microbial disease of the cardiovascular and lymphatic systems
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PPTX
Lesson notes of climatology university.
PPTX
master seminar digital applications in india
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Complications of Minimal Access Surgery at WLH
Chinmaya Tiranga quiz Grand Finale.pdf
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Supply Chain Operations Speaking Notes -ICLT Program
RMMM.pdf make it easy to upload and study
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Cell Structure & Organelles in detailed.
Microbial disease of the cardiovascular and lymphatic systems
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
A systematic review of self-coping strategies used by university students to ...
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Lesson notes of climatology university.
master seminar digital applications in india
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Anesthesia in Laparoscopic Surgery in India
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Paper A Mock Exam 9_ Attempt review.pdf.
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Complications of Minimal Access Surgery at WLH

I just need answers for all TODO- I do not need any explanation or any.pdf

  • 1. I just need answers for all TODO. I do not need any explanation or any other details. Just only answer for all TODO. TODO 6 To complete the TODO finish the below AddPolynomialFeatures class. The below class works by computing the polynomial feature transform from the passed data and creating/returning a new DataFrame containing both old and new polynomial features. The class takes in an argument called degree which determines the degree of the polynomial that will be computed. Compute the polynomial for the current feature column_name based on the current degree d. To do so, you need to index data X at the current column using the name of the column stored in column_name. Once you index the current feature's/column's data, you need to raise data to the current power determined by d. Store the output into degree_feat. Hint: To raise data to a given power you can use the ** syntax (ref) or you can use NumPy's power() function (docs). Append the degree_name to the column_names list using its append() method. Append the degree_feat to the features list using its append() method. Concatenate our old and new polynomial features into a new DataFrame using Panda's concat() function (docs). Hint: Be sure to specify the correct axis for the axis argument! We want to concatenate our features so that they are side-by-side. Meaning, they are stacked column-wise! class AddPolynomialFeatures(BaseEstimator, TransformerMixin): def __init__(self, degree): self.feature_names = None self.degree = degree def fit(self, X: pd.DataFrame) -> None: return self def transform(self, X: pd.DataFrame) -> pd.DataFrame: # Return if the degree is only 1 as no transform # needs to be computed. if self.degree <= 1: return X column_names = [] features = [] for idx, column_name in enumerate(X.columns):
  • 2. for d in range(1, self.degree+1): # TODO 6.1 degree_feat = # Determines the column name for our # new DataFrame which contains the Polynomial # and original features. if d > 1: degree_name = column_name+f"^{d}" else: degree_name = column_name # TODO 6.2 # TODO 6.3 # TODO 6.4 poly_X = # Set column names for our new polynomial DataFrame poly_X.columns = column_names # Set the new feature names self.feature_names = poly_X.columns return poly_X def get_feature_names_out(self, name=None) -> pd.Series: return self.feature_names TODO 7 Complete the TODO by finishing the feature_pipeline() function. Take note that this function is a little different from our target_pipeline() function. Notice, we have to use the Sklearn Pipeline class in conjunction with our DataFrameColumnTransformer class. This is because we want the AddBias and Standardization classes to apply to our entire data while we want the AddPolynomialFeatures and OneHotEncoding classes to only apply to certain columns/features. Recall, we use our DataFrameColumnTransformer class to apply certain data cleaning and transformations to certain columns. We use Sklearn's Pipeline class to apply certain data cleaning and transformations to ALL the columns.
  • 3. To begin, we need to construct our column transformer's data cleaning and transformation stages. These stages will consist of AddPolynomialFeatures, OneHotEncoding for 'month', and OneHotEncoding for 'day'. We separate the 'month' and 'day' one-hot encodings in case we want to drop one of these two features. When encoding them both at the same time we could break the ColumnTransformer class if we dropped either 'month' or 'day' as it wouldn't be able to find the feature.Create the polynomial transform stage by appending a tuple to our list col_trans_stages. The tuple should be defined as follows : Element 1 should be set to the string 'poly_transform'. Element 2 should be set an instance of our AddPolynomialFeatures class and pass the poly_degree argument to determine the degree of the polynomial. Element 3 should be the names of the features we want the polynomial transform to be applied to. This is given by the poly_col_names argument. Next, create the one-hot encoding stage for 'month' by appending a tuple to our list col_trans_stages. The tuple should be defined as follows Element 1 should be set to the string 'one_hot_month'. Element 2 should be set an instance of our OneHotEncoding class. Element 3 should be set to a list containing the 'month' feature name. Lastly, create the one-hot encoding stage for 'day' by appending a tuple to our list col_trans_stages. The tuple should be defined as follows Element 1 should be set to the string 'one_hot_day'. Element 2 should be set an instance of our OneHotEncoding class. Element 3 should be set to a list containing the 'day' feature name. def feature_pipeline( X_trn: pd.DataFrame, X_vld: pd.DataFrame, X_tst: pd.DataFrame, poly_degree: int = 1, poly_col_names: List[str] = []) -> List[pd.DataFrame]: """ Creates column transformers and pipelines to apply data clean and transfornations to the input features of our data. Args: X_trn: Train data.
  • 4. X_vld: Validation data. X_tst: Test data. poly_degree: Polynomial degrees which is passed to AddPolynomialFeatures. poly_col_names: Name of features to apply polynomial transform to. """ col_trans_stages = [] if poly_degree > 1: col_trans_stages.append( # TODO 7.1.A ) if 'month' in X_trn.columns: col_trans_stages.append( # TODO 7.1.B ) if 'day' in X_trn.columns: col_trans_stages.append( # TODO 7.1.C ) # Create DataFrameColumnTransformer that takes in col_trans_stages feature_col_trans = DataFrameColumnTransformer(col_trans_stages) # Create a Pipeline that calls our feature_col_trans and # other transformation classes that apply to ALL data. feature_pipe = Pipeline([ ('col_transformer', feature_col_trans), ('scaler', Standardization()), ('bias', AddBias()), ])
  • 5. # Fit and transform data X_trn_clean = feature_pipe.fit_transform(X_trn) X_vld_clean = feature_pipe.transform(X_vld) X_tst_clean = feature_pipe.transform(X_tst) return X_trn_clean, X_vld_clean, X_tst_clean TODO 8 def reshape_labels(y: np.ndarray) -> np.ndarray: if len(y.shape) == 1: y = y.reshape(-1, 1) return y def error(y: np.ndarray, y_hat: np.ndarray) -> np.ndarray: y = reshape_labels(y) y_hat = reshape_labels(y_hat) # TODO 8.1 pass # Replace this line with your code def mse(y: np.ndarray, y_hat: np.ndarray) -> np.ndarray: y = reshape_labels(y) y_hat = reshape_labels(y_hat) # TODO 8.2 pass # Replace this line with your code def rmse(y: np.ndarray, y_hat: np.ndarray) -> np.ndarray: y = reshape_labels(y) y_hat = reshape_labels(y_hat) # TODO 8.3 pass # Replace this line with your code def performance_measures(y: np.ndarray, y_hat: np.ndarray) -> Tuple[np.ndarray]: y = reshape_labels(y) y_hat = reshape_labels(y_hat) err = error(y=y, y_hat=y_hat) sse = np.sum(err**2) mse_ = mse(y=y, y_hat=y_hat) rmse_ = rmse(y=y, y_hat=y_hat) return err, sse, mse_, rmse_ TODO 12
  • 6. Complete the TODO by getting our data, training the OrdinaryLeastSquares class and making predictions for our training and validation data. Call the data_prep() function to get our cleaned and transformed data. Store the output into data. Make sure to pass forestfire_df and the arguments corresponding to the following descriptions: Return all data as NumPy arrays. Drop the features 'day', 'ISI', 'DC', 'RH', and 'FFMC' from the data using the drop_features keyword argument. Create an instance of the OrdinaryLeastSquares and pass the =10=10 to the model using the lamb keyword argument. Store the output into ols. # TODO 12.1 data = X_trn, y_trn, X_vld, y_vld, _, _, feature_names = data # TODO 12.2 ols = ols.fit(X_trn, y_trn) y_hat_trn = ols.predict(X_trn) _, trn_sse, trn_mse, trn_rmse = analyze( y=y_trn, y_hat=y_hat_trn, title="Training Predictions Log Transform", dataset="Training", xlabel="Data Sample Index", ylabel="Predicted Log Area" ) todo_check([ (isinstance(X_trn, np.ndarray), 'X_trn is not of type np.ndarray'), (np.isclose(trn_rmse, 1.34096, rtol=.01), "trn_rmse value is possibly incorrect!"), (np.all(np.isclose(ols.w[:3].flatten(), [ 1.1418, -0.03522, -0.0148 ], rtol=0.01)), 'ols.w weights possibly contain incorrect values!') ]) Complete the following TODO by finishing the , , functions. 1. Compute the error (difference) between our predictions and . Return the output. 2. Compute the MSE between our predictions and y . Return the output. A. Hint: Use the function to compute the mean of the squared error! MSE = m 1 i = 0 m ( y ^ y ) 2 3. Compute the RMSE between our predictions y _ hat and y .
  • 7. Return the output. RMSE = m 1 i = 0 m ( y ^ y ) 2 Below we also define a function called performance_measures () which will compute and return our errors, SSE, MSE, and RMSE!