def setUp(self): # MySQL test db self.connection = DBConnection(TEST_DB['user'], TEST_DB['pass'], TEST_DB['host'], TEST_DB['database'], vendor=TEST_DB['vendor']) self.context = DBContext(self.connection, target_table='trains', target_att='direction') # Postgres test db self.connection_pg = DBConnection(TEST_DB_POSTGRES['user'], TEST_DB_POSTGRES['pass'], TEST_DB_POSTGRES['host'], TEST_DB_POSTGRES['database'], vendor=TEST_DB_POSTGRES['vendor']) self.context_pg = DBContext(self.connection_pg) self.context_pg.target_table = 'urbanblock' self.context_pg.target_att = 'class'
def test_db_read(self): ''' tables: list of selected tables cols: dict of columns for each table all_cols: dict of columns for each table (even unselected) col_vals: available values for each table/column connected: dict of table pairs and the connected columns fkeys: foreign keys in a given table reverse_fkeys: fkey to table map pkeys: private key for a given table target_table: selected table for learning target_att: selected column for learning ''' self.context = DBContext(self.connection) self.assertItemsEqual(self.context.tables, ['cars', 'trains']) self.assertTrue(('cars', 'trains') in self.context.connected) self.context = DBContext(self.connection_pg) self.assertItemsEqual(self.context.tables, ['building', 'urbanblock']) self.assertTrue(('building', 'urbanblock') in self.context.connected)
from rdm.db import DBVendor, DBConnection, DBContext, AlephConverter from rdm.wrappers import Aleph # Provide connection information connection = DBConnection( 'ilp', # User 'ilp123', # Password 'workflow.ijs.si', # Host 'ilp', # Database ) # Define learning context context = DBContext(connection, target_table='trains', target_att='direction') # Convert the data and induce features using Aleph conv = AlephConverter(context, target_att_val='east') aleph = Aleph() theory, features = aleph.induce('induce_features', conv.positive_examples(), conv.negative_examples(), conv.background_knowledge()) print(theory)
from rdm.db import DBVendor, DBConnection, DBContext, RSDConverter, mapper from rdm.wrappers import RSD from rdm.validation import cv_split from rdm.helpers import arff_to_orange_table # Provide connection information connection = DBConnection( 'ilp', # User 'ilp123', # Password 'workflow.ijs.si', # Host 'imdb_top', # Database vendor=DBVendor.MySQL) # Define learning context context = DBContext(connection, target_table='movies', target_att='quality') # Cross-validation loop predictions = [] folds = 10 for train_context, test_context in cv_split(context, folds=folds, random_seed=0): # Find features on the train set conv = RSDConverter(train_context) rsd = RSD() features, train_arff, _ = rsd.induce( conv.background_knowledge(), # Background knowledge examples=conv.all_examples(), # Training examples cn2sd=False # Disable built-in subgroup discovery )
feature_selection = [1., 0.5, 0.75] #for propStar/propDRM learning_rates = [0.001, 0.01, 0.0001] num_featuress = [10000, 30000, 50000] hidden_sizes = [8, 16, 32] connection = DBConnection( 'guest', # User 'relational', # Password 'relational.fit.cvut.cz', # Host dataset, # Database vendor=DBVendor.MySQL) context = DBContext(connection, target_table=target_table, target_att=target_label) #Sql-File for propStar/propDRM sql_file = "Data/trains/trains.sql" if algorithm in ["aleph", "rsd", "treeliker", "wordification", "relaggs"]: transform(algorithm, context, target_attr_value, seed=1, result_file="results_transformation.txt", transformations="tmp_transformation", fold_nums=10) experiment(algorithm, transformations="tmp_transformation",
learner = args.learner dataset = args.dataset target_label = args.target_label target_attr_value = args.target_attribute # Provide connection information connection = DBConnection( 'guest', # User 'relational', # Password 'relational.fit.cvut.cz', # Host dataset, # Database vendor=DBVendor.MySQL) # Define learning context context = DBContext(connection, target_table=dataset, target_att=target_label) print("Got context..") # Cross-validation loop predictions = [] predictions_f1 = [] times = [] folds = 10 print(context) for train_context, test_context in cv_split(context, folds=folds, random_seed=0): # Find features on the train set start = timer() if learner == "RSD":
from rdm.db import DBContext, AlephConverter, CSVConnection from rdm.wrappers import Aleph # Load data from a set of csv files connection = CSVConnection([ 'data/mutagenesis42/atoms.csv', 'data/mutagenesis42/bonds.csv', 'data/mutagenesis42/drugs.csv', 'data/mutagenesis42/ring_atom.csv', 'data/mutagenesis42/ring_strucs.csv', 'data/mutagenesis42/rings.csv' ]) # Define learning context context = DBContext(connection, target_table='atoms', target_att='element') # Convert the data and induce features using Aleph conv = AlephConverter(context, target_att_val='c') aleph = Aleph() theory, features = aleph.induce('induce_features', conv.positive_examples(), conv.negative_examples(), conv.background_knowledge()) print(theory) print(features)