the following snippet showcases the function to one hot encode categorical variablesbased on methodologies we discussed in detail in feature engineering and selection def fit_transform_ohe(df,col_name)"""this function performs one hot encoding for the specified column argsdf(pandas dataframe)the data frame containing the mentioned column name col_namethe column to be one hot encoded returnstuplelabel_encoderone_hot_encodertransformed column as pandas series ""label encode the column le preprocessing labelencoder(le_labels le fit_transform(df[col_name]df[col_name+'_label'le_labels one hot encoding ohe preprocessing onehotencoder(feature_arr ohe fit_transform(df[[col_name+'_label']]toarray(feature_labels [col_name+' '+str(cls_labelfor cls_label in le classes_features_df pd dataframe(feature_arrcolumns=feature_labelsreturn le,ohe,features_df we use the fit_transform_ohe(function along with transform_ohe(to encode the categoricals the label and one hot encoders are available as part of scikit-learn' preprocessing module ##note we will be using scikit and sklearn interchangeably in the coming sections as discussed in the earlier we usually divide the dataset at hand into training and testing sets to evaluate the performance of our models in this case as wellwe use scikit-learn' train_test_split(function available through model_selection module we split our dataset into and as train and testrespectively the following snippet showcases the same in [ ]xx_testyy_test train_test_split(hour_df iloc[:, :- ]hour_df iloc[:,- ]test_size= random_state= reset_index(inplace=truey reset_index(x_test reset_index(inplace=truey_test y_test reset_index(