Skip to content
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

[RFC] Add a Galaxy tool for TabPFN package (by Prof. Hutter's group) #1533

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions tools/tabpfn/.shed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: tabpfn
owner: bgruening
description: Tabular data prediction using TabPFN using Pytorch.
long_description: |
The TabPFN is a neural network that learned to do tabular data prediction.
This is the original CUDA-supporting pytorch impelementation.
remote_repository_url: https://github.com/bgruening/galaxytools/tree/master/tools/tabpfn
homepage_url: https://github.com/bgruening/galaxytools/tree/master/tools/tabpfn
type:
categories:
- Machine Learning
maintainers:
anuprulez
54 changes: 54 additions & 0 deletions tools/tabpfn/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""
Tabular data prediction using TabPFN
"""
import argparse
import time

import matplotlib.pyplot as plt
import pandas as pd
from sklearn.metrics import accuracy_score, average_precision_score, precision_recall_curve
from tabpfn import TabPFNClassifier


def separate_features_labels(data):
df = pd.read_csv(data, sep=",")
labels = df.iloc[:, -1]
features = df.iloc[:, :-1]
return features, labels


def train_evaluate(args):
"""
Train TabPFN
"""
tr_features, tr_labels = separate_features_labels(args["train_data"])
te_features, te_labels = separate_features_labels(args["test_data"])
classifier = TabPFNClassifier(device='cpu', N_ensemble_configurations=32)
s_time = time.time()
classifier.fit(tr_features, tr_labels)
e_time = time.time()
print("Time taken by TabPFN for training: {} seconds".format(e_time - s_time))
y_eval, p_eval = classifier.predict(te_features, return_winning_probability=True)
print('Accuracy', accuracy_score(te_labels, y_eval))
pred_probas_test = classifier.predict_proba(te_features)
te_features["predicted_labels"] = y_eval
te_features.to_csv("output_predicted_data", sep="\t", index=None)
precision, recall, thresholds = precision_recall_curve(te_labels, pred_probas_test[:, 1])
average_precision = average_precision_score(te_labels, pred_probas_test[:, 1])
plt.figure(figsize=(8, 6))
plt.plot(recall, precision, label=f'Precision-Recall Curve (AP={average_precision:.2f})')
plt.xlabel('Recall')
plt.ylabel('Precision')
plt.title('Precision-Recall Curve')
plt.legend(loc='lower left')
plt.grid(True)
plt.savefig("output_prec_recall_curve.png")


if __name__ == "__main__":
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument("-trdata", "--train_data", required=True, help="Train data")
arg_parser.add_argument("-tedata", "--test_data", required=True, help="Test data")
# get argument values
args = vars(arg_parser.parse_args())
train_evaluate(args)
62 changes: 62 additions & 0 deletions tools/tabpfn/tabpfn.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<tool id="tabpfn" name="Tabular data prediction using TabPFN" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="23.0">
<description>with PyTorch</description>
<macros>
<token name="@TOOL_VERSION@">0.1</token>
<token name="@VERSION_SUFFIX@">0</token>
</macros>
<creator>
<organization name="European Galaxy Team" url="https://galaxyproject.org/eu/" />
<person givenName="Anup" familyName="Kumar" email="[email protected]" />
<person givenName="Frank" familyName="Hutter" email="[email protected]" />
</creator>
<requirements>
<requirement type="package" version="0.1.10">tabpfn</requirement>
<requirement type="package" version="2.2.2">pandas</requirement>
<requirement type="package" version="3.9.2">matplotlib</requirement>
</requirements>
<version_command>echo "@VERSION@"</version_command>
<command detect_errors="aggressive">
<![CDATA[
python '$__tool_directory__/main.py'
--train_data '$train_data'
--test_data '$test_data'
]]>
</command>
<inputs>
<param name="train_data" type="data" format="csv" label="Train data" help="Please provide training data for training model."/>
<param name="test_data" type="data" format="csv" label="Test data" help="Please provide test data for evaluating model."/>
</inputs>
<outputs>
<data format="tabular" name="output_predicted_data" from_work_dir="output_predicted_data" label="Predicted data"></data>
<data format="png" name="output_prec_recall_curve" from_work_dir="output_prec_recall_curve.png" label="Precision-recall curve"></data>
</outputs>
<tests>
<test>
<param name="train_data" value="local_train_rows" ftype="csv" />
<param name="test_data" value="local_test_rows" ftype="csv" />
<output name="output_predicted_data" file="output_predicted_data" ftype="tabular">
<assert_contents>
<has_n_columns n="42" />
<has_n_lines n="838" />
</assert_contents>
</output>
</test>
</tests>
<help>
<![CDATA[
**What it does**

Prediction on tabular data by TabPFN

**Input files**
- Training data
- Test data

**Output files**
- Predicted data along with predicted labels
]]>
</help>
<citations>
<citation type="doi">10.48550/arXiv.2207.01848</citation>
</citations>
</tool>
Loading
Loading