Regression, classification, and clustering techniques: Worked Example — Machine Learning With RAPIDS (NVIDIA-Certified Associate: Accelerated Data Science)
Introduction This worked example demonstrates how to apply regression , classification , and clustering techniques using GPU-accelerated libraries...
Introduction
This worked example demonstrates how to apply regression, classification, and clustering techniques using GPU-accelerated libraries from RAPIDS, specifically cuML. These techniques form a core part of the NVIDIA-Certified Associate: Accelerated Data Science exam, representing 16% of the content on Machine Learning With RAPIDS.
Scenario
Imagine a retail company wants to analyze customer data to:
- Predict customer spending (regression)
- Classify customers into loyalty tiers (classification)
- Identify natural groupings of customers for targeted marketing (clustering)
We will use RAPIDS cuML to perform these tasks efficiently on GPU.
Step 1: Data Preparation
Assume we have a dataset with features such as age, annual income, purchase frequency, and customer feedback score. The target variables are:
- Spending amount (continuous) for regression
- Loyalty tier (categorical: Bronze, Silver, Gold) for classification
For clustering, we use the features without target labels.
Step 2: Regression with cuML
We use cuML's LinearRegression to predict spending amount.
- Load data into GPU memory using cudf.DataFrame.
- Split data into training and test sets.
- Train model: Fit LinearRegression on training features and spending target.
- Predict: Use the model to predict spending on test data.
- Evaluate: Calculate performance metrics such as Mean Squared Error (MSE) and R² score.
Worked Example: Regression
Problem: Predict customer spending based on features.
Solution:
- Import cuML and cudf libraries.
- Load dataset into cudf.DataFrame.
- Split into train/test sets (e.g., 80/20).
- Initialize LinearRegression() and fit on training data.
- Predict spending on test set.
- Calculate MSE and R² to assess model quality.
Step 3: Classification with cuML
For classifying customers into loyalty tiers, we use cuML's RandomForestClassifier.
- Encode target labels (Bronze=0, Silver=1, Gold=2).
- Split data into training and test sets.
- Train model: Fit RandomForestClassifier on training features and loyalty labels.
- Predict: Generate predictions on test data.
- Evaluate: Use a confusion matrix and accuracy score to assess classification performance.
Worked Example: Classification
Problem: Classify customers into loyalty tiers.
Solution:
- Encode loyalty tiers numerically.
- Split dataset into train/test.
- Train RandomForestClassifier() on training data.
- Predict tiers on test set.
- Compute confusion matrix and accuracy score.
Step 4: Clustering with cuML
To discover natural customer segments, we apply cuML's KMeans clustering.
- Use features only (exclude targets).
- Initialize KMeans with a chosen number of clusters (e.g., 3).
- Fit model on the dataset.
- Assign cluster labels to each customer.
- Interpret clusters by analyzing feature means per cluster.
Worked Example: Clustering
Problem: Segment customers into 3 groups based on behavior.
Solution:
- Prepare feature matrix without labels.
- Initialize KMeans(n_clusters=3).
- Fit model to data.
- Assign cluster labels to customers.
- Analyze cluster centroids to understand group characteristics.
Summary
This example illustrates how RAPIDS cuML enables fast, GPU-accelerated machine learning workflows for regression, classification, and clustering. By leveraging these techniques, data scientists can efficiently build and evaluate models to extract actionable insights from large datasets.
For more details on RAPIDS and NVIDIA accelerated data science, visit https://rapids.ai/.
More in this topic
Ready to test your knowledge?
Put what you've learned into practice with a quick quiz and track your progress.
Test your knowledge →