0
$\begingroup$

I am aiming to guage the difference in my model performance from using data with and without Sesonality removal. My approach to Seasonality removal is taking the log of the column data and then performing 1-lag Differencing. This results in the first value of the column being NaN, which is then removed after all columns are processed. Also, it may be important to note both datasets are standardized after using sklearn.preprocessing.StandardScaler()

Edit 1: I have found a SO post with a very similar issue, however there are no responses. This is the post here

def remove_seasonality(col, drop=False):
    # check if col is stationary, if stationary skip col.
    if stationary_test(col, test=True) is True:
        return col
    
    # if column not number, skip col
    if not np.issubdtype(col.dtype, np.number): 
        return col

    if (col < 0).any(): # check if contains neg values
        # add constant, make values positive 
        col = col + col.min()
    
    log_values = np.log(col + 1) # add 1 to avoid log(0)
    
    diff = np.diff(log_values, prepend=np.nan)
    
    if drop: 
        diff = diff.dropna()
    
    return diff

I am using a Tensorflow model composed with Convolutional Layers and GRU's, I am using MAE to evaluate my model performance. The problem is that the log-transform and differencing results in a much smaller magnitude of numbers, so I cannot compare the difference in datasets effect on the MAE.

I'm not sure how to rescale my predictions to be able to compare them, I don't think I can perform inverse differencing on my predictions because that operation requires the first value before Differencing - which doesn't exist.

Alternatively, Is there an appropriate metric I could use to evaluate the difference in data preprocessing without performing any rescaling?

$\endgroup$

1 Answer 1

0
$\begingroup$

To find the first value to invert the differencing process, I have used the last data point from the preceding dataset, e.g for my Validation predictions, I used the last value from the Training set. This last value is plugged into this function:

def invert_seasonality(seasonality_vals, last_cum_val):
    invert_vals = np.insert(seasonality_vals, 0, np.log(last_cum_val + 1)).cumsum()
    invert_vals = np.exp(invert_vals) - 1
    
    return invert_vals    
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.