Record¶
Information on the software to evaluate is stored in a Record instance.
- class dffml.record.Record(key: str, *, data: Optional[Dict[str, Any]] = None, extra: Optional[Dict[str, Any]] = None)[source]¶
Manages feature independent information and actions for a record.
- evaluated(results: Dict[str, Any], overwrite=False)[source]¶
Updates features with the result dict
- Parameters:
results (dict) – The results that will be added to the features.
overwrite (boolean) – If ‘True’, the function overwrites the current features with the results provided. If ‘Fasle’, the function updates the current features with the results provided.
Examples
>>> from dffml import * >>> >>> example = Record("example", data=dict(features=dict(dead="beef"))) >>> print(example.features()) {'dead': 'beef'} >>> results = {"new": "feature"} >>> example.evaluated({"feed": "face"}) >>> print(example.features()) {'dead': 'beef', 'feed': 'face'} >>> example.evaluated(results, overwrite=True) >>> print(example.features()) {'new': 'feature'}
- feature(name: str) Any [source]¶
Returns a feature of the record.
- Parameters:
name (str) – The name of the feature that will be returned.
- Returns:
feature.
- Return type:
any
Examples
>>> from dffml import * >>> >>> example = Record("example", data=dict(features=dict(dead="beef"))) >>> print(example.feature("dead")) beef
- features(subset: List[str] = []) Dict[str, Any] [source]¶
Returns all features for the record or the subset specified.
- Parameters:
subset (list[str]) – The subset of features that will be returned.
- Returns:
features.
- Return type:
Examples
>>> from dffml import * >>> >>> example = Record("example", data=dict(features=dict(dead="beef"))) >>> >>> print(example.features(["dead"])) {'dead': 'beef'}
- predicted(target: str, value: Any, confidence: float)[source]¶
Set the prediction for this record.
- Parameters:
target (str) – The target you want to store the prediction at.
value (Any) – The prediction.
Examples
>>> from dffml import * >>> >>> example = Record("example", data=dict(features=dict(dead="beef"))) >>> example.predicted("target_name", "feed", 1.00) >>> print(example.prediction("target_name")) {'confidence': 1.0, 'value': 'feed'}
- prediction(target: str) RecordPrediction [source]¶
Get the prediction for this record.
- Parameters:
target (str) – The name of the feature that will be returned.
- Returns:
The prediction of the target specified.
- Return type:
Examples
>>> from dffml import * >>> >>> example = Record("example", data=dict(features=dict(dead="beef"))) >>> example.predicted("target_name", "feed", 1.00) >>> print(example.prediction("target_name")) {'confidence': 1.0, 'value': 'feed'}
- predictions(subset: List[str] = []) Dict[str, Any] [source]¶
Get the predictions for the subset of record.
- Parameters:
subset (list[str]) – The list of subset of the record that predictions are returned for.
- Returns:
The prediction of the specified subset.
- Return type:
Examples
>>> from dffml import * >>> >>> example = Record("example", data=dict(features=dict(dead="beef"))) >>> example.predicted("target_name1", "feed", 1.00) >>> example.predicted("target_name2", "deed", 0.97) >>> print(example.predictions(["target_name1", "target_name2"])) {'target_name1': {'confidence': 1.0, 'value': 'feed'}, 'target_name2': {'confidence': 0.97, 'value': 'deed'}}