srlearn.rdn
.BoostedRDNClassifier¶
-
class
srlearn.rdn.
BoostedRDNClassifier
(background=None, target='None', n_estimators=10, node_size=2, max_tree_depth=3, neg_pos_ratio=2, solver=None)[source]¶ Relational Dependency Networks Estimator
Wrappers around BoostSRL for learning and inference with Relational Dependency Networks written with a scikit-learn-style interface derived from
sklearn.base.BaseEstimator
Similar to
sklearn.ensemble.GradientBoostingClassifier
, this builds a model by fitting a series of regression trees.Examples
>>> from srlearn.rdn import BoostedRDNClassifier >>> from srlearn import Background >>> from srlearn.datasets import load_toy_cancer >>> train, test = load_toy_cancer() >>> bk = Background(modes=train.modes) >>> dn = BoostedRDNClassifier(background=bk, target="cancer") >>> dn.fit(train) BoostedRDNClassifier(background=setParam: numOfClauses=100. setParam: numOfCycles=100. usePrologVariables: true. setParam: nodeSize=2. setParam: maxTreeDepth=3. mode: friends(+Person,-Person). mode: friends(-Person,+Person). mode: smokes(+Person). mode: cancer(+Person). , n_estimators=10, neg_pos_ratio=2, solver='BoostSRL', target='cancer') >>> dn.predict(test) array([ True, True, True, False, False])
-
__init__
(background=None, target='None', n_estimators=10, node_size=2, max_tree_depth=3, neg_pos_ratio=2, solver=None)[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].
This fit function is based on subprocess calling the BoostSRL jar files. This will require a Java runtime to also be available. See [2].
[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/ - 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 on new data.
Parameters: - database :
srlearn.Database
Database containing examples and facts.
Returns: - results : ndarray
Positive or negative class.
- database :
-
predict_proba
(database)[source]¶ Return class probabilities.
Parameters: - database :
srlearn.Database
Database containing examples and facts.
Returns: - results : ndarray
Probability of belonging to the positive class
- database :
-
to_json
(file_name) → None¶ Serialize a learned model to json.
Parameters: - file_name : str (or pathlike)
Path to a saved json file.
-