sklearn.pipeline why code example

Example: sklearn pipeline

from sklearn.model_selection import train_test_split
from sklearn.impute import SimpleImputer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.datasets import make_classification
import pandas as pd

X, y = make_classification(n_samples=25, n_features=4, n_classes=2, random_state=123)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=123)
imputer = SimpleImputer()
clf = LogisticRegression()
pipe = make_pipeline(imputer, clf)

pipe.fit(X_train, y_train)
y_pred = pipe.predict(X_test)

Tags:

Misc Example