-
Notifications
You must be signed in to change notification settings - Fork 237
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
Add a Galaxy tool for TabPFN package (by Prof. Hutter's group) #1533
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e6febdf
add files
anuprulez 3569e1e
update
anuprulez e0a40ae
Merge branch 'bgruening:master' into tabpfn
anuprulez 6048605
update
anuprulez 91d25f5
update
anuprulez c09e7ac
update test
anuprulez bf3b626
Merge branch 'bgruening:master' into tabpfn
anuprulez 5477af3
add .shed.yml and remove usused imports
anuprulez df932ae
fix import order
anuprulez 29b1080
Merge branch 'bgruening:master' into tabpfn
anuprulez 004465a
modify for latest tabpfn
anuprulez a2a8306
update test data
bgruening 2fc47e7
Merge branch 'bgruening:master' into tabpfn
anuprulez be6b73c
update test
anuprulez e5ab02b
remove unused test data
anuprulez a6e2e80
fix linting error
anuprulez 7fe2287
Apply suggestions from code review
bgruening File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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="\t") | ||
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') | ||
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 = classifier.predict(te_features) | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@">2.0.3</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="@TOOL_VERSION@">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="tabular" label="Train data" help="Please provide training data for training model."/> | ||
<param name="test_data" type="data" format="tabular" 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" label="Precision-recall curve"></data> | ||
</outputs> | ||
<tests> | ||
<test> | ||
<param name="train_data" value="local_train_rows.tabular" ftype="tabular" /> | ||
<param name="test_data" value="local_test_rows.tabular" ftype="tabular" /> | ||
<output name="output_predicted_data"> | ||
<assert_contents> | ||
<has_n_columns n="42" /> | ||
<has_n_lines n="3" /> | ||
</assert_contents> | ||
</output> | ||
</test> | ||
</tests> | ||
<help> | ||
<![CDATA[ | ||
**What it does** | ||
|
||
Classification on tabular data by TabPFN | ||
|
||
**Input files** | ||
- Training data: the training data should contain features and the last column should be the class labels. It could either be tabular or in CSV format. | ||
- Test data: the test data should also contain the same features as the training data and the last column should be the class labels. It could either be tabular or in CSV format. | ||
|
||
**Output files** | ||
- Predicted data along with predicted labels | ||
]]> | ||
</help> | ||
<citations> | ||
<citation type="doi">10.1038/s41586-024-08328-6</citation> | ||
</citations> | ||
</tool> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SpMax_L J_Dz(e) nHM F01[N-N] F04[C-N] NssssC nCb- C% nCp nO F03[C-N] SdssC HyWi_B(m) LOC SM6_L F03[C-O] Me Mi nN-N nArNO2 nCRX3 SpPosA_B(p) nCIR B01[C-Br] B03[C-Cl] N-073 SpMax_A Psi_i_1d B04[C-Br] SdO TI2_L nCrt C-026 F02[C-N] nHDon SpMax_B(m) Psi_i_A nN SM6_B(m) nArCOOR nX predicted_labels | ||
3.919 2.6909 0 0 0 0 0 31.4 2 0 0 0 3.106 2.55 9.002 0 0.96 1.142 0 0 0 1.201 0 0 0 0 1.932 0.011 0 0 4.489 0 0 0 0 2.949 1.591 0 7.253 0 0 1 | ||
4.17 2.1144 0 0 0 0 0 30.8 1 1 0 0 2.461 1.393 8.723 1 0.989 1.144 0 0 0 1.104 1 0 0 0 2.214 -0.204 0 0 1.542 0 0 0 0 3.315 1.967 0 7.257 0 0 1 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A slightly better help would be nice :)