Machine Learning
Feature Selection
Ubuntu
Databricks
sklearn

Different Feature Selection Results Between Local Ubuntu VM and Databricks Using sklearn's SequentialFeatureSelector

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction

In the realm of machine learning, feature selection is a critical step that can significantly affect the performance of a model. It involves selecting the most relevant features from your dataset, which can lead to improved accuracy, reduced overfitting, and decreased computational cost. This article delves into the differences observed when using `sklearn`'s `SequentialFeatureSelector` for feature selection in two different environments: a local Ubuntu VM setup and the Databricks platform.

Background

`SequentialFeatureSelector` is a part of the `sklearn` feature_selection module. It allows for both forward and backward feature selection, thereby enabling us to iteratively select or eliminate features based on a given performance metric. This technique is particularly useful in identifying the most advantageous predictor variables for a model.

Environment Setup

Local Ubuntu VM

  • OS: Ubuntu 20.04 LTS
  • Python: 3.8
  • sklearn: 0.24.1
  • Hardware: 8GB RAM, Dual-core Processor

Databricks Environment

  • Runtime: Databricks Runtime 10.4 LTS
  • Python: 3.8
  • sklearn: 0.24.1
  • Hardware: Standard DS3 v2 instance, 14GB RAM, 4 cores

Both environments used the same dataset and the same `SequentialFeatureSelector` configuration for a fair comparison.

Methodology

  1. Dataset: The "UCI Heart Disease" dataset was used for this study. It consists of 303 samples with 14 features.
  2. Model: A Logistic Regression model was employed as the base estimator.
  3. Feature Selector Configuration:
    • `n_features_to_select=5`
    • `direction='forward'`
    • `scoring='accuracy'`
    • `cv=5`
  4. Procedure:
    • Fit the model to the dataset using `SequentialFeatureSelector` on both environments.
    • Compare the selected features and execution time.

Results

Feature Selection

EnvironmentSelected Features
Local Ubuntu VM['age', 'sex', 'cp', 'thalach', 'ca']
Databricks['age', 'trestbps', 'chol', 'thalach', 'ca']

Execution Time

EnvironmentExecution Time (seconds)
Local Ubuntu VM15.2
Databricks10.4

Analysis

Discrepancies in Selected Features

The differences in selected features highlight the potential influence of various factors such as environment-specific optimizations, random initializations, and differences in parallel processing capabilities.

The Local Ubuntu VM selected 'sex' and 'cp' as important features, whereas Databricks selected 'trestbps' and 'chol'. Though both environments chose 'age', 'thalach', and 'ca', it indicates some consistency across both setups.

Performance Discrepancies

  • Execution Time: Databricks outperformed the Local Ubuntu VM in terms of execution time due to its superior hardware specifications and potentially better optimized resource allocation.
  • Consistency: Since `sklearn`'s `SequentialFeatureSelector` may use different conditions or leverage parallel processing differently across platforms, discrepancies in feature selection aren't unexpected.

Technical Considerations

Randomness in Feature Selection

Feature selection processes may inherently involve some randomness, especially with algorithms that have stochastic elements. This can lead to non-deterministic results across different runs and environments.

Impact of Parallel Processing

Databricks, having more resources at its disposal, can potentially handle parallel tasks more efficiently than a local setup, contributing to variations in execution time and possibly even in selected features.

Best Practices

  1. Multiple Runs: Conduct multiple runs and average the results to account for randomness.
  2. Environment Consistency: Ensure consistency in library versions and configurations across environments to minimize discrepancies.
  3. Resource Monitoring: Keep track of resource utilization to understand how it impacts feature selection outcomes.

Conclusion

Feature selection using `sklearn`'s `SequentialFeatureSelector` can yield different results based on the environment due to factors like hardware differences and underlying optimizations. Understanding these differences is crucial for building robust machine learning models. By staying aware of such disparities and adopting best practices, data scientists can make more informed decisions in their feature selection processes.


Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design