Package: relational-datasets
relational-datasetsA small library for loading and downloading relational datasets.pipinstallrelational-datasetsBeta ReleaseThis API and the datasets athttps://github.com/srlearn/datasets/are currently being experimented with.PreferJulia? Check outRelationalDatasets.jl.Open enhancements and bugs are tracked here:Issues: relational-datasets packageIssues: datasetsBut here is a short-term Roadmap:Modes:srlearn/datasets: Issue 11Converting propositional->relationalProblem SettingsBinary ClassificationClassification: (0, 1)Classification: (-1, 1)Classification: maybe recommendsklearn.preprocessing.LabelBinarizerRegressionRegression: y ∈floatMulticlass Classification: When target isintand in[0, 1, 2, ...]Categorical datatype support inXmatrix.Dataframes:pandasUse Case 1: Fetching ZipfilesRunningthefetchmethod downloads a version of a datset to your local cache:importrelational_datasetsrelational_datasets.fetch("toy_cancer")relational_datasets.fetch("toy_father","v0.0.3")relational_datasets.fetch("cora")Resulting in:~/relational_datasets/├── toy_cancer_v0.0.4.zip   <--- latest├── toy_father_v0.0.3.zip   <--- specific version└── cora_v0.0.4.zip         <--- latestUse Case 2: Loading DataTheloadmethod returns train and test folds—each withpos,neg, andfacts. Internally it usesfetch, so it will automatically download a
dataset if it is not available.For example: "Load fold-2 of webkb"fromrelational_datasetsimportloadtrain,test=load("webkb","v0.0.4",fold=2)len(train.facts)# 1344Use Case 3: Working with Standard (Vector-based) Machine Learning DatasetsTherelational_datasets.convertmodule has functions for
converting vector-based datasets into relational/ILP-style
datasets:Binary ClassificationWhenyis a vector of 0/1fromrelational_datasets.convertimportfrom_numpyimportnumpyasnpdata,modes=from_numpy(np.array([[0,1,1],[0,1,2],[1,2,2]]),np.array([0,0,1]),)data,modes(RelationalDataset(pos=['v4(id3).'], neg=['v4(id1).', 'v4(id2).'], facts=['v1(id1,0).', 'v1(id2,0).', 'v1(id3,1).', 'v2(id1,1).', 'v2(id2,1).', 'v2(id3,2).', 'v3(id1,1).', 'v3(id2,2).', 'v3(id3,2).']),['v1(+id,#varv1).', 'v2(+id,#varv2).', 'v3(+id,#varv3).', 'v4(+id).'])RegressionWhenyis a vector of floatsfromrelational_datasets.convertimportfrom_numpyimportnumpyasnpdata,modes=from_numpy(np.array([[0,1,1],[0,1,2],[1,2,2]]),np.array([1.1,0.9,2.5]),)data,modes(RelationalDataset(pos=['regressionExample(v4(id1),1.1).', 'regressionExample(v4(id2),0.9).', 'regressionExample(v4(id3),2.5).'], neg=[], facts=['v1(id1,0).', 'v1(id2,0).', 'v1(id3,1).', 'v2(id1,1).', 'v2(id2,1).', 'v2(id3,2).', 'v3(id1,1).', 'v3(id2,2).', 'v3(id3,2).']),['v1(+id,#varv1).', 'v2(+id,#varv2).', 'v3(+id,#varv3).', 'v4(+id).'])Preprocessing scikit-learn'sload_breast_cancerload_breast_canceris based on theBreast Cancer Wisconsin dataset.Here we: (1) load the data and class labels,
(2) split into training and test sets, (3) bin the continuous
features to discrete, and (4) convert to the relational format.fromsklearn.datasetsimportload_breast_cancerfromsklearn.model_selectionimporttrain_test_splitfromsklearn.preprocessingimportKBinsDiscretizer# (1) LoadX,y=load_breast_cancer(return_X_y=True)# (2) SplitX_train,X_test,y_train,y_test=train_test_split(X,y)# (3) Discretizedisc=KBinsDiscretizer(n_bins=5,encode="ordinal")X_train=disc.fit_transform(X_train)X_test=disc.transform(X_test)X_train=X_train.astype(int)X_test=X_test.astype(int)# (4) Convertfromrelational_datasets.convertimportfrom_numpytrain,modes=from_numpy(X_train,y_train)test,_=from_numpy(X_test,y_test)InstallFrom PyPipipinstallrelational-datasetsFrom GitHub Sourcegitclonehttps://github.com/srlearn/relational-datasets.gitcdrelational-datasets
pipinstall-e.ContributionsAlexander Hayes-Indiana University, BloomingtonThis package was partially based on datasets from theStarling Lab Datasets Collection,
which included specific contributions byHarsha KokelandDevendra Singh Dhami.Tushar Khotconverted many to the ILP
format from Alchemy 2 format, but that occurred before versions were tracked.
Some inspiration was drawn from the
"RelationalDatasets" list thatJonas Schouterdencollected.