Complete the code to create a simple pipeline that scales data and fits a model.
from sklearn.pipeline import Pipeline from sklearn.preprocessing import StandardScaler from sklearn.linear_model import LogisticRegression pipeline = Pipeline([ ('scaler', StandardScaler()), ('classifier', [1]()) ])
The pipeline uses LogisticRegression as the classifier step. This fits the model after scaling the data.
Complete the code to split data into training and testing sets before building the pipeline.
from sklearn.model_selection import [1] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
The function train_test_split is used to split data into training and testing sets.
Fix the error in the pipeline code by completing the missing step for feature selection.
from sklearn.feature_selection import [1] pipeline = Pipeline([ ('scaler', StandardScaler()), ('selector', SelectKBest(k=10)), ('classifier', LogisticRegression()) ])
The feature selection step uses SelectKBest to select the top 10 features.
Fill both blanks to create a pipeline that scales data and performs cross-validation scoring.
from sklearn.model_selection import [1] from sklearn.preprocessing import [2] from sklearn.linear_model import LogisticRegression from sklearn.pipeline import Pipeline pipeline = Pipeline([ ('scaler', [2]()), ('classifier', LogisticRegression()) ]) scores = [1](pipeline, X, y, cv=5)
The pipeline uses StandardScaler to scale data, and cross_val_score to evaluate the model with cross-validation.
Fill all three blanks to create a pipeline that imputes missing values, scales features, and fits a classifier.
from sklearn.impute import [1] from sklearn.preprocessing import [2] from sklearn.linear_model import LogisticRegression from sklearn.pipeline import Pipeline pipeline = Pipeline([ ('imputer', [1]()), ('scaler', [2]()), ('classifier', LogisticRegression()) ])
The pipeline first imputes missing values using SimpleImputer, then scales features with StandardScaler, and finally fits a logistic regression model.