srlearn.rdn
.BoostedRDNRegressor¶
-
class
srlearn.rdn.
BoostedRDNRegressor
(background=None, target='None', n_estimators=10, node_size=2, max_tree_depth=3, neg_pos_ratio=2, solver='BoostSRL')[source]¶ Relational Dependency Networks Regressor
Wrappers around BoostSRL for learning and inference of RDNs for regression task.
Similar to
sklearn.ensemble.GradientBoostingRegressor
, this builds a model by fitting a series of regression trees.Examples
>>> from srlearn.rdn import BoostedRDNRegressor >>> from srlearn import Background >>> from srlearn import Database >>> train = Database.from_files( ... pos="../datasets/Boston/train/pos.pl", ... neg="../datasets/Boston/train/neg.pl", ... facts="../datasets/Boston/train/facts.pl", ... lazy_load=False, ... ) >>> test = Database.from_files( ... pos="../datasets/Boston/test/pos.pl", ... neg="../datasets/Boston/test/neg.pl", ... facts="../datasets/Boston/test/facts.pl", ... lazy_load=False, ... ) >>> train.modes = ["crim(+id,#varsrim).", ... "zn(+id,#varzn).", ... "indus(+id,#varindus).", ... "chas(+id,#varchas).", ... "nox(+id,#varnox).", ... "rm(+id,#varrm).", ... "age(+id,#varage).", ... "dis(+id,#vardis).", ... "rad(+id,#varrad).", ... "tax(+id,#vartax).", ... "ptratio(+id,#varptrat).", ... "b(+id,#varb).", ... "lstat(+id,#varlstat).", ... "medv(+id)."] >>> bk = Background(modes=train.modes) >>> reg = BoostedRDNRegressor(background=bk, target="medv", n_estimators=5) >>> reg.fit(train) BoostedRDNRegressor(background=setParam: numOfClauses=100. setParam: numOfCycles=100. usePrologVariables: true. setParam: nodeSize=2. setParam: maxTreeDepth=3. mode: crim(+id,#varsrim). mode: zn(+id,#varzn). mode: indus(+id,#varindus). mode: chas(+id,#varchas). mode: nox(+id,#varnox). mode: rm(+id,#varrm). mode: age(+id,#varage). mode: dis(+id,#vardis). mode: rad(+id,#varrad). mode: tax(+id,#vartax). mode: ptratio(+id,#varptrat). mode: b(+id,#varb). mode: lstat(+id,#varlstat). mode: medv(+id). , n_estimators=5, neg_pos_ratio=2, solver='BoostSRL', target='medv') >>> reg.predict(test) # doctest: +SKIP array([10.04313307 13.55804603 20.549378 18.14681934 23.9393469 10.01292162 29.83298024 20.34668817 27.81642572 32.04067867 9.41342835 20.975001 19.21966845])
-
__init__
(background=None, target='None', n_estimators=10, node_size=2, max_tree_depth=3, neg_pos_ratio=2, solver='BoostSRL')[source]¶ Initialize a BoostedRDN
Parameters: - background :
srlearn.background.Background
(default: None) Background knowledge with respect to the database
- target : str (default: “None”)
Target predicate to learn
- n_estimators : int, optional (default: 10)
Number of trees to fit
- node_size : int, optional (default: 2)
Maximum number of literals in each node.
- max_tree_depth : int, optional (default: 3)
Maximum number of nodes from root to leaf (height) in the tree.
- neg_pos_ratio : int or float, optional (default: 2)
Ratio of negative to positive examples used during learning.
Attributes: - estimators_ : array, shape (n_estimators)
Return the boosted regression trees
- feature_importances_ : array, shape (n_features)
Return the feature importances (based on how often each feature appears)
- background :
-
feature_importances_
¶ Return the features contained in a tree.
Parameters: - tree_number: int
Index of the tree to read.
-
fit
(database)[source]¶ Learn structure and parameters.
Fit the structure and parameters of a Relational Dependency Network using a database of positive examples, negative examples, facts, and any relevant background knowledge.
Parameters: - database :
srlearn.database.Database
Database containing examples and facts.
Returns: - self : object
Returns self.
Notes
The underlying algorithm is based on the “Relational Functional Gradient Boosting” as described in [1] and [2]_.
This fit function is based on subprocess calling the BoostSRL jar files. This will require a Java runtime to also be available. See [R81fc0061240d-3].
[1] Sriraam Natarajan, Tushar Khot, Kristian Kersting, and Jude Shavlik, “Boosted Statistical Relational Learners: From Benchmarks to Data-Driven Medicine”. SpringerBriefs in Computer Science, ISBN: 978-3-319-13643-1, 2015 – [2] https://starling.utdallas.edu/software/boostsrl/wiki/regression/ .. [R81fc0061240d-3] https://starling.utdallas.edu/software/boostsrl/
- database :
-
from_json
(file_name)¶ Load a learned model from json.
Parameters: - file_name : str (or pathlike)
Path to a saved json file.
-
predict
(database)[source]¶ Use the learned model to predict values on new data.
Parameters: - database :
srlearn.Database
Database containing examples and facts.
Returns: - pred : ndarray
regression value predicted for each example.
- database :
-
to_json
(file_name) → None¶ Serialize a learned model to json.
Parameters: - file_name : str (or pathlike)
Path to a saved json file.
-