nordlys.core.ml.instance module¶
Instance¶
Instance class.
- Features:
- This class supports different features for an instance.
- The features, together with the id of the instance, will be used in machine learning algorithms.
- All Features are stored in a dictionary, where keys are feature names (self.features).
- Instance properties:
- Properties are additional side information of an instance (e.g. query_id, entity_id, …).
- properties are stored in a dictionary (self.properties).
This is the base instance class. Specific type of instances can inherit form class and add more properties to the base class.
Author: | Faegheh Hasibi |
---|
-
class
nordlys.core.ml.instance.
Instance
(id, features=None, target='0', properties=None)[source]¶ Bases:
object
- Class attributes:
- ins_id: (string) features: a dictionary of feature names and values target: (string) target id or class properties: a dictionary of property names and values
-
add_feature
(feature, value)[source]¶ Adds a new feature to the features.
Parameters: feature – (string), feature name :param value
-
add_property
(property, value)[source]¶ Adds a new property to the properties.
Parameters: property – (string), property name :param value
-
features
¶
-
classmethod
from_json
(ins_id, fields)[source]¶ Reads an instance in JSON format and generates Instance.
Parameters: - ins_id – instance id
- fields – A dictionary of fields
:return (ml.Instance)
-
get_property
(property)[source]¶ Returns the value of a given property.
:param property :return value
-
id
¶
-
properties
¶
-
to_json
(file_name=None)[source]¶ Converts instance to the JSON format.
Parameters: file_name – (string) :return JSON dump of the instance.
-
to_libsvm
(features, qid_prop=None)[source]¶ Converts instance to the Libsvm format. - RankLib format:
<target> qid:<qid> <feature>:<value> … # <info>- Example: 3 qid:1 1:1 2:1 3:0 4:0.2 5:0 # 1A
NOTE: the property used for qid(qid_prop) should hold integers
Parameters: - features – the list of features that should be in the output
- qid_prop – property to be used as qid
:return str, instance in the rankLib format.