Skip to content

trend_classifier

Automated signal segmentation, trend classification and analysis.

PyPI version Python versions License Downloads


What is trend_classifier?

trend_classifier automatically segments time series data into regions with similar trends. It's designed for:

  • Financial analysis - Identify bull/bear markets, support/resistance levels
  • Signal processing - Segment sensor data, detect regime changes
  • Algorithmic trading - Extract trend features for trading strategies

Key Features

  • Multiple detection algorithms - Choose the best algorithm for your data
  • Easy to use - Get started in 5 lines of code
  • Flexible output - Export to DataFrames, visualize with matplotlib
  • Well tested - 80%+ code coverage, production ready

Quick Example

import yfinance as yf
from trend_classifier import Segmenter

# Download stock data
df = yf.download("AAPL", start="2020-01-01", end="2023-01-01")

# Segment the time series
seg = Segmenter(df=df, column="Close", n=40)
seg.calculate_segments()

# Visualize results
seg.plot_segments()

# Export to DataFrame
df_segments = seg.segments.to_dataframe()

Segmentation Example

Available Detectors

Detector Description Best For
sliding_window Window-based with linear regression General use, interpretable
bottom_up Merge-based segmentation Noisy data, target segment count
pelt PELT algorithm (requires ruptures) Optimal segmentation, large data
# Use different detectors
seg = Segmenter(df=df, detector="pelt", detector_params={"penalty": 5})
seg = Segmenter(df=df, detector="bottom_up", detector_params={"max_segments": 10})

Installation

pip install trend-classifier

With optional dependencies:

pip install trend-classifier[pelt]         # PELT algorithm
pip install trend-classifier[optimization] # Optuna tuning
pip install trend-classifier[all]          # Everything

Next Steps