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) 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
- targetstr (default: โNoneโ)
Target predicate to learn
- n_estimatorsint, optional (default: 10)
Number of trees to fit
- node_sizeint, optional (default: 2)
Maximum number of literals in each node.
- max_tree_depthint, optional (default: 3)
Maximum number of nodes from root to leaf (height) in the tree.
- neg_pos_ratioint or float, optional (default: 2)
Ratio of negative to positive examples used during learning.
- background
- 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)