python
import torch

device = 'cuda' if torch.cuda.is_available() else 'cpu'
features = torch.tensor([[1.0, 2.0], [3.0, 4.0]], requires_grad=True, device=device)
weights = torch.tensor([[0.2], [0.8]], requires_grad=True, device=device)

PyTorch tensor basics and automatic differentiation

pytorch tensors autograd
by Dr. Elena Vasquez 1 tab
python
from gensim.models import Word2Vec

sentences = [
    ['customer', 'refund', 'payment', 'issue'],
    ['login', 'authentication', 'password', 'reset'],
    ['delivery', 'shipment', 'tracking', 'delay'],

Word embeddings with gensim for semantic similarity tasks

word-embeddings gensim nlp
by Dr. Elena Vasquez 1 tab
python
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline
from sklearn.metrics import classification_report

pipeline = Pipeline([

Text vectorization with TF-IDF for strong classical baselines

tf-idf nlp text-classification
by Dr. Elena Vasquez 1 tab
python
import spacy
from spacy.matcher import Matcher

nlp = spacy.load('en_core_web_sm')
matcher = Matcher(nlp.vocab)
matcher.add('INCIDENT_ID', [[{'TEXT': {'REGEX': '^INC-[0-9]{6}$'}}]])

Natural language processing with spaCy pipelines and custom rules

spacy nlp entity-extraction
by Dr. Elena Vasquez 1 tab
python
from sklearn.decomposition import PCA
from sklearn.manifold import TSNE
from sklearn.preprocessing import StandardScaler

X_scaled = StandardScaler().fit_transform(X)

PCA and t-SNE for dimensionality reduction and inspection

pca tsne dimensionality-reduction
by Dr. Elena Vasquez 1 tab
python
import numpy as np
from sklearn.metrics import confusion_matrix

probabilities = model.predict_proba(X_valid)[:, 1]
thresholds = np.linspace(0.1, 0.9, 9)

Confusion matrix diagnostics for threshold selection

confusion-matrix thresholding evaluation
by Dr. Elena Vasquez 1 tab
python
from sklearn.metrics import (
    average_precision_score,
    classification_report,
    precision_recall_curve,
    roc_auc_score,
)

Classification metrics beyond accuracy for imbalanced problems

classification-metrics imbalanced-data evaluation
by Dr. Elena Vasquez 1 tab
python
import optuna
from sklearn.ensemble import HistGradientBoostingClassifier
from sklearn.model_selection import cross_val_score

def objective(trial):
    model = HistGradientBoostingClassifier(

Bayesian optimization with Optuna for efficient model tuning

optuna hyperparameter-tuning optimization
by Dr. Elena Vasquez 1 tab
python
from sklearn.model_selection import GridSearchCV, RandomizedSearchCV
from sklearn.ensemble import RandomForestClassifier

grid_search = GridSearchCV(
    estimator=RandomForestClassifier(random_state=42, n_jobs=-1),
    param_grid={

Hyperparameter tuning with GridSearchCV and randomized search

hyperparameter-tuning gridsearch scikit-learn
by Dr. Elena Vasquez 1 tab
python
from sklearn.compose import ColumnTransformer
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.impute import SimpleImputer
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.ensemble import RandomForestClassifier

ColumnTransformer pipelines that keep preprocessing honest

scikit-learn pipelines columntransformer
by Dr. Elena Vasquez 1 tab
python
from sklearn.cluster import KMeans, DBSCAN, AgglomerativeClustering
from sklearn.metrics import silhouette_score
from sklearn.preprocessing import StandardScaler

X_scaled = StandardScaler().fit_transform(X)

Clustering with KMeans, DBSCAN, and hierarchical approaches

clustering kmeans dbscan
by Dr. Elena Vasquez 1 tab
python
from sklearn.linear_model import LinearRegression, Ridge, Lasso, ElasticNet
from sklearn.metrics import mean_absolute_error, root_mean_squared_error

models = {
    'linear': LinearRegression(),
    'ridge': Ridge(alpha=1.0),

Regression workflows with linear, ridge, lasso, and elastic net

scikit-learn regression ridge
by Dr. Elena Vasquez 1 tab