Skip to content

Generate raw data#54

Open
franciscojavierarceo wants to merge 7 commits into
rh-aiservices-bu:mainfrom
franciscojavierarceo:generate-raw-data
Open

Generate raw data#54
franciscojavierarceo wants to merge 7 commits into
rh-aiservices-bu:mainfrom
franciscojavierarceo:generate-raw-data

Conversation

@franciscojavierarceo

Copy link
Copy Markdown

Resolves #53

Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
Comment thread data/generate_raw_data.py Outdated
Co-authored-by: Helber Belmiro <helber.belmiro@gmail.com>
Comment thread data/generate_raw_data.py
transactions_before["transaction_timestamp"] < transactions_before["created_x"]
]
transactions_before["days_between_transactions"] = (
transactions_before["transaction_timestamp"] - transactions_before["created_x"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
transactions_before["transaction_timestamp"] - transactions_before["created_x"]
abs(transactions_before["transaction_timestamp"] - transactions_before["created_x"])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently generates negative values, causing the "days_since_last_transaction" and "days_since_first_transaction" to get mixed up.

Comment thread data/generate_raw_data.py
df = pd.concat([train, test, valid], axis=0).reset_index(drop=True)

df["user_id"] = [f"user_{i}" for i in range(df.shape[0])]
df["transaction_id"] = [f"txn_{i}" for i in range(df.shape[0])]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This transaction_id seems to not be used again later and is not part of the output parquets.
Should it be added as a column in transactions_list in generate_random_transactions?

Comment thread data/generate_raw_data.py

print("generating transaction level data...")
user_purchase_history = generate_random_transactions(
users_df=df[df["repeat_retailer"] == 1].reset_index(drop=True),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im curious, why we only are using data from when they have purchased multiple times from the same retailer?

Comment thread data/generate_raw_data.py
days_since_first_transaction=("days_between_transactions", "max"),
)
.reset_index()
.fillna(0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.fillna(0)

@RHRolun RHRolun Feb 11, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still leaves NaNs in the dataframe, applying fillna(0) on the final_df fixes this issue

Comment thread data/generate_raw_data.py
.reset_index(drop=True)
.drop("created_x", axis=1)
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final_df = final_df.fillna(0)

Comment thread data/generate_raw_data.py


if __name__ == "__main__":
main()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR!
Just so I understand this correctly - do you think this should come in as its own data prep section, or that the parquet files this code produces should exist ahead of time and just be used during training/inference?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhance underlying example data to showcase more complicated features

3 participants