Preview:
# Add the label dummy variabls to the vector X_test_vec_lbl
# create a DataFrame with the dummy variables
dummy_df = test_lbl[["cluster_1", "cluster_2", "cluster_3", "cluster_4", "cluster_5",
                     "cluster_6", "cluster_7", "cluster_8", "cluster_9", "cluster_10",
                     "cluster_11", "cluster_12"]]

# Reshaping the dummy_df to dummy_matrices
for i, col in enumerate(dummy_df.columns):
    # get the column values as a dense numpy array
    col_values = dummy_df[col].values.reshape(-1, 1)
    # stack the column values horizontally with the sparse matrix
    X_test_vec_lbl = hstack([X_test_vec_lbl, col_values], format='csr')

# Size of X_train_vec_lbl after adding 12 dummy variables
print(X_test_vec_lbl.shape)
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter