An advanced music listening analysis tool that provides deep insights into your Spotify listening patterns using machine learning and network analysis.
- Listening Pattern Detection: Uses K-means clustering to identify distinct listening patterns
- Anomaly Detection: Identifies unusual listening patterns using Isolation Forest
- Engagement Scoring: Calculates sophisticated engagement metrics based on multiple factors
- Artist Network Analysis: Analyzes artist relationships and communities using network theory
- Content-based recommendation system using:
- Track popularity metrics
- Artist relationships
- Temporal patterns
- PCA for dimensionality reduction
- Cosine similarity for track matching
- Real-time visualization of listening patterns
- Artist network visualization
- Engagement analysis
- Recommendation interface
- Temporal analysis
- Python 3.8+
- pip package manager
pip install -r requirements.txt
Required packages:
- pandas
- numpy
- scikit-learn
- networkx
- plotly
- streamlit
- scipy
Place your Spotify data files in the data/raw
directory:
- spotify_recent_tracks.csv
- spotify_top_tracks_short.csv
- spotify_top_tracks_medium.csv
- spotify_top_tracks_long.csv
python src/python/spotify_analyzer.py
streamlit run src/python/spotify_dashboard.py
- Robust CSV parsing with error handling
- Automatic feature engineering
- Time-based feature extraction
- Session detection
- K-means clustering on temporal and engagement features
- Standardized feature scaling
- Dynamic cluster number selection
-
Feature Engineering:
- Popularity normalization
- Artist embeddings
- PCA dimensionality reduction
-
Similarity Calculation:
- Cosine similarity matrix
- Weighted feature importance
- Temporal context consideration
- Artist collaboration network based on temporal proximity
- Community detection using modularity optimization
- Centrality metrics calculation
- Interactive network visualization
The engagement score is calculated using multiple factors:
- Play frequency
- Artist diversity
- Time-of-day preferences
- Popularity metrics
spotify-analysis/
├── data/
│ └── raw/
│ ├── spotify_recent_tracks.csv
│ ├── spotify_top_tracks_short.csv
│ ├── spotify_top_tracks_medium.csv
│ └── spotify_top_tracks_long.csv
├── src/
│ └── python/
│ ├── spotify_analyzer.py
│ └── spotify_dashboard.py
└── README.md
def get_recommendations(track_name, artist, n_recommendations=5)
"""Get sophisticated music recommendations"""
def analyze_listening_patterns()
"""Enhanced analysis of listening patterns using ML"""
def detect_anomalies()
"""Detect unusual listening patterns"""
def analyze_artist_network()
"""Create and analyze artist collaboration network"""
def generate_insights()
"""Generate comprehensive insights using ML"""
def overview_page()
"""Enhanced overview page with ML insights"""
def pattern_analysis_page()
"""Enhanced pattern analysis page"""
def recommendation_page()
"""Smart recommendation interface"""
def artist_network_page()
"""Artist network visualization and analysis"""
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.