transforms x test X_seq : log sequence data
(self, X_seq)
| 144 | return X_new |
| 145 | |
| 146 | def transform(self, X_seq): |
| 147 | """ |
| 148 | transforms x test |
| 149 | X_seq : log sequence data |
| 150 | """ |
| 151 | |
| 152 | # loop over each sequence to create the time image |
| 153 | time_images = [] |
| 154 | for block in X_seq: |
| 155 | padded_block = sequence_padder(block, self.max_seq_length) |
| 156 | time_image = windower(padded_block, self.window_size) |
| 157 | time_image_counts = [] |
| 158 | for time_row in time_image: |
| 159 | row_count = Counter(time_row) |
| 160 | time_image_counts.append(row_count) |
| 161 | |
| 162 | time_image_df = pd.DataFrame(time_image_counts, columns=self.events) |
| 163 | time_image_df = time_image_df.reindex(sorted(time_image_df.columns), axis=1) |
| 164 | time_image_df = time_image_df.fillna(0) |
| 165 | time_image_np = time_image_df.to_numpy() |
| 166 | |
| 167 | # resize if too large |
| 168 | if len(time_image_np) > self.num_rows: |
| 169 | time_image_np = resize_time_image( |
| 170 | time_image_np, (self.num_rows, len(self.events)), |
| 171 | ) |
| 172 | |
| 173 | time_images.append(time_image_np) |
| 174 | |
| 175 | # stack all the blocks |
| 176 | X = np.stack(time_images) |
| 177 | |
| 178 | if self.term_weighting == "tf-idf": |
| 179 | |
| 180 | # set up sizing |
| 181 | dim1, dim2, dim3 = X.shape |
| 182 | X = X.reshape(-1, dim3) |
| 183 | |
| 184 | # apply tf-idf |
| 185 | idf_tile = np.tile(self.idf_vec, (dim1 * dim2, 1)) |
| 186 | idf_matrix = X * idf_tile |
| 187 | X = idf_matrix |
| 188 | |
| 189 | # reshape to original dimensions |
| 190 | X = X.reshape(dim1, dim2, dim3) |
| 191 | |
| 192 | X_new = X |
| 193 | print("test data shape: ", X_new.shape) |
| 194 | return X_new |
| 195 | |
| 196 | |
| 197 | if __name__ == "__main__": |