How can I to troubleshoot AttributeError"Can't get attribute '_RemainderColsList' on <module 'sklearn.compose._column_transformer'

# Step 0: Imports

import pandas as pd

import numpy as np

import matplotlib.pyplot as plt

import seaborn as sns

import os

from sklearn.pipeline import Pipeline

from sklearn.compose import ColumnTransformer

from sklearn.impute import SimpleImputer

from sklearn.preprocessing import OneHotEncoder, StandardScaler

from sklearn.ensemble import RandomForestRegressor

from sklearn.linear_model import ElasticNet

from sklearn.model_selection import train_test_split, cross_val_score

from sklearn.metrics import r2_score, mean_absolute_error, root_mean_squared_error, make_scorer

from sklearn.inspection import permutation_importance

import joblib

import warnings

warnings.filterwarnings(“ignore”)

model pipeline

# Numeric transformer: imputation and scaling

numeric_transformer = Pipeline(steps=[

("imputer", SimpleImputer(strategy="median")),

("scaler", StandardScaler())

])

# Categorical transformer: imputation and one-hot encoding

categorical_transformer = Pipeline(steps=[

("imputer", SimpleImputer(strategy="constant", fill_value="missing")),

("onehot", OneHotEncoder(handle_unknown="ignore"))

])

# Combine preprocessing

preprocessor = ColumnTransformer(

transformers=\[

    ("num", numeric_transformer, num_features),

    ("cat", categorical_transformer, cat_features)

\],

remainder="drop"

)

# Define Models

model_rf = RandomForestRegressor(n_estimators=250, random_state=42, n_jobs=-1)

model_enet = ElasticNet(alpha=0.001, l1_ratio=0.1, random_state=42)

# Pipelines

pipe_rf = Pipeline(steps=[

("preprocessor", preprocessor),

("model", model_rf)

])

pipe_enet = Pipeline(steps=[

("preprocessor", preprocessor),

("model", model_enet)

])

The error from the streamlit page when I run “streamlit run app,py”

AttributeError: Can’t get attribute ‘_RemainderColsList’ on <module ‘sklearn.compose._column_transformer’ from ‘C:\\Users\\USER\\kenyan-crop-yield-prediction\\venv\\Lib\\site-packages\\sklearn\\compose\\_column_transformer.py’>

Traceback:

File "C:\Users\USER\kenyan-crop-yield-prediction\crop-prediction\app.py", line 11, in <module>
    pipe = joblib.load("kenya_crop_yield_rf_pipeline.joblib")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\USER\kenyan-crop-yield-prediction\venv\Lib\site-packages\joblib\numpy_pickle.py", line 749, in load obj = _unpickle( ^^^^^^^^^^

File "C:\Users\USER\kenyan-crop-yield-prediction\venv\Lib\site-packages\joblib\numpy_pickle.py", line 626, in _unpickle obj = unpickler.load() ^^^^^^^^^^^^^^^^

File "C:\Program Files\Python312\Lib\pickle.py", line 1205, in load dispatch[key[0]](self)

File "C:\Program Files\Python312\Lib\pickle.py", line 1530, in load_stack_global self.append(self.find_class(module, name)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Program Files\Python312\Lib\pickle.py", line 1574, in find_class return _getattribute(sys.modules[module], name)[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Program Files\Python312\Lib\pickle.py", line 325, in _getattribute raise AttributeError("Can't get attribute {!r} on {!r}"