Feature
Feature implementation for deriva-ml.
This module provides classes for defining and managing features in deriva-ml. Features represent measurable properties or characteristics that can be associated with records in a table. The module includes:
- Feature: Main class for defining and managing features
- FeatureRecord: Base class for feature records using pydantic models
Typical usage example
feature = Feature(association_result, model) FeatureClass = feature.feature_record_class() record = FeatureClass(value="high", confidence=0.95)
Feature
Manages feature definitions and their relationships in the catalog.
A Feature represents a measurable property or characteristic that can be associated with records in a table. Features can include asset references, controlled vocabulary terms, and custom metadata fields.
Attributes:
Name | Type | Description |
---|---|---|
feature_table |
Table containing the feature implementation. |
|
target_table |
Table that the feature is associated with. |
|
feature_name |
Name of the feature (from Feature_Name column default). |
|
feature_columns |
Set of columns specific to this feature. |
|
asset_columns |
Set of columns referencing asset tables. |
|
term_columns |
Set of columns referencing vocabulary tables. |
|
value_columns |
Set of columns containing direct values. |
Example
feature = Feature(association_result, model) print(f"Feature {feature.feature_name} on {feature.target_table.name}") print("Asset columns:", [c.name for c in feature.asset_columns])
Source code in src/deriva_ml/feature.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
feature_record_class
feature_record_class() -> type[
FeatureRecord
]
Create a pydantic model for entries into the specified feature table
Returns:
Type | Description |
---|---|
type[FeatureRecord]
|
A Feature class that can be used to create instances of the feature. |
Source code in src/deriva_ml/feature.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
|
FeatureRecord
Bases: BaseModel
Base class for dynamically generated feature record models.
This class serves as the base for pydantic models that represent feature records. Each feature record contains the values and metadata associated with a feature instance.
Attributes:
Name | Type | Description |
---|---|---|
Execution |
Optional[str]
|
RID of the execution that created this feature record. |
Feature_Name |
str
|
Name of the feature this record belongs to. |
feature |
ClassVar[Optional[Feature]]
|
Reference to the Feature object that created this record. |
Example
class GeneFeature(FeatureRecord): ... value: str ... confidence: float record = GeneFeature( ... Feature_Name="expression", ... value="high", ... confidence=0.95 ... )
Source code in src/deriva_ml/feature.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
asset_columns
classmethod
asset_columns() -> set[Column]
Returns columns that reference asset tables.
Returns:
Type | Description |
---|---|
set[Column]
|
set[Column]: Set of columns that contain references to asset tables. |
Source code in src/deriva_ml/feature.py
66 67 68 69 70 71 72 73 |
|
feature_columns
classmethod
feature_columns() -> set[Column]
Returns all columns specific to this feature.
Returns:
Type | Description |
---|---|
set[Column]
|
set[Column]: Set of feature-specific columns, excluding system and relationship columns. |
Source code in src/deriva_ml/feature.py
57 58 59 60 61 62 63 64 |
|
term_columns
classmethod
term_columns() -> set[Column]
Returns columns that reference vocabulary terms.
Returns:
Type | Description |
---|---|
set[Column]
|
set[Column]: Set of columns that contain references to controlled vocabulary terms. |
Source code in src/deriva_ml/feature.py
75 76 77 78 79 80 81 82 |
|
value_columns
classmethod
value_columns() -> set[Column]
Returns columns that contain direct values.
Returns:
Type | Description |
---|---|
set[Column]
|
set[Column]: Set of columns containing direct values (not references to assets or terms). |
Source code in src/deriva_ml/feature.py
84 85 86 87 88 89 90 91 |
|