Skip to content

CI: fix using Kaggle datasets #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions templates/titanic/.meta.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
title: Solving Titanic dataset with Lightning Flash
author: PL team
created: 2021-10-15
updated: 2021-12-10
updated: 2022-04-10
license: CC
build: 0
description: |
This is a template to show how to contribute a tutorial.
requirements:
- https://github.com/PyTorchLightning/lightning-flash/archive/refs/tags/0.5.2.zip#egg=lightning-flash[tabular]
- matplotlib
- lightning-flash[tabular]>=0.7
- torchmetrics<0.8 # collision with `pytorch-tabular` which require PL 1.3.6
- pandas>=1.0
- matplotlib>=3.0
- seaborn
accelerator:
- CPU
Expand Down
19 changes: 14 additions & 5 deletions templates/titanic/tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
target_fields="Survived",
train_file=csv_train,
val_split=0.1,
batch_size=8,
batch_size=32,
)

# %% [markdown]
Expand All @@ -49,7 +49,7 @@
model = TabularClassifier.from_data(
datamodule,
learning_rate=0.1,
optimizer="Adam",
optimizer="AdamW",
n_a=8,
gamma=0.3,
)
Expand Down Expand Up @@ -81,20 +81,29 @@
sns.relplot(data=metrics, kind="line")
plt.gca().set_ylim([0, 1.25])
plt.gcf().set_size_inches(10, 5)
plt.grid()

# %% [markdown]
# ## 4. Generate predictions from a CSV

# %%
df_test = pd.read_csv(csv_test)

predictions = model.predict(csv_test)
print(predictions[0])
dm = TabularClassificationData.from_data_frame(
predict_data_frame=df_test,
parameters=datamodule.parameters,
batch_size=datamodule.batch_size,
)
preds = trainer.predict(model, datamodule=dm, output="classes")
print(preds[0][:10])

# %%
import itertools # noqa: E402]

import numpy as np # noqa: E402]

assert len(df_test) == len(predictions)
predictions = list(itertools.chain(*preds))
# assert len(df_test) == len(predictions)

df_test["Survived"] = np.argmax(predictions, axis=-1)
df_test.set_index("PassengerId", inplace=True)
Expand Down