AI System for Car Dealer Recommendation and Personalization
The traditional approach in a car dealership: a manager guesses the client's preferences based on a first conversation. An AI system analyzes search history, financial profile, and website behavior, recommending cars with explanations of how each matches the client's specific criteria.
Personalized Car Selection
import numpy as np
import pandas as pd
from anthropic import Anthropic
import json
class CarRecommendationEngine:
"""Car recommendations matching buyer profile"""
def __init__(self):
self.llm = Anthropic()
def build_buyer_profile(self, search_history: list[dict],
explicit_preferences: dict = None) -> dict:
"""Buyer profile from search history"""
if not search_history:
return explicit_preferences or {}
# Analyze preferences from viewed cars
viewed_cars = [s for s in search_history if s.get('action') == 'view_detail']
if not viewed_cars:
return explicit_preferences or {}
# Price range
prices = [c.get('price', 0) for c in viewed_cars if c.get('price')]
price_range = (min(prices), max(prices)) if prices else (0, float('inf'))
# Preferred body types
bodies = pd.Series([c.get('body_type') for c in viewed_cars]).value_counts()
preferred_bodies = bodies.head(2).index.tolist()
# Brand preferences (if viewing one brand >40% of the time)
brands = pd.Series([c.get('brand') for c in viewed_cars]).value_counts(normalize=True)
preferred_brands = brands[brands > 0.25].index.tolist()
# Fuel type (by views)
fuels = pd.Series([c.get('fuel_type') for c in viewed_cars]).value_counts(normalize=True)
profile = {
'price_min': price_range[0] * 0.85,
'price_max': price_range[1] * 1.15,
'preferred_body_types': preferred_bodies,
'preferred_brands': preferred_brands,
'preferred_fuel': fuels.index[0] if len(fuels) > 0 else 'any',
'total_views': len(viewed_cars),
}
# Merge with explicit preferences
if explicit_preferences:
profile.update({k: v for k, v in explicit_preferences.items() if v})
return profile
def recommend_cars(self, buyer_profile: dict,
inventory: pd.DataFrame,
top_k: int = 5) -> list[dict]:
"""Top cars for buyer"""
df = inventory.copy()
# Filter by budget
price_min = buyer_profile.get('price_min', 0)
price_max = buyer_profile.get('price_max', float('inf'))
df = df[(df['price'] >= price_min) & (df['price'] <= price_max)]
if df.empty:
return []
# Scoring
scores = pd.Series(1.0, index=df.index)
# Body type
preferred_bodies = buyer_profile.get('preferred_body_types', [])
if preferred_bodies:
scores += df['body_type'].isin(preferred_bodies).astype(float) * 0.3
# Brand
preferred_brands = buyer_profile.get('preferred_brands', [])
if preferred_brands:
scores += df['brand'].isin(preferred_brands).astype(float) * 0.25
# Fuel type
preferred_fuel = buyer_profile.get('preferred_fuel', 'any')
if preferred_fuel != 'any':
scores += (df.get('fuel_type', 'petrol') == preferred_fuel).astype(float) * 0.15
# Popularity (time on lot — longer duration = lower score)
if 'days_in_inventory' in df.columns:
freshness = 1.0 - (df['days_in_inventory'] / 90).clip(0, 1)
scores += freshness * 0.1
# Dealer margin (business interest)
if 'dealer_margin' in df.columns:
margin_norm = (df['dealer_margin'] - df['dealer_margin'].min()) / (
df['dealer_margin'].max() - df['dealer_margin'].min() + 1e-9
)
scores += margin_norm * 0.20
df['score'] = scores
top_cars = df.nlargest(top_k, 'score').to_dict('records')
# Add personalized explanation
for car in top_cars:
car['match_explanation'] = self._explain_match(car, buyer_profile)
return top_cars
def _explain_match(self, car: dict, buyer_profile: dict) -> str:
"""Why this car suits the buyer"""
reasons = []
if car.get('body_type') in buyer_profile.get('preferred_body_types', []):
reasons.append(f"{car['body_type']} body type you're interested in")
if car.get('brand') in buyer_profile.get('preferred_brands', []):
reasons.append(f"preferred brand {car['brand']}")
price_mid = (buyer_profile.get('price_min', 0) + buyer_profile.get('price_max', float('inf'))) / 2
if abs(car.get('price', 0) - price_mid) < price_mid * 0.15:
reasons.append("matches your price range")
if not reasons:
reasons.append("matching your criteria")
return "Perfect match because: " + ", ".join(reasons)
def generate_test_drive_proposal(self, car: dict,
buyer: dict) -> str:
"""Personalized test drive proposal"""
response = self.llm.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=120,
messages=[{
"role": "user",
"content": f"""Write a personalized test drive invitation in Russian for an auto dealer.
Car: {car.get('year')} {car.get('brand')} {car.get('model')}, {car.get('price', 0):,.0f} руб.
Buyer's interests: {buyer.get('preferred_body_types', [])}
Key match: {car.get('match_explanation', '')}
2-3 sentences. Highlight 1 specific feature of this car that matches their profile. Include a clear call to action."""
}]
)
return response.content[0].text
AI personalization in car dealerships reduces car selection time by 30-45% and increases test-drive conversion rate by 15-20%. The main implementation barrier is DMS (Dealer Management System) integration: inventory data must be updated in real-time.







