scikit-learn

repository·main·Indexed 13 days ago

https://github.com/scikit-learn/scikit-learn

A Python module for machine learning and data mining built on top of SciPy, providing a wide range of supervised and unsupervised learning algorithms. It includes a callback system for monitoring training processes via regular and auto-propagated callbacks, such as ProgressBar and ScoringMonitor.

Tokens
201.2K
Snippets
435
Records
1K
Agent score
100%

What's inside scikit-learn

  1. Overview of scikit-learn callbacks

    main
    Scikit-learn provides a callback system to monitor and visualize the training process. Callbacks can be 'regular' (attached to specific estimators to track their internal learning) or 'auto-propagated' (attached to meta-estimators like GridSearchCV to provide a high-level overview of the entire composition).
  2. Overview of the sklearn.preprocessing package

    main

    The sklearn.preprocessing package contains utility functions and transformer classes designed to transform raw feature vectors into representations more suitable for downstream machine learning estimators.

    Common use cases include:

    • Standardization: Many learning algorithms (like linear models) perform better when data is standardized.
    • Outlier Handling: If your dataset contains outliers, using robust scalers or specific transformers is often more appropriate than standard scaling.
    • Scaling and Normalization: Transforming features to specific ranges or distributions (e.g., Gaussian or Uniform).
  3. Classification metrics in sklearn.metrics

    main

    The sklearn.metrics module provides functions to measure classification performance, including loss, score, and utility functions.

    Metric Availability by Problem Type

    • Binary Classification Only: precision_recall_curve, roc_curve, class_likelihood_ratios, det_curve, confusion_matrix_at_thresholds.
    • Multiclass Classification: balanced_accuracy_score, cohen_kappa_score, confusion_matrix, hinge_loss, matthews_corrcoef, roc_auc_score, top_k_accuracy_score.
    • Multilabel Classification: accuracy_score, classification_report, f1_score, fbeta_score, hamming_loss, jaccard_score, log_loss, multilabel_confusion_matrix, precision_recall_fscore_support, precision_score, recall_score, roc_auc_score, zero_one_loss, d2_log_loss_score.
    • Binary and Multilabel (but not Multiclass): average_precision_score.

    Most implementations support a sample_weight parameter to allow each sample to provide a weighted contribution to the overall score.

  4. Understand model predictions with the sklearn.inspection module

    main

    The sklearn.inspection module provides tools to analyze and interpret machine learning models. Instead of relying solely on evaluation metrics, you can use these tools to:

    • Understand predictions: Identify what factors affect a model's output.
    • Evaluate assumptions and biases: Check if the model is making decisions based on inappropriate features or biased patterns.
    • Diagnose performance issues: Debug models to understand underlying issues when performance deviates from expectations.
    • Improve model design: Use insights from inspection to refine feature engineering or model selection.

    Key sub-modules for inspection include:

    • partial_dependence: To study the relationship between features and the predicted outcome.
    • permutation_importance: To assess feature importance by measuring how much error increases when a feature's values are shuffled.
  5. New Estimator Classes in scikit-learn v0.13

    main

    Version 0.13 introduced several new estimator classes across different modules:

    • Predictors (Classifiers/Regressors):

      • dummy.DummyClassifier and dummy.DummyRegressor: Data-independent predictors useful for sanity-checking other estimators.
      • linear_model.PassiveAggressiveClassifier and linear_model.PassiveAggressiveRegressor: Efficient stochastic optimization for linear models.
    • Transformers:

      • decomposition.FactorAnalysis: Implements classical factor analysis.
      • feature_extraction.FeatureHasher: Implements the "hashing trick" for fast, low-memory feature extraction from string fields.
      • feature_extraction.text.HashingVectorizer: For text documents.
      • pipeline.FeatureUnion: Concatenates results of several other transformers.
      • random_projection.GaussianRandomProjection and random_projection.SparseRandomProjection: Implement Gaussian and sparse random projection matrices.
      • kernel_approximation.Nystroem: Approximates arbitrary kernels.
      • preprocessing.OneHotEncoder: Computes binary encodings of categorical features.
      • ensemble.RandomTreesEmbedding: Creates high-dimensional sparse representations using ensembles of totally random trees.
      • manifold.SpectralEmbedding: Implements "laplacian eigenmaps" for non-linear dimensionality reduction.
      • isotonic.IsotonicRegression: Performs isotonic regression.
    • Functions:

      • random_projection.johnson_lindenstrauss_min_dim: Related to random projection dimensionality.
      • manifold.spectral_embedding: Function implementation of spectral embedding.
  6. Explore related statistical learning packages

    main

    For tasks involving data analysis and machine learning that extend beyond scikit-learn's core predictive modeling, consider the following ecosystem tools:

    • Pandas: Essential for handling heterogeneous/columnar data, relational queries, time series, and basic statistics.
    • statsmodels: Best for estimating and analyzing statistical models, with a focus on statistical tests rather than pure prediction.
    • PyMC: Used for Bayesian statistical models and fitting algorithms.
    • Seaborn: A high-level visualization library built on top of matplotlib for drawing statistical graphics.
    • scikit-survival: Implements models for survival analysis (learning from censored time-to-event data). It is designed to be fully compatible with the scikit-learn API.
  7. Glossary of Scikit-learn terms and API elements

    main
    Scikit-learn uses a consistent set of conventions for its API. This glossary provides a central reference for the terminology used across the library, including estimator types, metadata routing, callbacks, target types, methods, parameters, attributes, and sample properties. Understanding these terms is essential for navigating the API Reference and User Guide effectively.
  8. Explore domain-specific machine learning packages

    main

    For specialized machine learning applications in specific fields, use these libraries:

    • scikit-network: Machine learning on graphs.
    • scikit-image: Image processing and computer vision.
    • Natural language toolkit (nltk): Natural language processing (NLP).
    • gensim: Topic modeling, document indexing, and similarity retrieval.
    • NiLearn: Machine learning specifically for neuro-imaging.
    • AstroML: Machine learning for astronomy.
  9. Explore recommendation engine packages

    main

    If your goal is to build recommendation systems, these specialized libraries are available:

    • implicit: Designed for datasets containing implicit feedback.
    • lightfm: A hybrid recommender system implemented in Python/Cython.
    • Surprise Lib: Designed for datasets containing explicit feedback.
  10. What is Latent Dirichlet Allocation (LDA)?

    main

    Latent Dirichlet Allocation (LDA) is a generative probabilistic model used for topic modeling. It is designed to discover abstract topics from a collection of discrete datasets, such as text corpora.

    In the context of a text corpus, LDA assumes a generative process where:

    1. Each topic is defined by a distribution over words (controlled by topic_word_prior).
    2. Each document is defined by a mixture of topics (controlled by doc_topic_prior).
    3. Words in a document are sampled from the topics assigned to that document.

    The goal is to use the observed words to infer the hidden (latent) topic structure.