Artificial Intelligence and Machine Learning are the brains behind Kompara's intelligent recommendations. Our models analyze millions of data points to predict market behaviors and suggest optimal prices.
What Problems Does AI Solve in Pricing?
🔮 Change Prediction
Anticipate when a competitor will change their prices based on historical patterns and market signals.
💎 Opportunity Detection
Identify products where you can raise prices without losing competitiveness or lower them to gain market share.
📊 Dynamic Pricing
Automatically adjust prices based on demand, inventory, competition, and seasonality.
🎯 Intelligent Segmentation
Group products and competitors by behavior for personalized strategies.
⚠️ Anomaly Detection
Identify suspicious prices, scraping errors, or unusual market movements.
📈 Margin Optimization
Maximize profits by balancing sales volume with per-unit margin.
Machine Learning Models Used
1. Time Series Forecasting
To predict future prices, we use models specialized in temporal data:
🤖 Implemented Models
- ARIMA/SARIMA: To capture trends and seasonality
- Prophet (Facebook): Handles holidays and special events
- LSTM Neural Networks: For complex and non-linear patterns
- XGBoost with temporal features: Robust prediction with external variables
# Simplified example: Prediction with XGBoost
import xgboost as xgb
from sklearn.preprocessing import StandardScaler
# Input features
features = [
'precio_actual',
'precio_promedio_30d',
'volatilidad',
'posicion_ranking',
'dia_semana',
'mes',
'distancia_precio_min',
'distancia_precio_max',
'tendencia_7d',
'competidores_activos'
]
# Training
model = xgb.XGBRegressor(
n_estimators=100,
learning_rate=0.1,
max_depth=6,
objective='reg:squarederror'
)
model.fit(X_train, y_train)
# Prediction
predicted_price = model.predict(X_new)[0]
confidence = model.predict_proba(X_new)
2. Clustering and Segmentation
We group products and competitors with similar behaviors:
# K-Means for segmenting competitors
from sklearn.cluster import KMeans
# Behavioral features
features = [
'frecuencia_cambios_precio',
'amplitud_promedio_cambios',
'tiempo_respuesta_competencia',
'agresividad_descuentos',
'consistencia_liderazgo'
]
# Segmentation into 4 profiles
kmeans = KMeans(n_clusters=4, random_state=42)
competitor_profiles = kmeans.fit_predict(competitor_data)
# Typical profiles:
# 0: "Price Leader" - Always cheaper
# 1: "Follower" - Follows the market
# 2: "Premium" - High prices, little variation
# 3: "Aggressive" - Frequent and drastic changes
3. Price Optimization
We find the optimal price that maximizes business objectives:
Optimization Function
Objective: Maximize profit considering demand elasticity and competitive constraints
# Optimization with constraints
from scipy.optimize import minimize
def objective_function(price, cost, competition_prices):
# Demand model (elasticity)
base_demand = 1000
elasticity = -2.5
# Competition effect
price_position = np.percentile(competition_prices, 50)
competition_factor = 1 - ((price - price_position) / price_position) * 0.5
# Estimated demand
demand = base_demand * (price / base_price) ** elasticity * competition_factor
# Profit
profit = (price - cost) * demand
return -profit # Negative because minimize seeks minimums
# Constraints
constraints = [
{'type': 'ineq', 'fun': lambda x: x - cost * 1.1}, # Min 10% margin
{'type': 'ineq', 'fun': lambda x: max(competition_prices) * 1.05 - x} # Max 5% above competition
]
# Optimize
result = minimize(
objective_function,
x0=current_price,
args=(cost, competition_prices),
constraints=constraints,
method='SLSQP'
)
optimal_price = result.x[0]
Feature Engineering: The Key to Success
The quality of predictions depends heavily on the features we create:
Temporal Features
- Rolling statistics: 7/30/90-day moving average
- Volatility: Standard deviation of prices
- Trend: Linear regression over time window
- Relative changes: % change vs previous day/week/month
- Seasonality: Day of week, month, bi-week, holidays
Competitor Features
- Ranking position: 1st, 2nd, 3rd cheapest
- Gap with competition: Distance to the lowest/highest price
- Time as leader: Consecutive days being the cheapest
- Market aggressiveness: Frequency of changes in the sector
Product Features
- Historical elasticity: Demand sensitivity to price
- Current margin: (Price - Cost) / Price
- Inventory: Stock on hand / Turnover rate
- Popularity: Visits, conversions, searches
Machine Learning Pipeline
🔄 Full Training and Prediction Flow
1. Data Ingestion
└─> Hourly price scraping
└─> Internal sales data
└─> External events (holidays, campaigns)
2. Feature Engineering
└─> Calculation of temporal features
└─> Competitor features
└─> Normalization and scaling
3. Training
└─> Temporal train/validation/test split
└─> Hyperparameter tuning (GridSearch/Bayesian)
└─> Sliding window cross-validation
└─> Ensemble of multiple models
4. Evaluation
└─> MAE, RMSE, MAPE
└─> Backtesting on historical data
└─> A/B testing in production
5. Deployment
└─> Model to production (API)
└─> Drift monitoring
└─> Automatic weekly re-training
Anomaly Detection with Isolation Forest
We automatically identify suspicious prices or errors:
# Anomaly detection
from sklearn.ensemble import IsolationForest
# Features to detect anomalies
features = [
'precio_normalizado',
'cambio_porcentual',
'distancia_media',
'frecuencia_cambios'
]
# Model
iso_forest = IsolationForest(
contamination=0.01, # 1% of data are expected outliers
random_state=42
)
# Detect
anomalies = iso_forest.fit_predict(price_data)
# -1 = anomaly, 1 = normal
suspicious_prices = price_data[anomalies == -1]
# Alert for manual review
for price in suspicious_prices:
alert_system.send(
message=f"Anomalous price detected: {price.store} - {price.product}",
severity="medium",
requires_review=True
)
Reinforcement Learning for Dynamic Pricing
We experiment with RL to learn optimal pricing policies:
🎮 Q-Learning for Pricing Decisions
The agent learns what price action to take in each market state:
- States: Competitive position, inventory, trend
- Actions: Raise +5%, hold, lower -5%
- Reward: Profit generated in the next 24h
- Result: Policy that maximizes long-term profit
Interpretability and Explanations
It is crucial to explain WHY the model suggests a certain price:
# SHAP for explainability
import shap
# SHAP values
explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X_new)
# Top 5 most influential features
feature_importance = pd.DataFrame({
'feature': features,
'importance': np.abs(shap_values[0])
}).sort_values('importance', ascending=False).head(5)
# Explanation for the user:
explanation = f"""
We recommend a price of ${predicted_price:.2f} because:
1. Your main competitor lowered prices yesterday (-8%)
2. You are currently in 3rd position (losing sales)
3. Your margin allows lowering to ${min_price:.2f}
4. Model predicts competitor will raise prices in 2-3 days
5. High demand season (Q4)
"""
Real Results
📈 +35% Margin
Clients increase average margin by identifying opportunities to raise prices without losing competitiveness
⚡ 92% Accuracy
Our models predict price changes with 92% accuracy within a 48-hour window
⏱️ Real Time
Predictions in less than 100ms, allowing for instant decisions
🎯 85% Adoption
85% of the model's recommendations are implemented by users (high trust)
Tools and Stack
🐍 Python Ecosystem
scikit-learn, XGBoost, TensorFlow, PyTorch
📊 Feature Store
Feast for centralized feature management
🔄 MLflow
Experiment tracking and model versioning
☁️ Cloud ML
AWS SageMaker / Google Vertex AI for scalable training
Challenges and Lessons Learned
1. Data Drift
Market behavior changes constantly. Solution: Weekly re-training and performance monitoring.
2. Cold Start Problem
New products with no history. Solution: Transfer learning from similar products.
3. Causality vs. Correlation
Not every pattern is causal. Solution: Rigorous A/B testing before trusting predictions.
4. Explainability
Black boxes do not build trust. Solution: SHAP values and human-readable explanations.
Want to see AI in action?
Request a demo and we'll show you real predictions for your industry.
Request Demo →