<jupyter_start><jupyter_text>**Creating processing Engine**<jupyter_code>from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler, OneHotEncoder
categorical_transformer = Pipeline(steps=[('onehot', OneHotEncoder(handle_unknown='ignore'))])
numeric_transformer = Pipeline(steps=[('scaler', StandardScaler())])
numeric_features = X.select_dtypes(include=['int64', 'float64']).columns
categorical_features = X.select_dtypes(include=['object']).columns
from sklearn.compose import ColumnTransformer
preprocessor = ColumnTransformer(
    transformers=[
        ('num', numeric_transformer, numeric_features),
        ('cat', categorical_transformer, categorical_features)])<jupyter_output><empty_output><jupyter_text>**Modelling and prediction with pipeline**<jupyter_code># Importing necessary libraries
from sklearn.decomposition import PCA
from sklearn.linear_model import LogisticRegression

# Creating the estimator pipeline for model building
estimator = Pipeline(steps=[('preprocessor', preprocessor),
                      ('dimred', PCA(10)),
                           ('clf',LogisticRegression(random_state=123))])
# Fitting the modelling pipeline on the training set
estimator.fit(X_train,y_train)

# Creating the score on the test set
estimator.score(X_test, y_test)
# Generating the predictions on test set
pred = estimator.predict(X_test)
# Printing the classification report
from sklearn.metrics import classification_report

print(classification_report(pred,y_test))
# Generating confusion matrix
from sklearn.metrics import confusion_matrix

confusionMatrix = confusion_matrix(y_test, pred)
print(confusionMatrix)<jupyter_output>[[96 11]
 [11 78]]
{'fraction_non_alphanumeric': 0.09881656804733728, 'fraction_numerical': 0.010059171597633136, 'mean_word_length': 6.901869158878505, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '214976', 'license': 'MIT', 'n_tokens_mistral': 500, 'n_tokens_neox': 473, 'n_words': 112, 'path': 'Chapter16/Exercise16.04/Exercise_16_04_Model_building_using_Pipeline_v1_0.ipynb', 'repo_name': 'khieunguyen/The-Data-Science-Workshop', 'size': '1690'}