def test_Apriori(self): self.runAlgorithm(ps.Apriori(), "Apriori", self.result, self.qualities, self.task)
from pysubgroup.tests.DataSets import get_credit_data data = get_credit_data() np.random.seed(1111) target_variables = np.random.randint(low=0, high=2, size=1000) target_estimates = np.random.uniform(size=1000) target = ps.PredictionTarget(target_variables, target_estimates, roc_auc_score) searchSpace_Nominal = ps.create_nominal_selectors(data, ignore=['credit_amount']) searchSpace_Numeric = [] #ps.create_numeric_selectors(data, ignore=['credit_amount'], nbins=10) searchSpace = searchSpace_Nominal + searchSpace_Numeric task = ps.SubgroupDiscoveryTask(data, target, searchSpace, result_set_size=10, depth=5, qf=ps.CountCallsInterestingMeasure(ps.PredictionQFNumeric(1, False))) resultBS = ps.BeamSearch().execute(task) resultA = ps.Apriori(use_numba=False).execute(task) resultA_numba = ps.Apriori(use_numba=True).execute(task) resultSimpleDFS = ps.SimpleDFS().execute(task) resultDFS = ps.DFS(ps.BitSetRepresentation).execute(task) resultDFS.to_dataframe() ############################################################ ## Toy example using the default eval to generate answers ## ############################################################ np.random.seed(1111) eval_dict = {"AUPRC(ish)":average_precision_score} target_variables = np.random.randint(low=0, high=2, size=1000)
def test_Apriori_with_numba(self): self.runAlgorithm(ps.Apriori(use_numba=True), "Apriori use_numba=True", self.result, self.qualities, self.task)
def test_Apriori_no_numba(self): self.runAlgorithm(ps.Apriori(use_numba=False), "Apriori use_numba=False", self.result, self.qualities, self.task)
def test_GeneralisingApriori(self): algorithm = ps.Apriori(combination_name='Disjunction') algorithm.optimistic_estimate_name = 'optimistic_generalisation' self.runAlgorithm(algorithm, "GeneralisingApriori", self.result, self.qualities, self.task)
import cProfile from timeit import default_timer as timer data = pd.DataFrame(arff.loadarff("../data/credit-g.arff")[0]) target = ps.NominalTarget('class', b'bad') searchSpace = ps.createNominalSelectors(data, ignore=['class']) task = ps.SubgroupDiscoveryTask(data, target, searchSpace, resultSetSize=10, depth=5, qf=ps.StandardQF(1.0)) start = timer() result = ps.Apriori().execute(task) end = timer() print("Time elapsed: ", (end - start)) for (q, sg) in result: print(str(q) + ":\t" + str(sg.subgroupDescription)) print("******") start = timer() result = ps.SimpleDFS().execute(task) end = timer() print("Time elapsed: ", (end - start)) for (q, sg) in result: print(str(q) + ":\t" + str(sg.subgroupDescription))