0% found this document useful (0 votes)
11 views11 pages

Phase 4

Uploaded by

beni.kumar1972
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views11 pages

Phase 4

Uploaded by

beni.kumar1972
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Dynamic pricing

Introduction
Dynamic pricing is a strategy where businesses adjust prices
based on current market demands to optimize revenue and profit.
By leveraging data analytics and machine learning, companies can
make informed pricing decisions that reflect real-time market
conditions.

Objective
The goal of this project is to develop and evaluate a dynamic
pricing model using machine learning. The model will predict
demand and adjust prices to maximize revenue, covering data
preprocessing, exploratory data analysis (EDA), model training and
validation, price optimization, and performance evaluation.
Steps Involved

1.Data collection and preprocessing


Gather historical sales data and relevant features. Clean and
preprocess the data for analysis and model training.

2.Exploratory data analysis


Analyze data to identify trends and patterns, and visualize
factors influencing sales and pricing.
3. Model Training and validation
Train machine learning models to predict demand. Validate
performance using metrics like MAE, RMSE, and R².
Evaluation metrics
1. Financial Metrics
• Revenue: Total income from sales.
• Profit: Revenue minus costs.
• Gross Margin: (Revenue – COGS) / Revenue.

2. Accuracy Metrics

• Mean Absolute Error (MAE): Average absolute differences


between predicted and actual values.
• Root Mean Squared Error (RMSE): Square root of the average
squared differences.
• Mean Absolute Percentage Error (MAPE): Average absolute
percentage errors.
• R-squared (R²): Proportion of variance in demand explained by
the model.

3. Customer-Related Metrics

• Customer Satisfaction: Measured through surveys or


feedback.
• Customer Retention Rate: Percentage of repeat customers.
• Conversion Rate: Percentage of visits resulting in sales.

4. Demand and Elasticity Metrics


• Price Elasticity of Demand: Sensitivity of demand to price
changes.
• Demand Forecast Accuracy: Precision of demand predictions.

5. Operational Metrics
• Inventory Turnover: Rate of selling and replacing inventory.
• Stockouts and Overstocks: Frequency of running out of or
having excess stock.

6. Strategic Metrics
• Market Share: Company’s sales as a percentage of total
market sales.
• Competitive Positioning: How pricing compares to
competitors.

7. Behavioral Metrics

• Customer Segmentation Performance: Effectiveness of


targeted pricing.
• Shopping Cart Abandonment Rate: Percentage of
uncompleted online transactions.
8. Scenario-Specific Metrics

• Promotion Effectiveness: Impact of promotions on sales.


• Seasonality Adjustment: Adaptation to seasonal demand
variations.

4. Price optimization
Determine optimal prices to maximize revenue by simulating
various pricing scenarios.

5.Performance evaluation
Evaluate model effectiveness in real-world scenarios by
calculating metrics such as price elasticity and comparing actual
vs. predicted sales.

Conclusion

This project outlines the development and evaluation of a dynamic


pricing model using machine learning. By following a structured
approach, businesses can implement effective dynamic pricing
strategies to enhance profitability and competitiveness.
Program
Import pandas as pd
Import numpy as np
From sklearn.model_selection import train_test_split
From sklearn.preprocessing import StandardScaler
From datetime import timedelta
Import matplotlib.pyplot as plt
Import seaborn as sns
From sklearn.ensemble import GradientBoostingRegressor
From sklearn.metrics import mean_absolute_error,
mean_squared_error, r2_score

# Generate synthetic data


Np.random.seed(42)
Date_range = pd.date_range(start=’2020-01-01’, end=’2021-12-31’)
Data = pd.DataFrame({
‘Date’: date_range,
‘Sales’: np.random.randint(100, 200, size=len(date_range)),
‘Price’: np.random.uniform(10, 20, size=len(date_range)),
‘Competitor_Price’: np.random.uniform(10, 20,
size=len(date_range))
})

# Feature Engineering
Data[‘DayOfWeek’] = data[‘Date’].dt.dayofweek
Data[‘Month’] = data[‘Date’].dt.month
Data[‘Day’] = data[‘Date’].dt.day

# Create lag features


For lag in range(1, 8):
Data[f’Sales_Lag_{lag}’] = data[‘Sales’].shift(lag)

Data.dropna(inplace=True)

# Split data into features and target


X = data[[‘Price’, ‘Competitor_Price’, ‘DayOfWeek’, ‘Month’, ‘Day’] +
[f’Sales_Lag_{lag}’ for lag in range(1, 8)]]
Y = data[‘Sales’]

# Split data into training and test sets


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,
random_state=42)

# Standardize the data


Scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
# Visualize the sales over time
Plt.figure(figsize=(12, 6))
Plt.plot(data[‘Date’], data[‘Sales’])
Plt.xlabel(‘Date’)
Plt.ylabel(‘Sales’)
Plt.title(‘Sales Over Time’)
Plt.show()

# Correlation heatmap
Plt.figure(figsize=(10, 8))
Sns.heatmap(data.corr(), annot=True, fmt=’.2f’, cmap=’coolwarm’)
Plt.show()
# Train the model
Model = GradientBoostingRegressor(n_estimators=100,
learning_rate=0.1, max_depth=5, random_state=42)
Model.fit(X_train, y_train)

# Predictions
Y_pred_train = model.predict(X_train)
Y_pred_test = model.predict(X_test)
# Evaluation
Mae = mean_absolute_error(y_test, y_pred_test)
Rmse = np.sqrt(mean_squared_error(y_test, y_pred_test))
R2 = r2_score(y_test, y_pred_test)

Print(f’MAE: {mae}’)
Print(f’RMSE: {rmse}’)
Print(f’R2: {r2}’)
# Assuming we want to find the optimal price that maximizes
revenue
Price_range = np.linspace(min(data[‘Price’]), max(data[‘Price’]),
100)

Best_price = None
Max_revenue = -np.inf

For price in price_range:


Temp_X = X_test.copy()
Temp_X[:, 0] = price # Assuming price is the first column
Predicted_sales = model.predict(temp_X)
Revenue = price * predicted_sales.mean() # Simplified expected
revenue
If revenue > max_revenue:
Max_revenue = revenue
Best_price = price

Print(f’Optimal Price: {best_price}’)


Print(f’Maximum Revenue: {max_revenue}’)
# Calculate additional metrics
Price_elasticity = (np.mean(y_pred_test) – np.mean(y_test)) /
(best_price – np.mean(data[‘Price’]))
Print(f’Price Elasticity: {price_elasticity}’)
# Visualize actual vs predicted sales
Plt.figure(figsize=(12, 6))
Plt.plot(y_test.values, label=’Actual Sales’)
Plt.plot(y_pred_test, label=’Predicted Sales’)
Plt.xlabel(‘Samples’)
Plt.ylabel(‘Sales’)
Plt.title(‘Actual vs Predicted Sales’)
Plt.legend()
Plt.show()
Output

You might also like