A curated collection of ready-to-use ML/Data Science code snippets and utilities
Stop rewriting the same exploratory data analysis code β just copy, paste, and explore! π
Features β’ Installation β’ Usage β’ Scripts β’ Kaggle Resources β’ Contributing
ML Collections is a practical repository containing reusable Python scripts and utilities for machine learning and data science workflows. Whether you're working on Kaggle competitions or exploring datasets, this collection provides battle-tested code snippets that save time and reduce repetitive coding.
- β‘ Quick Start: Copy-paste ready code for common ML tasks
- π― Practical: Real-world utilities used in actual Kaggle competitions
- π Exploratory: Tools focused on dataset exploration and visualization
- π§ Modular: Each script is self-contained and easy to integrate
- π Educational: Learn from curated Kaggle resources and techniques
- Data Exploration Tools: Quickly analyze datasets with unique value counting and visualizations
- Distribution Analysis: Compare train/test distributions with KDE and box plots
- Dataset Utilities: Print directory trees and explore Kaggle dataset structures
- Kaggle Resources: Curated collection of valuable discussions and notebooks
- TensorFlow Setup: Pre-configured environment setup scripts
- Python 3.7 or higher
- pip package manager
Install the necessary dependencies:
pip install pandas numpy matplotlib seaborn scikit-learnFor TensorFlow-based scripts:
pip install tensorflowgit clone https://github.com/Sanjidh090/ml-collections.git
cd ml-collectionsThe simplest way to explore a dataset:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
# Load your dataset
df = pd.read_csv('path/to/your/dataset.csv')
# Analyze unique values
for column in df.columns:
print(f"="*100)
print(f" Unique values in {column}:")
print(df[column].value_counts())
print(f"=="*50)
print(f" Unique Value Report:")
print(df.nunique())
# Visualize distributions
df.hist(figsize=(16, 16), bins=30)
plt.tight_layout()
plt.show()Purpose: Quickly analyze unique values and distributions in your dataset.
Features:
- Count unique values per column
- Display value frequency distributions
- Generate histogram visualizations
Usage:
# Analyze any CSV file
df = pd.read_csv('/path/to/dataset.csv')
# Run the unique value analysis (see script for details)Purpose: Compare feature distributions between training and test sets to detect data drift.
Features:
- Automatic label encoding for categorical variables
- KDE (Kernel Density Estimation) plots
- Box plots for outlier detection
- Train vs Test comparison for all features
Key Functions:
convert_all_to_numeric(train, test): Converts all columns to numeric formatdist_plots(train, test, num_features): Generates distribution comparison plots
Usage:
train = pd.read_csv('train.csv')
test = pd.read_csv('test.csv')
# Convert and get numeric columns
tr_all, te_all, numeric_cols = convert_all_to_numeric(train, test)
# Plot distributions
dist_plots(tr_all, te_all, numeric_cols)Purpose: Standard setup script for TensorFlow-based Kaggle notebooks.
Features:
- TensorFlow version upgrade
- Protobuf compatibility fix
- CPU-only mode (CUDA disabled)
- Log level configuration
- Dataset file exploration
Usage:
# Run at the start of your Kaggle notebook
# Automatically lists first 5 files in /kaggle/inputPurpose: Print dataset directory structure in a clean ASCII tree format.
Features:
- Recursive directory traversal
- Beautiful ASCII tree formatting
- Error handling for permissions and missing paths
Usage:
from prompt_style_dataset import print_tree
# Print dataset structure
print_tree("/path/to/dataset")Output Example:
Dataset structure for: /kaggle/working/
βββ data
β βββ train.csv
β βββ test.csv
βββ models
βββ model_v1.pkl
The kaggle/ directory contains a curated collection of valuable Kaggle discussions, notebooks, and insights:
- Pseudo-labelling Techniques (Pseudo-labelling___Chris_Deotte.md)
- Probability Calibration (Probab-Calibration-Broccoli-beef..md)
- Code Robustness Tips (Code_robust?.md)
These resources serve as a personal knowledge base for:
- π‘ Competition strategies and winning approaches
- π Advanced ML techniques
- π οΈ Practical tips discovered across various competitions
- π Concepts to revisit when they become relevant
Check out the Kaggle README for more details!
- Markdown Cheatsheet: Quick reference for Markdown syntax
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-utility) - Commit your changes (
git commit -m 'Add amazing utility') - Push to the branch (
git push origin feature/amazing-utility) - Open a Pull Request
- Keep scripts self-contained and well-documented
- Add usage examples in comments
- Follow existing code style
- Test your code before submitting
This project is open source and available for educational and personal use.
- Inspired by common Kaggle workflows and community best practices
- Built for the data science community to reduce repetitive coding
- Special thanks to Kaggle competition participants for sharing insights
Author: Sanjidh090
Repository: github.com/Sanjidh090/ml-collections
β Star this repository if you find it helpful!
Made with β€οΈ for the Data Science Community