fixes around pivot points and BOM matrix
This commit is contained in:
@ -1389,19 +1389,58 @@ class EnhancedTradingOrchestrator(TradingOrchestrator):
|
||||
# Get model prediction
|
||||
prediction_result = model.predict(feature_matrix)
|
||||
|
||||
# Extract predictions (action probabilities)
|
||||
# Extract predictions (action probabilities) - ensure proper array handling
|
||||
if isinstance(prediction_result, dict):
|
||||
# Get probabilities as flat array
|
||||
predictions = prediction_result.get('probabilities', [0.33, 0.33, 0.34])
|
||||
confidence = prediction_result.get('confidence', 0.7)
|
||||
# Ensure predictions is a flat list first
|
||||
|
||||
# Convert predictions to numpy array first
|
||||
if isinstance(predictions, np.ndarray):
|
||||
predictions = predictions.flatten().tolist()
|
||||
elif not isinstance(predictions, list):
|
||||
predictions = [float(predictions)]
|
||||
# Add confidence as a single float
|
||||
predictions.append(float(confidence))
|
||||
# Convert to flat numpy array
|
||||
predictions = np.array(predictions, dtype=np.float32)
|
||||
predictions_array = predictions.flatten()
|
||||
elif isinstance(predictions, (list, tuple)):
|
||||
predictions_array = np.array(predictions, dtype=np.float32).flatten()
|
||||
else:
|
||||
predictions_array = np.array([float(predictions)], dtype=np.float32)
|
||||
|
||||
# Create final predictions array with confidence
|
||||
# Ensure confidence is a scalar value - handle all array shapes safely
|
||||
if isinstance(confidence, np.ndarray):
|
||||
if confidence.ndim == 0:
|
||||
# 0-dimensional array (scalar)
|
||||
confidence_scalar = float(confidence.item())
|
||||
elif confidence.size == 1:
|
||||
# 1-element array
|
||||
confidence_scalar = float(confidence.item())
|
||||
else:
|
||||
# Multi-element array - take first element or mean
|
||||
confidence_scalar = float(confidence.flat[0]) # Use flat[0] to safely get first element
|
||||
else:
|
||||
confidence_scalar = float(confidence)
|
||||
|
||||
# Combine predictions and confidence as separate elements
|
||||
predictions = np.concatenate([
|
||||
predictions_array,
|
||||
np.array([confidence_scalar], dtype=np.float32)
|
||||
])
|
||||
elif isinstance(prediction_result, tuple) and len(prediction_result) == 2:
|
||||
# Handle (pred_class, pred_proba) tuple from CNN models
|
||||
pred_class, pred_proba = prediction_result
|
||||
|
||||
# Flatten and process the probability array
|
||||
if isinstance(pred_proba, np.ndarray):
|
||||
if pred_proba.ndim > 1:
|
||||
# Handle 2D arrays like [[0.1, 0.2, 0.7]]
|
||||
pred_proba_flat = pred_proba.flatten()
|
||||
else:
|
||||
# Already 1D
|
||||
pred_proba_flat = pred_proba
|
||||
|
||||
# Use the probability values as the predictions array
|
||||
predictions = pred_proba_flat.astype(np.float32)
|
||||
else:
|
||||
# Fallback: use class prediction only
|
||||
predictions = np.array([float(pred_class)], dtype=np.float32)
|
||||
else:
|
||||
# Handle direct prediction result
|
||||
if isinstance(prediction_result, np.ndarray):
|
||||
|
Reference in New Issue
Block a user