MCPcopy Create free account
hub / github.com/FareedKhan-dev/ai-long-task / _scale_feature_value

Method _scale_feature_value

data/database.py:2196–2237  ·  view source on GitHub ↗

Scale a feature value according to the configured scaling method Args: feature_name: Name of the feature dimension value: Raw feature value Returns: Scaled value in range [0, 1]

(self, feature_name: str, value: float)

Source from the content-addressed store, hash-verified

2194 stats["values"] = stats["values"][-1000:]
2195
2196 def _scale_feature_value(self, feature_name: str, value: float) -> float:
2197 """
2198 Scale a feature value according to the configured scaling method
2199
2200 Args:
2201 feature_name: Name of the feature dimension
2202 value: Raw feature value
2203
2204 Returns:
2205 Scaled value in range [0, 1]
2206 """
2207 if feature_name not in self.feature_stats:
2208 # No stats yet, return normalized by a reasonable default
2209 return min(1.0, max(0.0, value))
2210
2211 stats = self.feature_stats[feature_name]
2212
2213 if self.feature_scaling_method == "minmax":
2214 # Min-max normalization to [0, 1]
2215 min_val = stats["min"]
2216 max_val = stats["max"]
2217
2218 if max_val == min_val:
2219 return 0.5 # All values are the same
2220
2221 scaled = (value - min_val) / (max_val - min_val)
2222 return min(1.0, max(0.0, scaled)) # Ensure in [0, 1]
2223
2224 elif self.feature_scaling_method == "percentile":
2225 # Use percentile ranking
2226 values = stats["values"]
2227 if not values:
2228 return 0.5
2229
2230 # Count how many values are less than or equal to this value
2231 count = sum(1 for v in values if v <= value)
2232 percentile = count / len(values)
2233 return percentile
2234
2235 else:
2236 # Default to min-max if unknown method
2237 return self._scale_feature_value_minmax(feature_name, value)
2238
2239 def _scale_feature_value_minmax(self, feature_name: str, value: float) -> float:
2240 """Helper for min-max scaling"""

Callers 3

Calls 1

Tested by

no test coverage detected