Sure!
All i did was multiply the column of the negative channel by -1 and input it as a channel variable along all others.
X[channel5]=X[channel5]*-1
Here is the error i get when trying to run mmm.fit
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[34], line 4
1 X = df_train.drop(kpi,axis=1)
2 y = df_train[kpi]
----> 4 mmm.fit(X=X, y=y, target_accept=0.95, chains=4, random_seed=42)
File /opt/conda/lib/python3.11/site-packages/pymc_marketing/model_builder.py:511, in ModelBuilder.fit(self, X, y, progressbar, predictor_names, random_seed, **kwargs)
509 y = np.zeros(X.shape[0])
510 y_df = pd.DataFrame({self.output_var: y})
--> 511 self.generate_and_preprocess_model_data(X, y_df.values.flatten())
512 if self.X is None or self.y is None:
513 raise ValueError("X and y must be set before calling build_model!")
File /opt/conda/lib/python3.11/site-packages/pymc_marketing/mmm/delayed_saturated_mmm.py:126, in BaseDelayedSaturatedMMM.generate_and_preprocess_model_data(self, X, y)
124 self.model_coords = coords
125 if self.validate_data:
--> 126 self.validate("X", X_data)
127 self.validate("y", y)
128 self.preprocessed_data: Dict[str, Union[pd.DataFrame, pd.Series]] = {
129 "X": self.preprocess("X", X_data),
130 "y": self.preprocess("y", y),
131 }
File /opt/conda/lib/python3.11/site-packages/pymc_marketing/mmm/base.py:129, in BaseMMM.validate(self, target, data)
126 validation_methods = self.validation_methods[1]
128 for method in validation_methods:
--> 129 method(self, data)
File /opt/conda/lib/python3.11/site-packages/pymc_marketing/mmm/validating.py:63, in ValidateChannelColumns.validate_channel_columns(self, data)
59 raise ValueError(
60 f"channel_columns {self.channel_columns} contains duplicates"
61 )
62 if (data.filter(list(self.channel_columns)) < 0).any().any():
---> 63 raise ValueError(
64 f"channel_columns {self.channel_columns} contains negative values"
65 )
ValueError: channel_columns ['channel1','channel2','channel3','channel4','channel5'] contains negative values
The validate_channel_columns function seems to block negative values in the channel data.