1. Define an instance of Sklearn's Pipeline class which applies the standardization class and then the AddBias class. Store the output into feature_pipe. 1. Hint: Recall the Pipeline class takes in a list of tuples where each tuple contains two elements: string and a class instance. 2. Hint: You can set the first element of each tuple to whatever string you would like. 2. Call the fit_transform() method for our feature_pipe instance and pass our x_trn data to be fitted and then transformed. Store the output into x_trn_clean. 3. Call the transform() method for our feature_pipe instance and pass our x_v1d data to be transformed. Store the output into X_vld_clean. 4. Call the transform() method for our feature_pipe instance and pass our x_tst data to be transformed. Store the output into X tst clean
1. Define an instance of Sklearn's Pipeline class which applies the standardization class and then the AddBias class. Store the output into feature_pipe. 1. Hint: Recall the Pipeline class takes in a list of tuples where each tuple contains two elements: string and a class instance. 2. Hint: You can set the first element of each tuple to whatever string you would like. 2. Call the fit_transform() method for our feature_pipe instance and pass our x_trn data to be fitted and then transformed. Store the output into x_trn_clean. 3. Call the transform() method for our feature_pipe instance and pass our x_v1d data to be transformed. Store the output into X_vld_clean. 4. Call the transform() method for our feature_pipe instance and pass our x_tst data to be transformed. Store the output into X tst clean
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 5PE
Related questions
Question
def feature_pipeline(
X_trn: pd.DataFrame,
X_vld: pd.DataFrame,
X_tst: pd.DataFrame,
) -> List[pd.DataFrame]:
""" Creates column transformers and pipelines to apply data cleaning and
transfornations to the input features of our data.
Args:
X_trn: train features
X_vld: validation features
X_tst: test features
"""
# TODO 1
feature_pipe =
# TODO 2
X_trn_clean =
# TODO 3
X_vld_clean =
# TODO 4
X_tst_clean =
return X_trn_clean, X_vld_clean, X_tst_clean
defTEST_feature_pipeline():
# Apply feature and label splitting
X, y = feature_label_split(iris_df, label_name='class')
# Apply train, validation and test set splitting
X_trn, y_trn, X_vld, y_vld, X_tst, y_tst = train_valid_test_split(X, y)
# Apply feature cleaning AFTER splitting
X_trn, X_vld, X_tst = feature_pipeline(X_trn, X_vld, X_tst)
print(f"X_trn shape: {X_trn.shape}")
print(f"X_trn type: {type(X_trn)}")
print(f"X_vld shape: {X_vld.shape}")
print(f"X_vld type: {type(X_vld)}")
print(f"X_tst shape: {X_tst.shape}")
print(f"X_tst type: {type(X_tst)}")
display(X_trn)
todo_check([
(np.all(np.isclose(X_trn.describe().loc['mean'],[1,0,0,0,0])),"'X_trn' has the wrong mean values"),
(np.all(np.isclose(X_trn.iloc[:3,4],[0.77996804,0.3865691,-0.2690958], rtol=.01)),"'X_trn' has incorrect values"),
(np.all(np.isclose(X_vld.iloc[:3,4],[-0.2690958,0.12430314,-1.31815965], rtol=.01)),"'X_vld' has incorrect values"),
(np.all(np.isclose(X_tst.iloc[:3,4],[-0.00682984,-1.18702667,1.43563294], rtol=.01)),"'X_tst' has incorrect values"),
])
TEST_feature_pipeline()
garbage_collect(['TEST_feature_pipeline'])
![Complete the TODO by finishing the feature_pipeline () function.
1. Define an instance of Sklearn's Pipeline class which applies the standardization class and then the AddBias class. Store the output
into feature_pipe.
1. Hint: Recall the Pipeline class takes in a list of tuples where each tuple contains two elements: string and a class instance.
2. Hint: You can set the first element of each tuple to whatever string you would like.
2. Call the fit_transform() method for our feature_pipe instance and pass our x_trn data to be fitted and then transformed.Store the
output into x_trn_clean.
3. Call the transform() method for our feature_pipe instance and pass our x_vld data to be transformed. Store the output into
X_vld_clean.
4. Call the transform() method for our feature_pipe instance and pass our x_tst data to be transformed. Store the output into
X_tst_clean.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Faf74fb9e-b533-4057-a79c-37c4b56e1189%2Fae786b0b-3b83-4e71-87b3-54c9e702dda4%2Fuqcej3i_processed.png&w=3840&q=75)
Transcribed Image Text:Complete the TODO by finishing the feature_pipeline () function.
1. Define an instance of Sklearn's Pipeline class which applies the standardization class and then the AddBias class. Store the output
into feature_pipe.
1. Hint: Recall the Pipeline class takes in a list of tuples where each tuple contains two elements: string and a class instance.
2. Hint: You can set the first element of each tuple to whatever string you would like.
2. Call the fit_transform() method for our feature_pipe instance and pass our x_trn data to be fitted and then transformed.Store the
output into x_trn_clean.
3. Call the transform() method for our feature_pipe instance and pass our x_vld data to be transformed. Store the output into
X_vld_clean.
4. Call the transform() method for our feature_pipe instance and pass our x_tst data to be transformed. Store the output into
X_tst_clean.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
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.Recommended textbooks for you
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning