Skip to main content

trend_classifier

PyPI version Python versions License Downloads codecov

Automated signal segmentation, trend classification and analysis.

Documentation | Tutorials | API Reference

Quick Start

from trend_classifier import Segmenter

seg = Segmenter(x=x_data, y=y_data, n=20)
seg.calculate_segments()
seg.plot_segments()

Segmentation example

Installation

pip install trend-classifier

With optional dependencies:

pip install trend-classifier[pelt]         # PELT algorithm (ruptures)
pip install trend-classifier[optimization] # Hyperparameter tuning (optuna)
pip install trend-classifier[all]          # All extras

Features

  • Multiple detection algorithms:

    • sliding_window - Original algorithm, interpretable, good for most cases
    • bottom_up - Merge-based, control exact segment count
    • pelt - Optimal segmentation via ruptures library
  • Rich segment information: slope, offset, volatility, trend consistency

  • DataFrame export: seg.segments.to_dataframe()

  • Visualization: plot_segments(), plot_segment()

  • Configurable: Fine-tune sensitivity with alpha, beta, window size

Example with Stock Data

import yfinance as yf
from trend_classifier import Segmenter

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

# Segment and visualize
seg = Segmenter(df=df, column="Close", n=20)
seg.calculate_segments()
seg.plot_segments()

# Export to DataFrame
seg.segments.to_dataframe()

Using Different Detectors

from trend_classifier import Segmenter

# PELT algorithm (requires: pip install trend-classifier[pelt])
seg = Segmenter(x=x, y=y, detector="pelt", detector_params={"penalty": 10})
seg.calculate_segments()

# Bottom-up with target segment count
seg = Segmenter(x=x, y=y, detector="bottom_up", detector_params={"max_segments": 10})
seg.calculate_segments()

Segment Properties

Each segment contains:

Property Description
start, stop Index range
slope Trend direction and steepness
std Volatility (after detrending)
reason_for_new_segment Why segment boundary was placed
segment = seg.segments[0]
print(f"Slope: {segment.slope:.4f}, Volatility: {segment.std:.4f}")

Documentation

Full documentation with tutorials and API reference:

https://izikeros.github.io/trend_classifier/

License

MIT © Krystian Safjan

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trend_classifier-0.3.3.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trend_classifier-0.3.3-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file trend_classifier-0.3.3.tar.gz.

File metadata

  • Download URL: trend_classifier-0.3.3.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for trend_classifier-0.3.3.tar.gz
Algorithm Hash digest
SHA256 9bba49bf79b1dca74d1079cc801986fe04b2fac40ef7d18622f6a9226652d314
MD5 96ec233097efa86cc024688561d1f581
BLAKE2b-256 9cb815e287765ce9162a70c5ca79b1ea3e1d8bc3ac72acb457e59832a5e4f39a

See more details on using hashes here.

File details

Details for the file trend_classifier-0.3.3-py3-none-any.whl.

File metadata

File hashes

Hashes for trend_classifier-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 97ca4d5c2039f0c4dbd6d04ac2c988fb817ddb1dfc9dcab5a5e9e143cea4868f
MD5 f841bcb91c13350ed6cf9ffa749b587e
BLAKE2b-256 cd5eddff2485dab7faeeb0b9187ef922bbc4a49a27f5a7cc63d1cba9ab0f878f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.3 This release

2 files

0.3.1

2 files

0.3.0

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page