Nalyst Documentation
Production-grade analytics with a single train()
/ infer() API spanning classical ML,
statistical modeling, time series, survival analysis, and a
PyTorch-style deep learning stack.
Unified API
One consistent train/infer interface across all model types — ML, stats, time series, and deep learning.
AutoML
Automated model selection, hyperparameter tuning, and imbalance handling built-in.
Time Series
ARIMA, VAR, and feature-based forecasting with leakage-aware backtesting.
Deep Learning
PyTorch-inspired nn module with autograd, 50+ layers, optimizers, and losses.
Installation
Install Nalyst from PyPI with pip:
pip install nalyst
With optional extras (visualization + dataframe support):
pip install "nalyst[visualization,dataframes]"
From source (development):
git clone https://github.com/nalystresearch/nalyst.git cd nalyst pip install -e .[dev,visualization,dataframes]
Quick Start
Train and evaluate a classifier in just a few lines:
from nalyst import learners, evaluation, datasets
# Sample data
X, y = datasets.load_sample_classification()
X_train, X_test, y_train, y_test = evaluation.train_test_split(
X, y, test_ratio=0.2, seed=42
)
# Train a classifier
model = learners.RandomForestLearner(
n_estimators=200,
max_depth=8,
random_state=42
)
model.train(X_train, y_train)
# Evaluate
preds = model.infer(X_test)
acc = evaluation.accuracy_score(y_test, preds)
print(f"Accuracy: {acc:.4f}")
Supervised Learning
Nalyst provides a comprehensive set of model families:
- Linear Models: Linear/Logistic Regression, Ridge, Lasso, ElasticNet
- Tree Ensembles: RandomForest, GradientBoosting, ExtraTrees
- Support Vector Machines: SVC, SVR with various kernels
- Neighbors: KNN classifier/regressor
- Bayesian: Naive Bayes variants
from nalyst import learners
# Classification
model = learners.GradientBoostingLearner(
n_estimators=100,
learning_rate=0.1
)
model.train(X_train, y_train)
predictions = model.infer(X_test)
# Regression
reg_model = learners.LinearRegressionLearner()
reg_model.train(X_train, y_train)
predictions = reg_model.infer(X_test)
Unsupervised Learning
Clustering and dimensionality reduction tools:
- Clustering: KMeans, DBSCAN, Hierarchical, GMM
- Manifold Learning: t-SNE, UMAP-style, Isomap
- Diagnostics: Silhouette scores, cluster stability, elbow method
from nalyst.clustering import KMeansLearner from nalyst.reduction import PCAReducer # Dimensionality reduction pca = PCAReducer(n_components=10) X_reduced = pca.fit_transform(X) # Clustering kmeans = KMeansLearner(n_clusters=5) kmeans.train(X_reduced) labels = kmeans.infer(X_reduced)
Time Series
Univariate and multivariate forecasting with classical and ML-based methods:
from nalyst.timeseries import arima # Univariate ARIMA y = arima.demos.airpassengers() model = arima.ARIMA(order=(2, 1, 2)) model.train(y) forecast = model.infer(steps=12) print(forecast)
| Method | Use Case | Key Parameters |
|---|---|---|
| ARIMA | Univariate forecasting | order (p, d, q) |
| SARIMA | Seasonal patterns | seasonal_order |
| VAR | Multivariate | maxlags |
| Exponential Smoothing | Trend + seasonality | trend, seasonal |
Survival Analysis
Model time-to-event data with proper censoring handling:
from nalyst.survival import cox # Load demo dataset X, y_time, y_event = cox.demo_rossi() # Fit Cox Proportional Hazards model model = cox.CoxPH() model.train(X, y_time, y_event) # Get hazard predictions hazards = model.infer(X[:5]) print(hazards)
- Cox Proportional Hazards: Hazard ratios and survival curves
- Kaplan-Meier: Non-parametric survival estimation
- Metrics: Concordance index, Brier score
Deep Learning
PyTorch-inspired neural network module with autograd:
from nalyst.nn import Module, layers, optim, losses
from nalyst.data import DataLoader, TensorDataset
class Classifier(Module):
def __init__(self, in_features, hidden, num_classes):
super().__init__()
self.net = layers.Sequential(
layers.Linear(in_features, hidden),
layers.ReLU(),
layers.Linear(hidden, num_classes)
)
def forward(self, x):
return self.net(x)
# Initialize model, optimizer, and loss
model = Classifier(
in_features=20,
hidden=64,
num_classes=3
)
optimizer = optim.Adam(model.parameters(), lr=1e-3)
criterion = losses.CrossEntropyLoss()
# Create data loader
train_loader = DataLoader(
TensorDataset(X_train, y_train),
batch_size=64,
shuffle=True
)
# Training loop
for epoch in range(10):
for xb, yb in train_loader:
optimizer.zero_grad()
logits = model(xb)
loss = criterion(logits, yb)
loss.backward()
optimizer.step()
AutoML & Tuning
Automated model selection and hyperparameter tuning:
from nalyst import evaluation, learners
from nalyst.evaluation import grid_search
# Generate sample data
X, y = evaluation.make_classification(
n_samples=2000,
n_features=20,
random_state=7
)
# Define search space
search_space = {
"n_estimators": [100, 200, 400],
"max_depth": [None, 8, 12],
"max_features": ["sqrt", "log2"],
}
# Run grid search
base = learners.RandomForestLearner(random_state=7)
best_params, best_score = grid_search(
base,
X,
y,
param_grid=search_space,
scoring=evaluation.accuracy_score,
cv=5
)
print("Best params:", best_params)
print("CV accuracy:", best_score)
Explainability & Diagnostics
Understand your models with built-in tools:
- Feature Importance: Permutation importance, built-in importance
- SHAP/LIME-style: Attribution helpers when dependencies installed
- Diagnostics: Calibration plots, residual analysis, confusion matrices
- Partial Dependence: PDP and ICE curves
Pipelines & Serialization
Bundle preprocessing with models for consistent train/inference:
from nalyst.transform import Pipeline, StandardScaler, OneHotEncoder
from nalyst import learners
# Create pipeline
pipeline = Pipeline([
('scaler', StandardScaler()),
('encoder', OneHotEncoder(columns=['category'])),
('model', learners.RandomForestLearner())
])
# Train and save
pipeline.train(X_train, y_train)
pipeline.save('model_pipeline.pkl')
# Load and infer
loaded = Pipeline.load('model_pipeline.pkl')
predictions = loaded.infer(X_new)
Modules at a Glance
| Module | Description |
|---|---|
learners | Linear models, trees, ensembles, SVM, neighbors |
clustering | KMeans, DBSCAN, hierarchical, GMM |
reduction | PCA, manifold learning, feature selection |
transform | Scalers, encoders, imputers, pipelines |
evaluation | Metrics, cross-validation, grid search |
timeseries | ARIMA, SARIMA, VAR, exponential smoothing |
survival | Cox PH, Kaplan-Meier, AFT models |
nn | Layers, optimizers, losses, autograd |
automl | Model search, tuning, imbalance handling |
explainability | Feature importance, SHAP, diagnostics |
Need Help?
Check out the resources below or reach out to the community:
Examples GitHub Issues Contact