psyke 0.8.9.dev93__tar.gz → 0.8.14__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of psyke might be problematic. Click here for more details.
- {psyke-0.8.9.dev93/psyke.egg-info → psyke-0.8.14}/PKG-INFO +1 -1
- psyke-0.8.14/VERSION +1 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/extraction/hypercubic/hypercube.py +5 -3
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/extraction/real/__init__.py +10 -19
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/extraction/real/utils.py +2 -2
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/extraction/trepan/__init__.py +2 -2
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/hypercubepredictor.py +4 -2
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/utils/logic.py +3 -7
- {psyke-0.8.9.dev93 → psyke-0.8.14/psyke.egg-info}/PKG-INFO +1 -1
- {psyke-0.8.9.dev93 → psyke-0.8.14}/setup.py +49 -49
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/__init__.py +4 -10
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/extraction/cart/test_simplified_cart.py +2 -2
- psyke-0.8.9.dev93/VERSION +0 -1
- {psyke-0.8.9.dev93 → psyke-0.8.14}/LICENSE +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/MANIFEST.in +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/README.md +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/clustering/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/clustering/cream/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/clustering/exact/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/clustering/utils.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/extraction/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/extraction/cart/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/extraction/cart/predictor.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/extraction/hypercubic/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/extraction/hypercubic/cosmik/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/extraction/hypercubic/creepy/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/extraction/hypercubic/divine/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/extraction/hypercubic/gridex/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/extraction/hypercubic/gridrex/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/extraction/hypercubic/hex/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/extraction/hypercubic/iter/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/extraction/hypercubic/strategy.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/extraction/hypercubic/utils.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/extraction/trepan/utils.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/schema/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/tuning/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/tuning/crash/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/tuning/orchid/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/tuning/pedro/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/utils/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/utils/dataframe.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/utils/metrics.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/utils/plot.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke/utils/sorted.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke.egg-info/SOURCES.txt +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke.egg-info/dependency_links.txt +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke.egg-info/not-zip-safe +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke.egg-info/requires.txt +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/psyke.egg-info/top_level.txt +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/pyproject.toml +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/setup.cfg +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/clustering/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/extraction/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/extraction/cart/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/extraction/cart/test_cart.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/extraction/hypercubic/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/extraction/hypercubic/gridex/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/extraction/hypercubic/gridex/test_gridex.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/extraction/hypercubic/iter/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/extraction/hypercubic/iter/test_iter.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/extraction/hypercubic/test_hypercube.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/extraction/real/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/extraction/real/test_real.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/extraction/real/test_rule.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/extraction/trepan/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/extraction/trepan/test_node.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/extraction/trepan/test_split.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/extraction/trepan/test_trepan.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/utils/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/utils/test_prune.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/utils/test_simplify.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/psyke/utils/test_simplify_formatter.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/resources/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/resources/datasets/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/resources/predictors/__init__.py +0 -0
- {psyke-0.8.9.dev93 → psyke-0.8.14}/test/resources/tests/__init__.py +0 -0
psyke-0.8.14/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.8.14
|
|
@@ -472,11 +472,13 @@ class RegressionCube(HyperCube):
|
|
|
472
472
|
|
|
473
473
|
def body(self, variables: dict[str, Var], ignore: list[str], unscale=None, normalization=None) -> Iterable[Struct]:
|
|
474
474
|
intercept = self.output.intercept_ if normalization is None else unscale(sum(
|
|
475
|
-
[-self.output.coef_[i] * normalization[name][0] / normalization[name][1] for i, name in
|
|
475
|
+
[-self.output.coef_.flatten()[i] * normalization[name][0] / normalization[name][1] for i, name in
|
|
476
476
|
enumerate(self.dimensions.keys())], self.output.intercept_), list(normalization.keys())[-1])
|
|
477
|
+
if isinstance(intercept, list):
|
|
478
|
+
intercept = intercept[0]
|
|
477
479
|
coefs = self.output.coef_ if normalization is None else [
|
|
478
|
-
self.output.coef_[i] / normalization[name][1] * normalization[list(normalization.keys())[-1]][1]
|
|
479
|
-
i, name in enumerate(self.dimensions.keys())
|
|
480
|
+
self.output.coef_.flatten()[i] / normalization[name][1] * normalization[list(normalization.keys())[-1]][1]
|
|
481
|
+
for i, name in enumerate(self.dimensions.keys())
|
|
480
482
|
]
|
|
481
483
|
return list(super().body(variables, ignore, unscale, normalization)) + [linear_function_creator(
|
|
482
484
|
list(variables.values()), [to_rounded_real(v) for v in coefs], to_rounded_real(intercept)
|
|
@@ -15,13 +15,11 @@ class REAL(PedagogicalExtractor):
|
|
|
15
15
|
"""
|
|
16
16
|
Explanator implementing Rule Extraction As Learning (REAL) algorithm, doi:10.1016/B978-1-55860-335-6.50013-1.
|
|
17
17
|
The algorithm is sensible to features' order in the provided dataset during extraction.
|
|
18
|
-
To make it reproducible the features are internally sorted (alphabetically).
|
|
19
18
|
"""
|
|
20
19
|
|
|
21
20
|
def __init__(self, predictor, discretization: Iterable[DiscreteFeature]):
|
|
22
21
|
super().__init__(predictor, discretization)
|
|
23
22
|
self._ruleset: IndexedRuleSet = IndexedRuleSet()
|
|
24
|
-
self._output_mapping = {}
|
|
25
23
|
|
|
26
24
|
@property
|
|
27
25
|
def n_rules(self):
|
|
@@ -31,7 +29,7 @@ class REAL(PedagogicalExtractor):
|
|
|
31
29
|
new_rule = self._rule_from_example(sample)
|
|
32
30
|
return any([new_rule in rule for rule in rules])
|
|
33
31
|
|
|
34
|
-
def
|
|
32
|
+
def _body(self, variables: dict[str, Var], rule: Rule) -> list[Struct]:
|
|
35
33
|
result = []
|
|
36
34
|
for predicates, truth_value in zip(rule.to_lists(), [True, False]):
|
|
37
35
|
for predicate in predicates:
|
|
@@ -40,27 +38,24 @@ class REAL(PedagogicalExtractor):
|
|
|
40
38
|
return result
|
|
41
39
|
|
|
42
40
|
def _create_clause(self, dataset: pd.DataFrame, variables: dict[str, Var], key: int, rule: Rule) -> Clause:
|
|
43
|
-
|
|
44
|
-
sorted(list(variables.values())),
|
|
45
|
-
str(sorted(list(set(dataset.iloc[:, -1])))[key]))
|
|
46
|
-
return clause(head, self._create_body(variables, rule))
|
|
41
|
+
return clause(create_head(dataset.columns[-1], list(variables.values()), key), self._body(variables, rule))
|
|
47
42
|
|
|
48
43
|
def _create_new_rule(self, sample: pd.Series) -> Rule:
|
|
49
44
|
rule = self._rule_from_example(sample)
|
|
50
45
|
return self._generalise(rule, sample)
|
|
51
46
|
|
|
52
47
|
def _create_ruleset(self, dataset: pd.DataFrame) -> IndexedRuleSet:
|
|
53
|
-
ruleset = IndexedRuleSet.create_indexed_ruleset(dataset)
|
|
54
|
-
for
|
|
48
|
+
ruleset = IndexedRuleSet.create_indexed_ruleset(sorted(set(dataset.iloc[:, -1])))
|
|
49
|
+
for _, sample in dataset.iloc[:, :-1].iterrows():
|
|
55
50
|
prediction = list(self.predictor.predict(sample.to_frame().transpose()))[0]
|
|
56
|
-
rules = ruleset.get(
|
|
51
|
+
rules = ruleset.get(prediction)
|
|
57
52
|
if not self._covers(sample, rules):
|
|
58
53
|
rules.append(self._create_new_rule(sample))
|
|
59
54
|
return ruleset.optimize()
|
|
60
55
|
|
|
61
|
-
def _create_theory(self, dataset: pd.DataFrame
|
|
56
|
+
def _create_theory(self, dataset: pd.DataFrame) -> MutableTheory:
|
|
62
57
|
theory = mutable_theory()
|
|
63
|
-
for key, rule in
|
|
58
|
+
for key, rule in self._ruleset.flatten():
|
|
64
59
|
variables = create_variable_list(self.discretization)
|
|
65
60
|
theory.assertZ(self._create_clause(dataset, variables, key, rule))
|
|
66
61
|
return theory
|
|
@@ -93,15 +88,14 @@ class REAL(PedagogicalExtractor):
|
|
|
93
88
|
|
|
94
89
|
def _internal_predict(self, sample: pd.Series):
|
|
95
90
|
x = [index for index, rule in self._ruleset.flatten() if REAL._rule_from_example(sample) in rule]
|
|
96
|
-
|
|
97
|
-
return reverse_mapping[x[0]] if len(x) > 0 else None
|
|
91
|
+
return x[0] if x else None
|
|
98
92
|
|
|
99
93
|
@staticmethod
|
|
100
94
|
def _rule_from_example(sample: pd.Series) -> Rule:
|
|
101
95
|
true_predicates, false_predicates = [], []
|
|
102
96
|
for feature, value in sample.items():
|
|
103
97
|
true_predicates.append(str(feature)) if value == 1 else false_predicates.append(str(feature))
|
|
104
|
-
return Rule(
|
|
98
|
+
return Rule(true_predicates, false_predicates)
|
|
105
99
|
|
|
106
100
|
def _subset(self, samples: pd.DataFrame, predicate: str) -> (pd.DataFrame, bool):
|
|
107
101
|
samples_0 = samples.copy()
|
|
@@ -112,11 +106,8 @@ class REAL(PedagogicalExtractor):
|
|
|
112
106
|
return samples_all, len(set(self.predictor.predict(samples_all))) == 1
|
|
113
107
|
|
|
114
108
|
def _extract(self, dataframe: pd.DataFrame) -> Theory:
|
|
115
|
-
# Order the dataset by column to preserve reproducibility.
|
|
116
|
-
dataframe = dataframe.sort_values(by=list(dataframe.columns.values), ascending=False)
|
|
117
|
-
self._output_mapping = {value: index for index, value in enumerate(sorted(set(dataframe.iloc[:, -1])))}
|
|
118
109
|
self._ruleset = self._get_or_set(HashableDataFrame(dataframe))
|
|
119
|
-
return self._create_theory(dataframe
|
|
110
|
+
return self._create_theory(dataframe)
|
|
120
111
|
|
|
121
112
|
def _predict(self, dataframe) -> Iterable:
|
|
122
113
|
return np.array([self._internal_predict(data.transpose()) for _, data in dataframe.iterrows()])
|
|
@@ -49,5 +49,5 @@ class IndexedRuleSet(dict[int, list[Rule]]):
|
|
|
49
49
|
]
|
|
50
50
|
|
|
51
51
|
@staticmethod
|
|
52
|
-
def create_indexed_ruleset(
|
|
53
|
-
return IndexedRuleSet({
|
|
52
|
+
def create_indexed_ruleset(indices: Iterable) -> IndexedRuleSet:
|
|
53
|
+
return IndexedRuleSet({i: [] for i in indices})
|
|
@@ -73,10 +73,10 @@ class Trepan(PedagogicalExtractor):
|
|
|
73
73
|
splits.add(split)
|
|
74
74
|
return splits
|
|
75
75
|
|
|
76
|
-
def _create_theory(self, name: str
|
|
76
|
+
def _create_theory(self, name: str) -> MutableTheory:
|
|
77
77
|
theory = mutable_theory()
|
|
78
78
|
for node in self._root:
|
|
79
|
-
variables = create_variable_list(self.discretization
|
|
79
|
+
variables = create_variable_list(self.discretization)
|
|
80
80
|
theory.assertZ(
|
|
81
81
|
clause(
|
|
82
82
|
create_head(name, list(variables.values()), str(node.dominant)),
|
|
@@ -45,9 +45,9 @@ class HyperCubePredictor(EvaluableModel):
|
|
|
45
45
|
idx = tree.query([list(row.values())], k=1)[1][0][0]
|
|
46
46
|
return HyperCubePredictor._get_cube_output(cubes[idx], row)
|
|
47
47
|
|
|
48
|
-
def _brute_predict_surface(self, row:
|
|
48
|
+
def _brute_predict_surface(self, row: pd.Series) -> GenericCube:
|
|
49
49
|
return min([(
|
|
50
|
-
cube.surface_distance(Point(list(row.keys()), list(row.values
|
|
50
|
+
cube.surface_distance(Point(list(row.keys()), list(row.values))), cube.volume(), cube
|
|
51
51
|
) for cube in self._hypercubes])[-1]
|
|
52
52
|
|
|
53
53
|
def _create_brute_tree(self, criterion: str = 'center', n: int = 2) -> (BallTree, list[GenericCube]):
|
|
@@ -76,6 +76,8 @@ class HyperCubePredictor(EvaluableModel):
|
|
|
76
76
|
return round(HyperCubePredictor._get_cube_output(cube, data), get_int_precision())
|
|
77
77
|
|
|
78
78
|
def _find_cube(self, data: dict[str, float]) -> GenericCube | None:
|
|
79
|
+
if not self._hypercubes:
|
|
80
|
+
return None
|
|
79
81
|
data = data.copy()
|
|
80
82
|
for dimension in self._dimensions_to_ignore:
|
|
81
83
|
if dimension in data:
|
|
@@ -123,12 +123,8 @@ def to_var(name: str) -> Var:
|
|
|
123
123
|
return var(name[0].upper() + name[1:])
|
|
124
124
|
|
|
125
125
|
|
|
126
|
-
def create_variable_list(features: list[DiscreteFeature], dataset: pd.DataFrame = None
|
|
127
|
-
if
|
|
128
|
-
features = sorted(features, key=lambda x: x.name)
|
|
129
|
-
dataset = sorted(dataset.columns[:-1]) if dataset is not None else None
|
|
130
|
-
else:
|
|
131
|
-
dataset = dataset.columns[:-1] if dataset is not None else None
|
|
126
|
+
def create_variable_list(features: list[DiscreteFeature], dataset: pd.DataFrame = None) -> dict[str, Var]:
|
|
127
|
+
dataset = dataset.columns[:-1] if dataset is not None else None
|
|
132
128
|
values = {feature.name: to_var(feature.name) for feature in features} \
|
|
133
129
|
if len(features) > 0 else {name: to_var(name) for name in dataset}
|
|
134
130
|
return values
|
|
@@ -325,4 +321,4 @@ def get_not_in_rule(min_included: bool = False, max_included: bool = True) -> Cl
|
|
|
325
321
|
parser = DEFAULT_CLAUSES_PARSER
|
|
326
322
|
theory = parser.parse_clauses(not_in_textual_rule(LE if min_included else L, GE if max_included else G),
|
|
327
323
|
operators=None)
|
|
328
|
-
return theory[0]
|
|
324
|
+
return theory[0]
|
|
@@ -70,58 +70,58 @@ class GetVersionCommand(distutils.cmd.Command):
|
|
|
70
70
|
print(version)
|
|
71
71
|
|
|
72
72
|
|
|
73
|
-
class CreateTestPredictors(distutils.cmd.Command):
|
|
74
|
-
description = 'gets the project version from git describe'
|
|
75
|
-
user_options = []
|
|
76
|
-
|
|
77
|
-
def initialize_options(self):
|
|
78
|
-
pass
|
|
79
|
-
|
|
80
|
-
def finalize_options(self):
|
|
81
|
-
pass
|
|
82
|
-
|
|
83
|
-
def run(self):
|
|
84
|
-
from psyke.utils import get_default_random_seed
|
|
85
|
-
from psyke.utils.dataframe import get_discrete_dataset
|
|
86
|
-
from sklearn.model_selection import train_test_split
|
|
87
|
-
from test import REQUIRED_PREDICTORS, get_dataset, get_model, get_schema
|
|
88
|
-
from test.resources.predictors import get_predictor_path, PATH, create_predictor_name
|
|
89
|
-
import ast
|
|
90
|
-
import pandas as pd
|
|
91
|
-
from tensorflow.keras import Model
|
|
92
|
-
from test import Predictor
|
|
73
|
+
#class CreateTestPredictors(distutils.cmd.Command):
|
|
74
|
+
# description = 'gets the project version from git describe'
|
|
75
|
+
# user_options = []
|
|
76
|
+
|
|
77
|
+
# def initialize_options(self):
|
|
78
|
+
# pass
|
|
79
|
+
|
|
80
|
+
# def finalize_options(self):
|
|
81
|
+
# pass
|
|
82
|
+
|
|
83
|
+
# def run(self):
|
|
84
|
+
# from psyke.utils import get_default_random_seed
|
|
85
|
+
# from psyke.utils.dataframe import get_discrete_dataset
|
|
86
|
+
# from sklearn.model_selection import train_test_split
|
|
87
|
+
# from test import REQUIRED_PREDICTORS, get_dataset, get_model, get_schema
|
|
88
|
+
# from test.resources.predictors import get_predictor_path, PATH, create_predictor_name
|
|
89
|
+
# import ast
|
|
90
|
+
# import pandas as pd
|
|
91
|
+
# from tensorflow.keras import Model
|
|
92
|
+
# from test import Predictor
|
|
93
93
|
|
|
94
94
|
# Read the required predictors to run the tests:
|
|
95
95
|
# model | model_options | dataset
|
|
96
|
-
required_predictors = pd.read_csv(REQUIRED_PREDICTORS, sep=';')
|
|
96
|
+
# required_predictors = pd.read_csv(REQUIRED_PREDICTORS, sep=';')
|
|
97
97
|
|
|
98
98
|
# Create missing predictors.
|
|
99
99
|
# model | model_options | dataset
|
|
100
|
-
for index, row in required_predictors.iterrows():
|
|
101
|
-
options = ast.literal_eval(row['model_options'])
|
|
102
|
-
file_name = create_predictor_name(row['dataset'], row['model'], options)
|
|
103
|
-
if not get_predictor_path(file_name).is_file():
|
|
104
|
-
dataset = get_dataset(row['dataset'])
|
|
105
|
-
if row['bins'] > 0:
|
|
106
|
-
schema = get_schema(dataset) # int(row['bins'])
|
|
107
|
-
dataset = get_discrete_dataset(dataset.iloc[:, :-1], schema).join(dataset.iloc[:, -1])
|
|
108
|
-
model, _ = get_model(row['model'], options)
|
|
109
|
-
training_set, test_set = train_test_split(dataset, test_size=0.5,
|
|
110
|
-
random_state=get_default_random_seed())
|
|
111
|
-
if isinstance(model, Model):
|
|
112
|
-
keys = set(training_set.iloc[:, -1])
|
|
113
|
-
mapping = {key: i for i, key in enumerate(keys)}
|
|
114
|
-
training_set.iloc[:, -1] = training_set.iloc[:, -1].apply(lambda x: mapping[x])
|
|
115
|
-
test_set.iloc[:, -1] = test_set.iloc[:, -1].apply(lambda x: mapping[x])
|
|
116
|
-
model.fit(training_set.iloc[:, :-1], training_set.iloc[:, -1], epochs=EPOCHS, batch_size=BATCH_SIZE)
|
|
117
|
-
else:
|
|
118
|
-
model.fit(training_set.iloc[:, :-1], training_set.iloc[:, -1])
|
|
119
|
-
predictor = Predictor(model)
|
|
120
|
-
predictor.save_to_onnx(PATH / file_name, Predictor.get_initial_types(training_set.iloc[:, :-1]))
|
|
121
|
-
|
|
122
|
-
required_predictors.to_csv(REQUIRED_PREDICTORS, sep=';', index=False)
|
|
123
|
-
|
|
124
|
-
print("Done")
|
|
100
|
+
# for index, row in required_predictors.iterrows():
|
|
101
|
+
# options = ast.literal_eval(row['model_options'])
|
|
102
|
+
# file_name = create_predictor_name(row['dataset'], row['model'], options)
|
|
103
|
+
# if not get_predictor_path(file_name).is_file():
|
|
104
|
+
# dataset = get_dataset(row['dataset'])
|
|
105
|
+
# if row['bins'] > 0:
|
|
106
|
+
# schema = get_schema(dataset) # int(row['bins'])
|
|
107
|
+
# dataset = get_discrete_dataset(dataset.iloc[:, :-1], schema).join(dataset.iloc[:, -1])
|
|
108
|
+
# model, _ = get_model(row['model'], options)
|
|
109
|
+
# training_set, test_set = train_test_split(dataset, test_size=0.5,
|
|
110
|
+
# random_state=get_default_random_seed())
|
|
111
|
+
# if isinstance(model, Model):
|
|
112
|
+
# keys = set(training_set.iloc[:, -1])
|
|
113
|
+
# mapping = {key: i for i, key in enumerate(keys)}
|
|
114
|
+
# training_set.iloc[:, -1] = training_set.iloc[:, -1].apply(lambda x: mapping[x])
|
|
115
|
+
# test_set.iloc[:, -1] = test_set.iloc[:, -1].apply(lambda x: mapping[x])
|
|
116
|
+
# model.fit(training_set.iloc[:, :-1], training_set.iloc[:, -1], epochs=EPOCHS, batch_size=BATCH_SIZE)
|
|
117
|
+
# else:
|
|
118
|
+
# model.fit(training_set.iloc[:, :-1], training_set.iloc[:, -1])
|
|
119
|
+
# predictor = Predictor(model)
|
|
120
|
+
# predictor.save_to_onnx(PATH / file_name, Predictor.get_initial_types(training_set.iloc[:, :-1]))
|
|
121
|
+
|
|
122
|
+
# required_predictors.to_csv(REQUIRED_PREDICTORS, sep=';', index=False)
|
|
123
|
+
|
|
124
|
+
# print("Done")
|
|
125
125
|
|
|
126
126
|
|
|
127
127
|
class CreateTheoryPlot(distutils.cmd.Command):
|
|
@@ -205,8 +205,8 @@ setup(
|
|
|
205
205
|
include_package_data=True,
|
|
206
206
|
python_requires='>=3.9.0, <3.10',
|
|
207
207
|
install_requires=REQUIREMENTS, # Optional
|
|
208
|
-
zip_safe
|
|
209
|
-
platforms
|
|
208
|
+
zip_safe=False,
|
|
209
|
+
platforms="Independant",
|
|
210
210
|
project_urls={ # Optional
|
|
211
211
|
'Bug Reports': 'https://github.com/psykei/psyke-python/issues',
|
|
212
212
|
# 'Funding': 'https://donate.pypi.org',
|
|
@@ -215,7 +215,7 @@ setup(
|
|
|
215
215
|
},
|
|
216
216
|
cmdclass={
|
|
217
217
|
'get_project_version': GetVersionCommand,
|
|
218
|
-
'create_test_predictors': CreateTestPredictors,
|
|
218
|
+
# 'create_test_predictors': CreateTestPredictors,
|
|
219
219
|
'create_theory_plot': CreateTheoryPlot
|
|
220
220
|
},
|
|
221
221
|
)
|
|
@@ -20,10 +20,6 @@ def initialize(file: str) -> list[dict[str:Theory]]:
|
|
|
20
20
|
params = dict() if row['extractor_params'] == '' else ast.literal_eval(row['extractor_params'])
|
|
21
21
|
dataset = get_dataset(row['dataset'])
|
|
22
22
|
|
|
23
|
-
# Dataset's columns are sorted due to alphabetically sorted extracted rules.
|
|
24
|
-
# columns = sorted(dataset.columns[:-1]) + [dataset.columns[-1]]
|
|
25
|
-
# dataset = dataset.reindex(columns, axis=1)
|
|
26
|
-
|
|
27
23
|
training_set, test_set = train_test_split(dataset, test_size=0.05 if row['dataset'].lower() == 'house' else 0.5,
|
|
28
24
|
random_state=get_default_random_seed())
|
|
29
25
|
|
|
@@ -63,10 +59,8 @@ def initialize(file: str) -> list[dict[str:Theory]]:
|
|
|
63
59
|
|
|
64
60
|
# Compute predictions from rules
|
|
65
61
|
index = test_set.shape[1] - 1
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
axis=1)
|
|
69
|
-
cast, substitutions = get_substitutions(test_set, ordered_test_set, theory)
|
|
62
|
+
|
|
63
|
+
cast, substitutions = get_substitutions(test_set, theory)
|
|
70
64
|
expected = [cast(query.solved_query.get_arg_at(index)) for query in substitutions if query.is_yes]
|
|
71
65
|
predictions = [prediction for prediction in extractor.predict(test_set_for_predictor.iloc[:, :-1])
|
|
72
66
|
if prediction is not None]
|
|
@@ -82,8 +76,8 @@ def initialize(file: str) -> list[dict[str:Theory]]:
|
|
|
82
76
|
}
|
|
83
77
|
|
|
84
78
|
|
|
85
|
-
def get_substitutions(test_set,
|
|
79
|
+
def get_substitutions(test_set, theory):
|
|
86
80
|
cast: Callable = lambda x: (str(x) if isinstance(test_set.iloc[0, -1], str) else float(x.value))
|
|
87
81
|
solver = prolog_solver(static_kb=mutable_theory(theory).assertZ(get_in_rule()).assertZ(get_not_in_rule()))
|
|
88
|
-
substitutions = [solver.solveOnce(data_to_struct(data)) for _, data in
|
|
82
|
+
substitutions = [solver.solveOnce(data_to_struct(data)) for _, data in test_set.iterrows()]
|
|
89
83
|
return cast, substitutions
|
|
@@ -33,10 +33,10 @@ class TestSimplifiedCart(unittest.TestCase):
|
|
|
33
33
|
simplified_theory = simplified_extractor.extract(train)
|
|
34
34
|
|
|
35
35
|
index = test.shape[1] - 1
|
|
36
|
-
cast, substitutions = get_substitutions(test,
|
|
36
|
+
cast, substitutions = get_substitutions(test, theory)
|
|
37
37
|
expected = [cast(query.solved_query.get_arg_at(index)) for query in substitutions]
|
|
38
38
|
|
|
39
|
-
cast, simplified_substitutions = get_substitutions(test,
|
|
39
|
+
cast, simplified_substitutions = get_substitutions(test, simplified_theory)
|
|
40
40
|
simplified_expected = [cast(query.solved_query.get_arg_at(index)) for query in simplified_substitutions]
|
|
41
41
|
|
|
42
42
|
if isinstance(test.iloc[0, -1], str):
|
psyke-0.8.9.dev93/VERSION
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
0.8.9.dev93
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|