pyFTS - Fuzzy Time Series for Python

What is pyFTS Library?

https://img.shields.io/badge/License-GPLv3-blue.svghttps://img.shields.io/badge/Made%20with-Python-1f425f.svg Fork me on GitHub

This package is intended for students, researchers, data scientists or whose want to exploit the Fuzzy Time Series methods. These methods provide simple, easy to use, computationally cheap and human-readable models, suitable from statistic laymans to experts.

This tool is developed on MINDS Lab, headed by Prof. Frederico Gadelha Guimarães from Electrical Engineering Departament of Federal University of Minas Gerais (UFMG) at Brazil. Also colaborate with this tool the Brazilian instituitions Federal Institute of North of Minas Gerais (IFNMG) and Federal Institute of Minas Gerais (IFMG) .

MINDS - Machine Intelligence and Data Science Lab           UFMG           IFNMG           IFMG

pyFTS Quick Start

How to install pyFTS?

https://img.shields.io/badge/Made%20with-Python-1f425f.svg

Before of all, pyFTS was developed and tested with Python 3.6. To install pyFTS using pip tool

pip install -U pyFTS

Ou clone directly from the GitHub repo for the most recent review:

pip install -U git+https://github.com/PYFTS/pyFTS

What are Fuzzy Time Series (FTS)?

Fuzzy Time Series (FTS) are non parametric methods for time series forecasting based on Fuzzy Theory. The original method was proposed by [1] and improved later by many researchers. The general approach of the FTS methods, based on [2] is listed below:

  1. Data preprocessing: Data transformation functions contained at pyFTS.common.Transformations, like differentiation, Box-Cox, scaling and normalization.
  2. Universe of Discourse Partitioning: This is the most important step. Here, the range of values of the numerical time series Y(t) will be splited in overlapped intervals and for each interval will be created a Fuzzy Set. This step is performed by pyFTS.partition module and its classes (for instance GridPartitioner, EntropyPartitioner, etc). The main parameters are:

Check out the jupyter notebook on notebooks/Partitioners.ipynb for sample codes.

  1. Data Fuzzyfication: Each data point of the numerical time series Y(t) will be translated to a fuzzy representation (usually one or more fuzzy sets), and then a fuzzy time series F(t) is created.

4. Generation of Fuzzy Rules: In this step the temporal transition rules are created. These rules depends on the method and their characteristics: - order: the number of time lags used on forecasting - weights: the weighted models introduce weights on fuzzy rules for smoothing - seasonality: seasonality models - steps ahead: the number of steps ahed to predict. Almost all standard methods are based on one-step-ahead forecasting - forecasting type: Almost all standard methods are point-based, but pyFTS also provides intervalar and probabilistic forecasting methods.

  1. Forecasting: The forecasting step takes a sample (with minimum length equal to the model’s order) and generate a fuzzy outputs (fuzzy set(s)) for the next time ahead.
  2. Defuzzyfication: This step transform the fuzzy forecast into a real number.
  3. Data postprocessing: The inverse operations of step 1.

Usage examples

There is nothing better than good code examples to start. Then check out the demo Jupyter Notebooks of the implemented method os pyFTS!.

A Google Colab example can also be found here.

pyFTS

pyFTS package

Subpackages
pyFTS.benchmarks package
Module contents

pyFTS module for benchmarking the FTS models

Submodules
pyFTS.benchmarks.benchmarks module
pyFTS.benchmarks.Measures module
pyFTS.benchmarks.ResidualAnalysis module
pyFTS.benchmarks.Tests module
pyFTS.benchmarks.Util module
pyFTS.benchmarks.arima module
pyFTS.benchmarks.knn module
pyFTS.benchmarks.naive module
pyFTS.benchmarks.quantreg module
pyFTS.benchmarks.gaussianproc module
pyFTS.benchmarks.BSTS module
pyFTS.common package
Module contents
Submodules
pyFTS.common.Activations module

Activation functions for Time Series Classification

pyFTS.common.Activations.argmax(dist: dict, weights: dict) → str[source]
pyFTS.common.Activations.scale(dist: dict, weights: dict) → dict[source]
pyFTS.common.Activations.softmax(dist: dict, weights: dict) → dict[source]
pyFTS.common.Composite module

Composite Fuzzy Sets

class pyFTS.common.Composite.FuzzySet(name, superset=False, **kwargs)[source]

Bases: pyFTS.common.FuzzySet.FuzzySet

Composite Fuzzy Set

append(mf, parameters)[source]

Adds a new function to composition

Parameters:
  • mf
  • parameters
Returns:

append_set(set)[source]

Adds a new function to composition

Parameters:
  • mf
  • parameters
Returns:

membership(x)[source]

Calculate the membership value of a given input

Parameters:x – input value
Returns:membership value of x at this fuzzy set
transform(x)[source]

Preprocess the data point for non native types

Parameters:x
Returns:return a native type value for the structured type
pyFTS.common.FLR module

This module implements functions for Fuzzy Logical Relationship generation

class pyFTS.common.FLR.FLR(LHS, RHS)[source]

Bases: object

Fuzzy Logical Relationship

Represents a temporal transition of the fuzzy set LHS on time t for the fuzzy set RHS on time t+1.

LHS = None

Left Hand Side fuzzy set

RHS = None

Right Hand Side fuzzy set

class pyFTS.common.FLR.IndexedFLR(index, LHS, RHS)[source]

Bases: pyFTS.common.FLR.FLR

Season Indexed Fuzzy Logical Relationship

index = None

seasonal index

pyFTS.common.FLR.generate_high_order_recurrent_flr(fuzzyData)[source]

Create a ordered FLR set from a list of fuzzy sets with recurrence

Parameters:fuzzyData – ordered list of fuzzy sets
Returns:ordered list of FLR
pyFTS.common.FLR.generate_indexed_flrs(sets, indexer, data, transformation=None, alpha_cut=0.0)[source]

Create a season-indexed ordered FLR set from a list of fuzzy sets with recurrence

Parameters:
  • sets – fuzzy sets
  • indexer – seasonality indexer
  • data – original data
Returns:

ordered list of FLR

pyFTS.common.FLR.generate_non_recurrent_flrs(fuzzyData, steps=1)[source]

Create a ordered FLR set from a list of fuzzy sets without recurrence

Parameters:fuzzyData – ordered list of fuzzy sets
Returns:ordered list of FLR
pyFTS.common.FLR.generate_recurrent_flrs(fuzzyData, steps=1)[source]

Create a ordered FLR set from a list of fuzzy sets with recurrence

Parameters:
  • fuzzyData – ordered list of fuzzy sets
  • steps – the number of steps ahead on the right side of FLR
Returns:

ordered list of FLR

pyFTS.common.FuzzySet module
class pyFTS.common.FuzzySet.FuzzySet(name: str, mf, parameters: list, centroid: float, alpha: float = 1.0, **kwargs)[source]

Bases: object

Fuzzy Set

Z = None

Partition function in respect to the membership function

alpha = None

The alpha cut value

centroid = None

The fuzzy set center of mass (or midpoint)

membership(x)[source]

Calculate the membership value of a given input

Parameters:x – input value
Returns:membership value of x at this fuzzy set
mf = None

The membership function

name = None

The fuzzy set name

parameters = None

The parameters of the membership function

partition_function(uod=None, nbins=100)[source]

Calculate the partition function over the membership function.

Parameters:
  • uod
  • nbins
Returns:

transform(x)[source]

Preprocess the data point for non native types

Parameters:x
Returns:return a native type value for the structured type
type = None

The fuzzy set type (common, composite, nonstationary, etc)

variable = None

In multivariate time series, indicate for which variable this fuzzy set belogs

pyFTS.common.FuzzySet.check_bounds(data, fuzzy_sets, ordered_sets)[source]
pyFTS.common.FuzzySet.check_bounds_index(data, fuzzy_sets, ordered_sets)[source]
pyFTS.common.FuzzySet.fuzzyfy(data, partitioner, **kwargs)[source]

A general method for fuzzyfication.

Parameters:
  • data – input value to be fuzzyfied
  • partitioner – a trained pyFTS.partitioners.Partitioner object
  • kwargs – dict, optional arguments
  • alpha_cut – the minimal membership value to be considered on fuzzyfication (only for mode=’sets’)
  • method – the fuzzyfication method (fuzzy: all fuzzy memberships, maximum: only the maximum membership)
  • mode – the fuzzyfication mode (sets: return the fuzzy sets names, vector: return a vector with the membership

values for all fuzzy sets, both: return a list with tuples (fuzzy set, membership value) )

:returns a list with the fuzzyfied values, depending on the mode

pyFTS.common.FuzzySet.fuzzyfy_instance(inst, fuzzy_sets: dict, ordered_sets: list = None)[source]

Calculate the membership values for a data point given fuzzy sets

Parameters:
  • inst – data point
  • fuzzy_sets – a dictionary where the key is the fuzzy set name and the value is the fuzzy set object.
  • ordered_sets – a list with the fuzzy sets names ordered by their centroids.
Returns:

array of membership values

pyFTS.common.FuzzySet.fuzzyfy_instances(data: list, fuzzy_sets: dict, ordered_sets=None) → list[source]

Calculate the membership values for a data point given fuzzy sets

Parameters:
  • inst – data point
  • fuzzy_sets – a dictionary where the key is the fuzzy set name and the value is the fuzzy set object.
  • ordered_sets – a list with the fuzzy sets names ordered by their centroids.
Returns:

array of membership values

pyFTS.common.FuzzySet.fuzzyfy_series(data, fuzzy_sets, method='maximum', alpha_cut=0.0, ordered_sets=None)[source]
pyFTS.common.FuzzySet.fuzzyfy_series_old(data, fuzzy_sets, method='maximum')[source]
pyFTS.common.FuzzySet.get_fuzzysets(inst, fuzzy_sets: dict, ordered_sets: list = None, alpha_cut: float = 0.0) → list[source]

Return the fuzzy sets which membership value for a inst is greater than the alpha_cut

Parameters:
  • inst – data point
  • fuzzy_sets – a dictionary where the key is the fuzzy set name and the value is the fuzzy set object.
  • ordered_sets – a list with the fuzzy sets names ordered by their centroids.
  • alpha_cut – Minimal membership to be considered on fuzzyfication process
Returns:

array of membership values

pyFTS.common.FuzzySet.get_maximum_membership_fuzzyset(inst, fuzzy_sets, ordered_sets=None) → pyFTS.common.FuzzySet.FuzzySet[source]

Fuzzify a data point, returning the fuzzy set with maximum membership value

Parameters:
  • inst – data point
  • fuzzy_sets – a dictionary where the key is the fuzzy set name and the value is the fuzzy set object.
  • ordered_sets – a list with the fuzzy sets names ordered by their centroids.
Returns:

fuzzy set with maximum membership

pyFTS.common.FuzzySet.get_maximum_membership_fuzzyset_index(inst, fuzzy_sets) → int[source]

Fuzzify a data point, returning the fuzzy set with maximum membership value

Parameters:
  • inst – data point
  • fuzzy_sets – dict of fuzzy sets
Returns:

fuzzy set with maximum membership

pyFTS.common.FuzzySet.grant_bounds(data, fuzzy_sets, ordered_sets)[source]
pyFTS.common.FuzzySet.set_ordered(fuzzy_sets)[source]

Order a fuzzy set list by their centroids

Parameters:fuzzy_sets – a dictionary where the key is the fuzzy set name and the value is the fuzzy set object.
Returns:a list with the fuzzy sets names ordered by their centroids.
pyFTS.common.Membership module

Membership functions for Fuzzy Sets

pyFTS.common.Membership.bellmf(x, parameters)[source]

Bell shaped membership function

Parameters:
  • x
  • parameters
Returns:

pyFTS.common.Membership.gaussmf(x, parameters)[source]

Gaussian fuzzy membership function

Parameters:
  • x – data point
  • parameters – a list with 2 real values (mean and variance)
Returns:

the membership value of x given the parameters

pyFTS.common.Membership.sigmf(x, parameters)[source]

Sigmoid / Logistic membership function

Parameters:
  • x
  • parameters – an list with 2 real values (smoothness and midpoint)

:return

pyFTS.common.Membership.singleton(x, parameters)[source]

Singleton membership function, a single value fuzzy function

Parameters:
  • x
  • parameters – a list with one real value

:returns

pyFTS.common.Membership.trapmf(x, parameters)[source]

Trapezoidal fuzzy membership function

Parameters:
  • x – data point
  • parameters – a list with 4 real values
Returns:

the membership value of x given the parameters

pyFTS.common.Membership.trimf(x, parameters)[source]

Triangular fuzzy membership function

Parameters:
  • x – data point
  • parameters – a list with 3 real values
Returns:

the membership value of x given the parameters

pyFTS.common.SortedCollection module
class pyFTS.common.SortedCollection.SortedCollection(iterable=(), key=None)[source]

Bases: object

Sequence sorted by a key function.

SortedCollection() is much easier to work with than using bisect() directly. It supports key functions like those use in sorted(), min(), and max(). The result of the key function call is saved so that keys can be searched efficiently.

Instead of returning an insertion-point which can be hard to interpret, the five find-methods return a specific item in the sequence. They can scan for exact matches, the last item less-than-or-equal to a key, or the first item greater-than-or-equal to a key.

Once found, an item’s ordinal position can be located with the index() method. New items can be added with the insert() and insert_right() methods. Old items can be deleted with the remove() method.

The usual sequence methods are provided to support indexing, slicing, length lookup, clearing, copying, forward and reverse iteration, contains checking, item counts, item removal, and a nice looking repr.

Finding and indexing are O(log n) operations while iteration and insertion are O(n). The initial sort is O(n log n).

The key function is stored in the ‘key’ attibute for easy introspection or so that you can assign a new key function (triggering an automatic re-sort).

In short, the class was designed to handle all of the common use cases for bisect but with a simpler API and support for key functions.

>>> from pprint import pprint
>>> from operator import itemgetter
>>> s = SortedCollection(key=itemgetter(2))
>>> for record in [
...         ('roger', 'young', 30),
...         ('angela', 'jones', 28),
...         ('bill', 'smith', 22),
...         ('david', 'thomas', 32)]:
...     s.insert(record)
>>> pprint(list(s))         # show records sorted by age
[('bill', 'smith', 22),
 ('angela', 'jones', 28),
 ('roger', 'young', 30),
 ('david', 'thomas', 32)]
>>> s.find_le(29)           # find oldest person aged 29 or younger
('angela', 'jones', 28)
>>> s.find_lt(28)           # find oldest person under 28
('bill', 'smith', 22)
>>> s.find_gt(28)           # find youngest person over 28
('roger', 'young', 30)
>>> r = s.find_ge(32)       # find youngest person aged 32 or older
>>> s.index(r)              # get the index of their record
3
>>> s[3]                    # fetch the record at that index
('david', 'thomas', 32)
>>> s.key = itemgetter(0)   # now sort by first name
>>> pprint(list(s))
[('angela', 'jones', 28),
 ('bill', 'smith', 22),
 ('david', 'thomas', 32),
 ('roger', 'young', 30)]
around(k)[source]
between(ge, le)[source]
clear()[source]
copy()[source]
count(item)[source]

Return number of occurrences of item

find(k)[source]

Return first item with a key == k. Raise ValueError if not found.

find_ge(k)[source]

Return first item with a key >= equal to k. Raise ValueError if not found

find_gt(k)[source]

Return first item with a key > k. Raise ValueError if not found

find_le(k)[source]

Return last item with a key <= k. Raise ValueError if not found.

find_lt(k)[source]

Return last item with a key < k. Raise ValueError if not found.

index(item)[source]

Find the position of an item. Raise ValueError if not found.

insert(item)[source]

Insert a new item. If equal keys are found, add to the left

insert_right(item)[source]

Insert a new item. If equal keys are found, add to the right

inside(ge, le)[source]
key

key function

remove(item)[source]

Remove first occurence of item. Raise ValueError if not found

pyFTS.common.Util module
pyFTS.common.flrg module
class pyFTS.common.flrg.FLRG(order, **kwargs)[source]

Bases: object

Fuzzy Logical Relationship Group

Group a set of FLR’s with the same LHS. Represents the temporal patterns for time t+1 (the RHS fuzzy sets) when the LHS pattern is identified on time t.

LHS = None

Left Hand Side of the rule

RHS = None

Right Hand Side of the rule

append_rhs(set, **kwargs)[source]
get_key()[source]

Returns a unique identifier for this FLRG

get_lower(sets)[source]

Returns the lower bound value for the RHS fuzzy sets

Parameters:sets – fuzzy sets
Returns:lower bound value
get_membership(data, sets)[source]

Returns the membership value of the FLRG for the input data

Parameters:
  • data – input data
  • sets – fuzzy sets
Returns:

the membership value

get_midpoint(sets)[source]

Returns the midpoint value for the RHS fuzzy sets

Parameters:sets – fuzzy sets
Returns:the midpoint value
get_midpoints(sets)[source]
get_upper(sets)[source]

Returns the upper bound value for the RHS fuzzy sets

Parameters:sets – fuzzy sets
Returns:upper bound value
order = None

Number of lags on LHS

reset_calculated_values()[source]
pyFTS.common.fts module
pyFTS.common.tree module

Tree data structure

class pyFTS.common.tree.FLRGTree[source]

Bases: object

Represents a FLRG set with a tree structure

class pyFTS.common.tree.FLRGTreeNode(value)[source]

Bases: object

Tree node for

appendChild(child)[source]
getChildren()[source]
getStr(k)[source]
paths(acc=[])[source]
pyFTS.common.tree.build_tree_without_order(node, lags, level)[source]
pyFTS.common.tree.flat(dados)[source]
pyFTS.common.transformations package
Module contents
Submodules
pyFTS.common.transformations.adapativeexpectation module
pyFTS.common.transformations.boxcox module
class pyFTS.common.transformations.boxcox.BoxCox(plambda)[source]

Bases: pyFTS.common.transformations.transformation.Transformation

Box-Cox power transformation

y’(t) = log( y(t) ) y(t) = exp( y’(t) )

apply(data, param=None, **kwargs)[source]

Apply the transformation on input data

Parameters:
  • data – input data
  • param
  • kwargs
Returns:

numpy array with transformed data

inverse(data, param=None, **kwargs)[source]
Parameters:
  • data – transformed data
  • param
  • kwargs
Returns:

numpy array with inverse transformed data

parameters
pyFTS.common.transformations.differential module
class pyFTS.common.transformations.differential.Differential(lag)[source]

Bases: pyFTS.common.transformations.transformation.Transformation

Differentiation data transform

y’(t) = y(t) - y(t-1) y(t) = y(t-1) + y’(t)

apply(data, param=None, **kwargs)[source]

Apply the transformation on input data

Parameters:
  • data – input data
  • param
  • kwargs
Returns:

numpy array with transformed data

inverse(data, param, **kwargs)[source]
Parameters:
  • data – transformed data
  • param
  • kwargs
Returns:

numpy array with inverse transformed data

parameters
pyFTS.common.transformations.normalization module
class pyFTS.common.transformations.normalization.Normalization(**kwargs)[source]

Bases: pyFTS.common.transformations.transformation.Transformation

apply(data, param=None, **kwargs)[source]

Apply the transformation on input data

Parameters:
  • data – input data
  • param
  • kwargs
Returns:

numpy array with transformed data

inverse(data, param=None, **kwargs)[source]
Parameters:
  • data – transformed data
  • param
  • kwargs
Returns:

numpy array with inverse transformed data

train(data, **kwargs)[source]
pyFTS.common.transformations.roi module
class pyFTS.common.transformations.roi.ROI(**kwargs)[source]

Bases: pyFTS.common.transformations.transformation.Transformation

Return of Investment (ROI) transformation. Retrieved from Sadaei and Lee (2014) - Multilayer Stock Forecasting Model Using Fuzzy Time Series

y’(t) = ( y(t) - y(t-1) ) / y(t-1) y(t) = ( y(t-1) * y’(t) ) + y(t-1)

apply(data, param=None, **kwargs)[source]

Apply the transformation on input data

Parameters:
  • data – input data
  • param
  • kwargs
Returns:

numpy array with transformed data

inverse(data, param=None, **kwargs)[source]
Parameters:
  • data – transformed data
  • param
  • kwargs
Returns:

numpy array with inverse transformed data

pyFTS.common.transformations.scale module
class pyFTS.common.transformations.scale.Scale(min=0, max=1)[source]

Bases: pyFTS.common.transformations.transformation.Transformation

Scale data inside a interval [min, max]

apply(data, param=None, **kwargs)[source]

Apply the transformation on input data

Parameters:
  • data – input data
  • param
  • kwargs
Returns:

numpy array with transformed data

inverse(data, param, **kwargs)[source]
Parameters:
  • data – transformed data
  • param
  • kwargs
Returns:

numpy array with inverse transformed data

parameters
pyFTS.common.transformations.smoothing module
class pyFTS.common.transformations.smoothing.AveragePooling(**kwargs)[source]

Bases: pyFTS.common.transformations.transformation.Transformation

apply(data)[source]

Apply the transformation on input data

Parameters:
  • data – input data
  • param
  • kwargs
Returns:

numpy array with transformed data

inverse(data, param=None, **kwargs)[source]
Parameters:
  • data – transformed data
  • param
  • kwargs
Returns:

numpy array with inverse transformed data

class pyFTS.common.transformations.smoothing.ExponentialSmoothing(**kwargs)[source]

Bases: pyFTS.common.transformations.transformation.Transformation

apply(data, param=None, **kwargs)[source]

Apply the transformation on input data

Parameters:
  • data – input data
  • param
  • kwargs
Returns:

numpy array with transformed data

inverse(data, param=None, **kwargs)[source]
Parameters:
  • data – transformed data
  • param
  • kwargs
Returns:

numpy array with inverse transformed data

class pyFTS.common.transformations.smoothing.MaxPooling(**kwargs)[source]

Bases: pyFTS.common.transformations.transformation.Transformation

apply(data)[source]

Apply the transformation on input data

Parameters:
  • data – input data
  • param
  • kwargs
Returns:

numpy array with transformed data

inverse(data, param=None, **kwargs)[source]
Parameters:
  • data – transformed data
  • param
  • kwargs
Returns:

numpy array with inverse transformed data

class pyFTS.common.transformations.smoothing.MovingAverage(**kwargs)[source]

Bases: pyFTS.common.transformations.transformation.Transformation

apply(data, param=None, **kwargs)[source]

Apply the transformation on input data

Parameters:
  • data – input data
  • param
  • kwargs
Returns:

numpy array with transformed data

inverse(data, param=None, **kwargs)[source]
Parameters:
  • data – transformed data
  • param
  • kwargs
Returns:

numpy array with inverse transformed data

pyFTS.common.transformations.som module

Kohonen Self Organizing Maps for Fuzzy Time Series

class pyFTS.common.transformations.som.SOMTransformation(grid_dimension: Tuple, **kwargs)[source]

Bases: pyFTS.common.transformations.transformation.Transformation

apply(data: pandas.core.frame.DataFrame, param=None, **kwargs)[source]

Transform a M-dimensional dataset into a 3-dimensional dataset, where one dimension is the endogen variable If endogen_variable = None, the last column will be the endogen_variable.

Args:

data (pd.DataFrame): M-Dimensional dataset endogen_variable (str): column of dataset names (Tuple): names for new columns created by SOM Transformation. param: **kwargs: params of SOM’s train process

percentage_train (float). Percentage of dataset that will be used for train SOM network. default: 0.7 leaning_rate (float): leaning rate of SOM network. default: 0.01 epochs: epochs of SOM network. default: 10000

Returns:

save_net(filename: str = 'SomNet trained')[source]
show_grid(graph_type: str = 'nodes_graph', **kwargs)[source]
train(data: pandas.core.frame.DataFrame, percentage_train: float = 0.7, leaning_rate: float = 0.01, epochs: int = 10000)[source]
pyFTS.common.transformations.transformation module
class pyFTS.common.transformations.transformation.Transformation(**kwargs)[source]

Bases: object

Data transformation used on pre and post processing of the FTS

apply(data, param, **kwargs)[source]

Apply the transformation on input data

Parameters:
  • data – input data
  • param
  • kwargs
Returns:

numpy array with transformed data

inverse(data, param, **kwargs)[source]
Parameters:
  • data – transformed data
  • param
  • kwargs
Returns:

numpy array with inverse transformed data

is_multivariate = None

detemine if this transformation can be applied to multivariate data

pyFTS.common.transformations.trend module
pyFTS.data package
Module contents

Module for pyFTS standard datasets facilities

Submodules
pyFTS.data.common module
pyFTS.data.common.get_dataframe(filename: str, url: str, sep: str = ';', compression: str = 'infer') → pandas.core.frame.DataFrame[source]

This method check if filename already exists, read the file and return its data. If the file don’t already exists, it will be downloaded and decompressed.

Parameters:
  • filename – dataset local filename
  • url – dataset internet URL
  • sep – CSV field separator
  • compression – type of compression
Returns:

Pandas dataset

Datasets
Artificial and synthetic data generators

Facilities to generate synthetic stochastic processes

class pyFTS.data.artificial.SignalEmulator(**kwargs)[source]

Bases: object

Emulate a complex signal built from several additive and non-additive components

blip(**kwargs)[source]

Creates an outlier greater than the maximum or lower then the minimum previous values of the signal, and insert it on a random location of the signal.

Returns:the current SignalEmulator instance, for method chaining
components = None

Components of the signal

incremental_gaussian(mu: float, sigma: float, **kwargs)[source]

Creates an additive gaussian interference on a previous signal

Parameters:
  • mu – increment on mean
  • sigma – increment on variance
  • start – lag index to start this signal, the default value is 0
  • it – Number of iterations, the default value is 1
  • length – Number of samples generated on each iteration, the default value is 100
  • vmin – Lower bound value of generated data, the default value is None
  • vmax – Upper bound value of generated data, the default value is None
Returns:

the current SignalEmulator instance, for method chaining

periodic_gaussian(type: str, period: int, mu_min: float, sigma_min: float, mu_max: float, sigma_max: float, **kwargs)[source]

Creates an additive periodic gaussian interference on a previous signal

Parameters:
  • type – ‘linear’ or ‘sinoidal’
  • period – the period of recurrence
  • mu – increment on mean
  • sigma – increment on variance
  • start – lag index to start this signal, the default value is 0
  • it – Number of iterations, the default value is 1
  • length – Number of samples generated on each iteration, the default value is 100
  • vmin – Lower bound value of generated data, the default value is None
  • vmax – Upper bound value of generated data, the default value is None
Returns:

the current SignalEmulator instance, for method chaining

run()[source]

Render the signal

Returns:a list of float values
stationary_gaussian(mu: float, sigma: float, **kwargs)[source]

Creates a continuous Gaussian signal with mean mu and variance sigma.

Parameters:
  • mu – mean
  • sigma – variance
  • additive – If False it cancels the previous signal and start this one, if True this signal is added to the previous one
  • start – lag index to start this signal, the default value is 0
  • it – Number of iterations, the default value is 1
  • length – Number of samples generated on each iteration, the default value is 100
  • vmin – Lower bound value of generated data, the default value is None
  • vmax – Upper bound value of generated data, the default value is None
Returns:

the current SignalEmulator instance, for method chaining

pyFTS.data.artificial.generate_gaussian_linear(mu_ini, sigma_ini, mu_inc, sigma_inc, it=100, num=10, vmin=None, vmax=None)[source]

Generate data sampled from Gaussian distribution, with constant or linear changing parameters

Parameters:
  • mu_ini – Initial mean
  • sigma_ini – Initial variance
  • mu_inc – Mean increment after ‘num’ samples
  • sigma_inc – Variance increment after ‘num’ samples
  • it – Number of iterations
  • num – Number of samples generated on each iteration
  • vmin – Lower bound value of generated data
  • vmax – Upper bound value of generated data
Returns:

A list of it*num float values

pyFTS.data.artificial.generate_linear_periodic_gaussian(period, mu_min, sigma_min, mu_max, sigma_max, it=100, num=10, vmin=None, vmax=None)[source]

Generates a periodic linear variation on mean and variance

Parameters:
  • period – the period of recurrence
  • mu_min – initial (and minimum) mean of each period
  • sigma_min – initial (and minimum) variance of each period
  • mu_max – final (and maximum) mean of each period
  • sigma_max – final (and maximum) variance of each period
  • it – Number of iterations
  • num – Number of samples generated on each iteration
  • vmin – Lower bound value of generated data
  • vmax – Upper bound value of generated data
Returns:

A list of it*num float values

pyFTS.data.artificial.generate_sinoidal_periodic_gaussian(period, mu_min, sigma_min, mu_max, sigma_max, it=100, num=10, vmin=None, vmax=None)[source]

Generates a periodic sinoidal variation on mean and variance

Parameters:
  • period – the period of recurrence
  • mu_min – initial (and minimum) mean of each period
  • sigma_min – initial (and minimum) variance of each period
  • mu_max – final (and maximum) mean of each period
  • sigma_max – final (and maximum) variance of each period
  • it – Number of iterations
  • num – Number of samples generated on each iteration
  • vmin – Lower bound value of generated data
  • vmax – Upper bound value of generated data
Returns:

A list of it*num float values

pyFTS.data.artificial.generate_uniform_linear(min_ini, max_ini, min_inc, max_inc, it=100, num=10, vmin=None, vmax=None)[source]

Generate data sampled from Uniform distribution, with constant or linear changing bounds

Parameters:
  • mu_ini – Initial mean
  • sigma_ini – Initial variance
  • mu_inc – Mean increment after ‘num’ samples
  • sigma_inc – Variance increment after ‘num’ samples
  • it – Number of iterations
  • num – Number of samples generated on each iteration
  • vmin – Lower bound value of generated data
  • vmax – Upper bound value of generated data
Returns:

A list of it*num float values

pyFTS.data.artificial.random_walk(n=500, type='gaussian')[source]

Simple random walk

Parameters:
  • n – number of samples
  • type – ‘gaussian’ or ‘uniform’
Returns:

pyFTS.data.artificial.white_noise(n=500)[source]

Simple Gaussian noise signal :param n: number of samples :return:

AirPassengers dataset

Monthly totals of a airline passengers from USA, from January 1949 through December 1960.

Source: Hyndman, R.J., Time Series Data Library, http://www-personal.buseco.monash.edu.au/~hyndman/TSDL/.

pyFTS.data.AirPassengers.get_data() → numpy.ndarray[source]

Get a simple univariate time series data.

Returns:numpy array
pyFTS.data.AirPassengers.get_dataframe() → pandas.core.frame.DataFrame[source]

Get the complete multivariate time series data.

Returns:Pandas DataFrame
Bitcoin dataset

Bitcoin to USD quotations

Daily averaged index, by business day, from 2010 to 2018.

Source: https://finance.yahoo.com/quote/BTC-USD?p=BTC-USD

pyFTS.data.Bitcoin.get_data(field: str = 'AVG') → numpy.ndarray[source]

Get the univariate time series data.

Parameters:field – dataset field to load
Returns:numpy array
pyFTS.data.Bitcoin.get_dataframe() → pandas.core.frame.DataFrame[source]

Get the complete multivariate time series data.

Returns:Pandas DataFrame
DowJones dataset

DJI - Dow Jones

Daily averaged index, by business day, from 1985 to 2017.

Source: https://finance.yahoo.com/quote/%5EGSPC/history?p=%5EGSPC

pyFTS.data.DowJones.get_data(field: str = 'AVG') → numpy.ndarray[source]

Get the univariate time series data.

Parameters:field – dataset field to load
Returns:numpy array
pyFTS.data.DowJones.get_dataframe() → pandas.core.frame.DataFrame[source]

Get the complete multivariate time series data.

Returns:Pandas DataFrame
Enrollments dataset

Yearly University of Alabama enrollments from 1971 to 1992.

pyFTS.data.Enrollments.get_data() → numpy.ndarray[source]

Get a simple univariate time series data.

Returns:numpy array
pyFTS.data.Enrollments.get_dataframe() → pandas.core.frame.DataFrame[source]
Ethereum dataset

Ethereum to USD quotations

Daily averaged index, by business day, from 2016 to 2018.

Source: https://finance.yahoo.com/quote/ETH-USD?p=ETH-USD

pyFTS.data.Ethereum.get_data(field: str = 'AVG') → numpy.ndarray[source]

Get the univariate time series data.

Parameters:field – dataset field to load
Returns:numpy array
pyFTS.data.Ethereum.get_dataframe() → pandas.core.frame.DataFrame[source]

Get the complete multivariate time series data.

Returns:Pandas DataFrame
EUR-GBP dataset

FOREX market EUR-GBP pair.

Daily averaged quotations, by business day, from 2016 to 2018.

pyFTS.data.EURGBP.get_data(field: str = 'avg') → numpy.ndarray[source]

Get the univariate time series data.

Parameters:field – dataset field to load
Returns:numpy array
pyFTS.data.EURGBP.get_dataframe() → pandas.core.frame.DataFrame[source]

Get the complete multivariate time series data.

Returns:Pandas DataFrame
EUR-USD dataset

FOREX market EUR-USD pair.

Daily averaged quotations, by business day, from 2016 to 2018.

pyFTS.data.EURUSD.get_data(field: str = 'avg') → numpy.ndarray[source]

Get the univariate time series data.

Parameters:field – dataset field to load
Returns:numpy array
pyFTS.data.EURUSD.get_dataframe() → pandas.core.frame.DataFrame[source]

Get the complete multivariate time series data.

Returns:Pandas DataFrame
GBP-USD dataset

FOREX market GBP-USD pair.

Daily averaged quotations, by business day, from 2016 to 2018.

pyFTS.data.GBPUSD.get_data(field: str = 'avg') → numpy.ndarray[source]

Get the univariate time series data.

Parameters:field – dataset field to load
Returns:numpy array
pyFTS.data.GBPUSD.get_dataframe() → pandas.core.frame.DataFrame[source]

Get the complete multivariate time series data.

Returns:Pandas DataFrame
INMET dataset

INMET - Instituto Nacional Meteorologia / Brasil

Belo Horizonte station, from 2000-01-01 to 31/12/2012

Source: http://www.inmet.gov.br

pyFTS.data.INMET.get_dataframe() → pandas.core.frame.DataFrame[source]

Get the complete multivariate time series data.

Returns:Pandas DataFrame
Malaysia dataset

Hourly Malaysia eletric load and tempeature

pyFTS.data.Malaysia.get_data(field: str = 'load') → numpy.ndarray[source]

Get the univariate time series data.

Parameters:field – dataset field to load
Returns:numpy array
pyFTS.data.Malaysia.get_dataframe() → pandas.core.frame.DataFrame[source]

Get the complete multivariate time series data.

Returns:Pandas DataFrame
NASDAQ module

National Association of Securities Dealers Automated Quotations - Composite Index (NASDAQ IXIC)

Daily averaged index by business day, from 2000 to 2016.

Source: http://www.nasdaq.com/aspx/flashquotes.aspx?symbol=IXIC&selected=IXIC

pyFTS.data.NASDAQ.get_data(field: str = 'avg') → numpy.ndarray[source]

Get a simple univariate time series data.

Parameters:field – the dataset field name to extract
Returns:numpy array
pyFTS.data.NASDAQ.get_dataframe() → pandas.core.frame.DataFrame[source]

Get the complete multivariate time series data.

Returns:Pandas DataFrame
SONDA dataset

SONDA - Sistema de Organização Nacional de Dados Ambientais, from INPE - Instituto Nacional de Pesquisas Espaciais, Brasil.

Brasilia station

Source: http://sonda.ccst.inpe.br/

pyFTS.data.SONDA.get_data(field: str) → numpy.ndarray[source]

Get a simple univariate time series data.

Parameters:field – the dataset field name to extract
Returns:numpy array
pyFTS.data.SONDA.get_dataframe() → pandas.core.frame.DataFrame[source]

Get the complete multivariate time series data.

Returns:Pandas DataFrame
S&P 500 dataset

S&P500 - Standard & Poor’s 500

Daily averaged index, by business day, from 1950 to 2017.

Source: https://finance.yahoo.com/quote/%5EGSPC/history?p=%5EGSPC

pyFTS.data.SP500.get_data() → numpy.ndarray[source]

Get the univariate time series data.

Returns:numpy array
pyFTS.data.SP500.get_dataframe() → pandas.core.frame.DataFrame[source]

Get the complete multivariate time series data.

Returns:Pandas DataFrame
TAIEX dataset

The Taiwan Stock Exchange Capitalization Weighted Stock Index (TAIEX)

Daily averaged index by business day, from 1995 to 2014.

Source: http://www.twse.com.tw/en/products/indices/Index_Series.php

pyFTS.data.TAIEX.get_data() → numpy.ndarray[source]

Get the univariate time series data.

Returns:numpy array
pyFTS.data.TAIEX.get_dataframe() → pandas.core.frame.DataFrame[source]

Get the complete multivariate time series data.

Returns:Pandas DataFrame
Henon chaotic time series
  1. Hénon. “A two-dimensional mapping with a strange attractor”. Commun. Math. Phys. 50, 69-77 (1976)

dx/dt = a + by(t-1) - x(t-1)^2 dy/dt = x

pyFTS.data.henon.get_data(var: str, a: float = 1.4, b: float = 0.3, initial_values: list = [1, 1], iterations: int = 1000) → pandas.core.frame.DataFrame[source]

Get a simple univariate time series data.

Parameters:var – the dataset field name to extract
Returns:numpy array
pyFTS.data.henon.get_dataframe(a: float = 1.4, b: float = 0.3, initial_values: list = [1, 1], iterations: int = 1000) → pandas.core.frame.DataFrame[source]

Return a dataframe with the bivariate Henon Map time series (x, y).

Parameters:
  • a – Equation coefficient
  • b – Equation coefficient
  • initial_values – numpy array with the initial values of x and y. Default: [1, 1]
  • iterations – number of iterations. Default: 1000
Returns:

Panda dataframe with the x and y values

Logistic_map chaotic time series

May, Robert M. (1976). “Simple mathematical models with very complicated dynamics”. Nature. 261 (5560): 459–467. doi:10.1038/261459a0.

x(t) = r * x(t-1) * (1 - x(t -1) )

pyFTS.data.logistic_map.get_data(r: float = 4, initial_value: float = 0.3, iterations: int = 100) → list[source]

Return a list with the logistic map chaotic time series.

Parameters:
  • r – Equation coefficient
  • initial_value – Initial value of x. Default: 0.3
  • iterations – number of iterations. Default: 100
Returns:

Lorentz chaotic time series

Lorenz, Edward Norton (1963). “Deterministic nonperiodic flow”. Journal of the Atmospheric Sciences. 20 (2): 130–141. https://doi.org/10.1175/1520-0469(1963)020<0130:DNF>2.0.CO;2

dx/dt = a(y -x) dy/dt = x(b - z) - y dz/dt = xy - cz

pyFTS.data.lorentz.get_data(var: str, a: float = 10.0, b: float = 28.0, c: float = 2.6666666666666665, dt: float = 0.01, initial_values: list = [0.1, 0, 0], iterations: int = 1000) → pandas.core.frame.DataFrame[source]

Get a simple univariate time series data.

Parameters:var – the dataset field name to extract
Returns:numpy array
pyFTS.data.lorentz.get_dataframe(a: float = 10.0, b: float = 28.0, c: float = 2.6666666666666665, dt: float = 0.01, initial_values: list = [0.1, 0, 0], iterations: int = 1000) → pandas.core.frame.DataFrame[source]

Return a dataframe with the multivariate Lorenz Map time series (x, y, z).

Parameters:
  • a – Equation coefficient. Default value: 10
  • b – Equation coefficient. Default value: 28
  • c – Equation coefficient. Default value: 8.0/3.0
  • dt – Time differential for continuous time integration. Default value: 0.01
  • initial_values – numpy array with the initial values of x,y and z. Default: [0.1, 0, 0]
  • iterations – number of iterations. Default: 1000
Returns:

Panda dataframe with the x, y and z values

Mackey-Glass chaotic time series

Mackey, M. C. and Glass, L. (1977). Oscillation and chaos in physiological control systems. Science, 197(4300):287-289.

dy/dt = -by(t)+ cy(t - tau) / 1+y(t-tau)^10

pyFTS.data.mackey_glass.get_data(b: float = 0.1, c: float = 0.2, tau: float = 17, initial_values: numpy.ndarray = array([0.5, 0.55882353, 0.61764706, 0.67647059, 0.73529412, 0.79411765, 0.85294118, 0.91176471, 0.97058824, 1.02941176, 1.08823529, 1.14705882, 1.20588235, 1.26470588, 1.32352941, 1.38235294, 1.44117647, 1.5 ]), iterations: int = 1000) → list[source]

Return a list with the Mackey-Glass chaotic time series.

Parameters:
  • b – Equation coefficient
  • c – Equation coefficient
  • tau – Lag parameter, default: 17
  • initial_values – numpy array with the initial values of y. Default: np.linspace(0.5,1.5,18)
  • iterations – number of iterations. Default: 1000
Returns:

Rossler chaotic time series
    1. Rössler, Phys. Lett. 57A, 397 (1976).

dx/dt = -z - y dy/dt = x + ay dz/dt = b + z( x - c )

pyFTS.data.rossler.get_data(var: str, a: float = 0.2, b: float = 0.2, c: float = 5.7, dt: float = 0.01, initial_values: numpy.ndarray = [0.001, 0.001, 0.001], iterations: int = 5000) → numpy.ndarray[source]

Get a simple univariate time series data.

Parameters:var – the dataset field name to extract
Returns:numpy array
pyFTS.data.rossler.get_dataframe(a: float = 0.2, b: float = 0.2, c: float = 5.7, dt: float = 0.01, initial_values: numpy.ndarray = [0.001, 0.001, 0.001], iterations: int = 5000) → pandas.core.frame.DataFrame[source]

Return a dataframe with the multivariate Rössler Map time series (x, y, z).

Parameters:
  • a – Equation coefficient. Default value: 0.2
  • b – Equation coefficient. Default value: 0.2
  • c – Equation coefficient. Default value: 5.7
  • dt – Time differential for continuous time integration. Default value: 0.01
  • initial_values – numpy array with the initial values of x,y and z. Default: [0.001, 0.001, 0.001]
  • iterations – number of iterations. Default: 5000
Returns:

Panda dataframe with the x, y and z values

Sunspots dataset

Monthly sunspot numbers from 1749 to May 2016

Source: https://www.esrl.noaa.gov/psd/gcos_wgsp/Timeseries/SUNSPOT/

pyFTS.data.sunspots.get_data() → numpy.ndarray[source]

Get a simple univariate time series data.

Returns:numpy array
pyFTS.data.sunspots.get_dataframe() → pandas.core.frame.DataFrame[source]

Get the complete multivariate time series data.

Returns:Pandas DataFrame
pyFTS.distributed package
Module contents
Submodules
pyFTS.distributed.dispy module
pyFTS.distributed.spark module
pyFTS.hyperparam package
Module contents
Submodules
pyFTS.hyperparam.Util module

Common facilities for hyperparameter optimization

pyFTS.hyperparam.Util.create_hyperparam_tables(conn)[source]

Create a sqlite3 table designed to store benchmark results.

Parameters:conn – a sqlite3 database connection
pyFTS.hyperparam.Util.insert_hyperparam(data, conn)[source]

Insert benchmark data on database

Parameters:data – a tuple with the benchmark data with format:

Dataset: Identify on which dataset the dataset was performed Tag: a user defined word that indentify a benchmark set Model: FTS model Transformation: The name of data transformation, if one was used mf: membership function Order: the order of the FTS method Partitioner: UoD partitioning scheme Partitions: Number of partitions alpha: alpha cut lags: lags Measure: accuracy measure Value: the measure value

Parameters:conn – a sqlite3 database connection
Returns:
pyFTS.hyperparam.Util.open_hyperparam_db(name)[source]

Open a connection with a Sqlite database designed to store benchmark results.

Parameters:name – database filenem
Returns:a sqlite3 database connection
pyFTS.hyperparam.GridSearch module
pyFTS.hyperparam.Evolutionary module
pyFTS.models package
Module contents

Fuzzy Time Series methods

Subpackages
pyFTS.models.ensemble package
Submodules
pyFTS.models.ensemble.ensemble module
pyFTS.models.ensemble.multiseasonal module
Module contents

Meta FTS that aggregates other FTS methods

pyFTS.models.incremental package
Module contents

FTS methods with incremental/online learning

Submodules
pyFTS.models.incremental.TimeVariant module
pyFTS.models.incremental.IncrementalEnsemble module
pyFTS.models.multivariate package
Module contents

Multivariate Fuzzy Time Series methods

Submodules
pyFTS.models.multivariate.FLR module
class pyFTS.models.multivariate.FLR.FLR[source]

Bases: object

Multivariate Fuzzy Logical Relationship

set_lhs(var, set)[source]
set_rhs(set)[source]
pyFTS.models.multivariate.common module
class pyFTS.models.multivariate.common.MultivariateFuzzySet(**kwargs)[source]

Bases: pyFTS.common.Composite.FuzzySet

Multivariate Composite Fuzzy Set

append_set(variable, set)[source]

Appends a new fuzzy set from a new variable

Parameters:
  • variable – an multivariate.variable instance
  • set – an common.FuzzySet instance
membership(x)[source]

Calculate the membership value of a given input

Parameters:x – input value
Returns:membership value of x at this fuzzy set
set_target_variable(variable)[source]
pyFTS.models.multivariate.common.fuzzyfy_instance(data_point, var, tuples=True)[source]
pyFTS.models.multivariate.common.fuzzyfy_instance_clustered(data_point, cluster, **kwargs)[source]
pyFTS.models.multivariate.variable module
pyFTS.models.multivariate.flrg module
class pyFTS.models.multivariate.flrg.FLRG(**kwargs)[source]

Bases: pyFTS.common.flrg.FLRG

Multivariate Fuzzy Logical Rule Group

append_rhs(fset, **kwargs)[source]
get_lower(sets)[source]

Returns the lower bound value for the RHS fuzzy sets

Parameters:sets – fuzzy sets
Returns:lower bound value
get_membership(data, variables)[source]

Returns the membership value of the FLRG for the input data

Parameters:
  • data – input data
  • sets – fuzzy sets
Returns:

the membership value

get_upper(sets)[source]

Returns the upper bound value for the RHS fuzzy sets

Parameters:sets – fuzzy sets
Returns:upper bound value
set_lhs(var, fset)[source]
pyFTS.models.multivariate.partitioner module
class pyFTS.models.multivariate.partitioner.MultivariatePartitioner(**kwargs)[source]

Bases: pyFTS.partitioners.partitioner.Partitioner

Base class for partitioners which use the MultivariateFuzzySet

append(fset)[source]
build(data)[source]

Perform the partitioning of the Universe of Discourse

Parameters:data – training data
Returns:
build_index()[source]
change_target_variable(variable)[source]
format_data(data)[source]
fuzzyfy(data, **kwargs)[source]

Fuzzyfy the input data according to this partitioner fuzzy sets.

Parameters:
  • data – input value to be fuzzyfied
  • alpha_cut – the minimal membership value to be considered on fuzzyfication (only for mode=’sets’)
  • method – the fuzzyfication method (fuzzy: all fuzzy memberships, maximum: only the maximum membership)
  • mode – the fuzzyfication mode (sets: return the fuzzy sets names, vector: return a vector with the membership

values for all fuzzy sets, both: return a list with tuples (fuzzy set, membership value) )

:returns a list with the fuzzyfied values, depending on the mode

prune()[source]
search(data, **kwargs)[source]

Perform a search for the nearest fuzzy sets of the point ‘data’. This function were designed to work with several overlapped fuzzy sets.

Parameters:
  • data – the value to search for the nearest fuzzy sets
  • type – the return type: ‘index’ for the fuzzy set indexes or ‘name’ for fuzzy set names.
Returns:

a list with the nearest fuzzy sets

pyFTS.models.multivariate.grid module
class pyFTS.models.multivariate.grid.GridCluster(**kwargs)[source]

Bases: pyFTS.models.multivariate.partitioner.MultivariatePartitioner

A cartesian product of all fuzzy sets of all variables

build(data)[source]

Perform the partitioning of the Universe of Discourse

Parameters:data – training data
Returns:
defuzzyfy(values, mode='both')[source]
class pyFTS.models.multivariate.grid.IncrementalGridCluster(**kwargs)[source]

Bases: pyFTS.models.multivariate.partitioner.MultivariatePartitioner

Create combinations of fuzzy sets of the variables on demand, incrementally increasing the multivariate fuzzy set base.

fuzzyfy(data, **kwargs)[source]

Fuzzyfy the input data according to this partitioner fuzzy sets.

Parameters:
  • data – input value to be fuzzyfied
  • alpha_cut – the minimal membership value to be considered on fuzzyfication (only for mode=’sets’)
  • method – the fuzzyfication method (fuzzy: all fuzzy memberships, maximum: only the maximum membership)
  • mode – the fuzzyfication mode (sets: return the fuzzy sets names, vector: return a vector with the membership

values for all fuzzy sets, both: return a list with tuples (fuzzy set, membership value) )

:returns a list with the fuzzyfied values, depending on the mode

prune()[source]
pyFTS.models.multivariate.mvfts module
pyFTS.models.multivariate.wmvfts module
pyFTS.models.multivariate.cmvfts module
pyFTS.models.multivariate.granular module
pyFTS.models.nonstationary package
Submodules
pyFTS.models.nonstationary.common module

Non Stationary Fuzzy Sets

GARIBALDI, Jonathan M.; JAROSZEWSKI, Marcin; MUSIKASUWAN, Salang. Nonstationary fuzzy sets. IEEE Transactions on Fuzzy Systems, v. 16, n. 4, p. 1072-1086, 2008.

class pyFTS.models.nonstationary.common.FuzzySet(name, mf, parameters, **kwargs)[source]

Bases: pyFTS.common.FuzzySet.FuzzySet

Non Stationary Fuzzy Sets

get_lower(t)[source]
get_midpoint(t)[source]
get_upper(t)[source]
location = None

Pertubation function that affects the location of the membership function

location_params = None

Parameters for location pertubation function

membership(x, t)[source]

Calculate the membership value of a given input

Parameters:
  • x – input value
  • t – time displacement or perturbation parameters
Returns:

membership value of x at this fuzzy set

noise = None

Pertubation function that adds noise on the membership function

noise_params = None

Parameters for noise pertubation function

perform_location(t, param)[source]
perform_width(t, param)[source]
perturbate_parameters(t)[source]
width = None

Pertubation function that affects the width of the membership function

width_params = None

Parameters for width pertubation function

pyFTS.models.nonstationary.common.check_bounds(data, partitioner, t)[source]
pyFTS.models.nonstationary.common.check_bounds_index(data, partitioner, t)[source]
pyFTS.models.nonstationary.common.fuzzify(inst, t, fuzzySets)[source]

Calculate the membership values for a data point given nonstationary fuzzy sets

Parameters:
  • inst – data points
  • t – time displacement of the instance
  • fuzzySets – list of fuzzy sets
Returns:

array of membership values

pyFTS.models.nonstationary.common.fuzzySeries(data, fuzzySets, ordered_sets, window_size=1, method='fuzzy', const_t=None)[source]
pyFTS.models.nonstationary.common.window_index(t, window_size)[source]
pyFTS.models.nonstationary.cvfts module
pyFTS.models.nonstationary.flrg module
class pyFTS.models.nonstationary.flrg.NonStationaryFLRG(LHS, **kwargs)[source]

Bases: pyFTS.common.flrg.FLRG

get_key()[source]

Returns a unique identifier for this FLRG

get_lower(*args)[source]

Returns the lower bound value for the RHS fuzzy sets

Parameters:sets – fuzzy sets
Returns:lower bound value
get_membership(data, *args)[source]

Returns the membership value of the FLRG for the input data

Parameters:
  • data – input data
  • sets – fuzzy sets
Returns:

the membership value

get_midpoint(*args)[source]

Returns the midpoint value for the RHS fuzzy sets

Parameters:sets – fuzzy sets
Returns:the midpoint value
get_upper(*args)[source]

Returns the upper bound value for the RHS fuzzy sets

Parameters:sets – fuzzy sets
Returns:upper bound value
unpack_args(*args)[source]
pyFTS.models.nonstationary.honsfts module
pyFTS.models.nonstationary.nsfts module
pyFTS.models.nonstationary.partitioners module
class pyFTS.models.nonstationary.partitioners.PolynomialNonStationaryPartitioner(data, part, **kwargs)[source]

Bases: pyFTS.partitioners.partitioner.Partitioner

Non Stationary Universe of Discourse Partitioner

build(data)[source]

Perform the partitioning of the Universe of Discourse

Parameters:data – training data
Returns:
get_polynomial_perturbations(data, **kwargs)[source]
poly_width(par1, par2, rng, deg)[source]
scale_down(x, pct)[source]
scale_up(x, pct)[source]
class pyFTS.models.nonstationary.partitioners.SimpleNonStationaryPartitioner(data, part, **kwargs)[source]

Bases: pyFTS.partitioners.partitioner.Partitioner

Non Stationary Universe of Discourse Partitioner

build(data)[source]

Perform the partitioning of the Universe of Discourse

Parameters:data – training data
Returns:
pyFTS.models.nonstationary.partitioners.simplenonstationary_gridpartitioner_builder(data, npart, transformation)[source]
pyFTS.models.nonstationary.perturbation module

Pertubation functions for Non Stationary Fuzzy Sets

pyFTS.models.nonstationary.perturbation.exponential(x, parameters)[source]
pyFTS.models.nonstationary.perturbation.linear(x, parameters)[source]
pyFTS.models.nonstationary.perturbation.periodic(x, parameters)[source]
pyFTS.models.nonstationary.perturbation.polynomial(x, parameters)[source]
pyFTS.models.nonstationary.util module
Module contents

Fuzzy time series with nonstationary fuzzy sets, for heteroskedastic data

pyFTS.models.seasonal package
Submodules
pyFTS.models.seasonal.SeasonalIndexer module
class pyFTS.models.seasonal.SeasonalIndexer.DataFrameSeasonalIndexer(index_fields, index_seasons, data_field, **kwargs)[source]

Bases: pyFTS.models.seasonal.SeasonalIndexer.SeasonalIndexer

Use the Pandas.DataFrame index position to index the seasonality

get_data(data)[source]
get_data_by_season(data, indexes)[source]
get_index_by_season(indexes)[source]
get_season_by_index(index)[source]
get_season_of_data(data)[source]
set_data(data, value)[source]
class pyFTS.models.seasonal.SeasonalIndexer.DateTimeSeasonalIndexer(date_field, index_fields, index_seasons, data_field, **kwargs)[source]

Bases: pyFTS.models.seasonal.SeasonalIndexer.SeasonalIndexer

Use a Pandas.DataFrame date field to index the seasonality

get_data(data)[source]
get_data_by_season(data, indexes)[source]
get_index(data)[source]
get_index_by_season(indexes)[source]
get_season_by_index(index)[source]
get_season_of_data(data)[source]
set_data(data, value)[source]
class pyFTS.models.seasonal.SeasonalIndexer.LinearSeasonalIndexer(seasons, units, ignore=None, **kwargs)[source]

Bases: pyFTS.models.seasonal.SeasonalIndexer.SeasonalIndexer

Use the data array/list position to index the seasonality

get_data(data)[source]
get_index_by_season(indexes)[source]
get_season_by_index(index)[source]
get_season_of_data(data)[source]
class pyFTS.models.seasonal.SeasonalIndexer.SeasonalIndexer(num_seasons, **kwargs)[source]

Bases: object

Seasonal Indexer. Responsible to find the seasonal index of a data point inside its data set

get_data(data)[source]
get_data_by_season(data, indexes)[source]
get_index(data)[source]
get_index_by_season(indexes)[source]
get_season_by_index(inde)[source]
get_season_of_data(data)[source]
pyFTS.models.seasonal.cmsfts module
pyFTS.models.seasonal.common module
class pyFTS.models.seasonal.common.DateTime[source]

Bases: enum.Enum

Data and Time granularity for time granularity and seasonality identification

day_of_month = 30
day_of_week = 7
day_of_year = 364
half = 2
hour = 24
hour_of_day = 24
hour_of_month = 744
hour_of_week = 168
hour_of_year = 8736
minute = 60
minute_of_day = 1440
minute_of_hour = 60
minute_of_month = 44640
minute_of_week = 10080
minute_of_year = 524160
month = 12
quarter = 4
second = 60
second_of_day = 86400
second_of_hour = 3600
second_of_minute = 60.00001
sixth = 6
third = 3
year = 1
class pyFTS.models.seasonal.common.FuzzySet(datepart, name, mf, parameters, centroid, alpha=1.0, **kwargs)[source]

Bases: pyFTS.common.FuzzySet.FuzzySet

Temporal/Seasonal Fuzzy Set

transform(x)[source]

Preprocess the data point for non native types

Parameters:x
Returns:return a native type value for the structured type
pyFTS.models.seasonal.common.strip_datepart(date, date_part, mask='')[source]
pyFTS.models.seasonal.msfts module
pyFTS.models.seasonal.partitioner module
class pyFTS.models.seasonal.partitioner.TimeGridPartitioner(**kwargs)[source]

Bases: pyFTS.partitioners.partitioner.Partitioner

Even Length DateTime Grid Partitioner

build(data)[source]

Perform the partitioning of the Universe of Discourse

Parameters:data – training data
Returns:
build_index()[source]
extractor(x)[source]

Extract a single primitive type from an structured instance

mask = None

A string with datetime formating mask

plot(ax)[source]

Plot the :param ax: :return:

search(data, **kwargs)[source]

Perform a search for the nearest fuzzy sets of the point ‘data’. This function were designed to work with several overlapped fuzzy sets.

Parameters:
  • data – the value to search for the nearest fuzzy sets
  • type – the return type: ‘index’ for the fuzzy set indexes or ‘name’ for fuzzy set names.
  • results – the number of nearest fuzzy sets to return
Returns:

a list with the nearest fuzzy sets

season = None

Seasonality, a pyFTS.models.seasonal.common.DateTime object

pyFTS.models.seasonal.sfts module
Module contents
Submodules
pyFTS.models.song module
pyFTS.models.chen module
pyFTS.models.yu module
pyFTS.models.cheng module
pyFTS.models.hofts module
pyFTS.models.hwang module
pyFTS.models.ifts module
pyFTS.models.ismailefendi module
pyFTS.models.pwfts module
pyFTS.models.sadaei module
pyFTS.partitioners package
Module contents

Module for pyFTS Universe of Discourse partitioners.

Submodules
pyFTS.partitioners.partitioner module
class pyFTS.partitioners.partitioner.Partitioner(**kwargs)[source]

Bases: object

Universe of Discourse partitioner. Split data on several fuzzy sets

build(data)[source]

Perform the partitioning of the Universe of Discourse

Parameters:data – training data
Returns:
build_index()[source]
check_bounds(data)[source]

Check if the input data is outside the known Universe of Discourse and, if it is, round it to the closest fuzzy set.

Parameters:data – input data to be verified
Returns:the index of the closest fuzzy set when data is outside de universe of discourse or None if

the data is inside the UoD.

defuzzyfy(values, mode='both')[source]
extractor(x)[source]

Extract a single primitive type from an structured instance

fuzzyfy(data, **kwargs)[source]

Fuzzyfy the input data according to this partitioner fuzzy sets.

Parameters:
  • data – input value to be fuzzyfied
  • alpha_cut – the minimal membership value to be considered on fuzzyfication (only for mode=’sets’)
  • method – the fuzzyfication method (fuzzy: all fuzzy memberships, maximum: only the maximum membership)
  • mode – the fuzzyfication mode (sets: return the fuzzy sets names, vector: return a vector with the membership

values for all fuzzy sets, both: return a list with tuples (fuzzy set, membership value) )

:returns a list with the fuzzyfied values, depending on the mode

get_name(counter)[source]

Find the name of the fuzzy set given its counter id.

Parameters:counter – The number of the fuzzy set
Returns:String
kdtree = None

A spatial index to help in fuzzyfication

lower_margin = None

Specific lower exceeding margins for the known UoD. The default value is the self.margin parameter

lower_set()[source]

Return the fuzzy set on lower bound of the universe of discourse.

Returns:Fuzzy Set
margin = None

The upper and lower exceeding margins for the known UoD. The default value is .1

membership_function = None

Fuzzy membership function (pyFTS.common.Membership)

name = None

partitioner name

ordered_sets = None

A ordered list of the fuzzy sets names, sorted by their middle point

partitions = None

The number of universe of discourse partitions, i.e., the number of fuzzy sets that will be created

plot(ax, rounding=0)[source]

Plot the partitioning using the Matplotlib axis ax

Parameters:ax – Matplotlib axis
plot_set(ax, s)[source]

Plot an isolate fuzzy set on Matplotlib axis

Parameters:
  • ax – Matplotlib axis
  • s – Fuzzy Set
prefix = None

prefix of auto generated partition names

search(data, **kwargs)[source]

Perform a search for the nearest fuzzy sets of the point ‘data’. This function were designed to work with several overlapped fuzzy sets.

Parameters:
  • data – the value to search for the nearest fuzzy sets
  • type – the return type: ‘index’ for the fuzzy set indexes or ‘name’ for fuzzy set names.
  • results – the number of nearest fuzzy sets to return
Returns:

a list with the nearest fuzzy sets

setnames = None

list of partitions names. If None is given the partitions will be auto named with prefix

sets = None

The fuzzy sets dictionary

transformation = None

data transformation to be applied on data

type = None

The type of fuzzy sets that are generated by this partitioner

upper_margin = None

Specific upper exceeding margins for the known UoD. The default value is the self.margin parameter

upper_set()[source]

Return the fuzzy set on upper bound of the universe of discourse.

Returns:Fuzzy Set
variable = None

In a multivariate context, the variable that contains this partitioner

pyFTS.partitioners.Class module

Class Partitioner with Singleton Fuzzy Sets

class pyFTS.partitioners.Class.ClassPartitioner(**kwargs)[source]

Bases: pyFTS.partitioners.partitioner.Partitioner

Class Partitioner: Given a dictionary with class/values pairs, create singleton fuzzy sets for each class

build(data: list)[source]

Perform the partitioning of the Universe of Discourse

Parameters:data – training data
Returns:
pyFTS.partitioners.CMeans module
class pyFTS.partitioners.CMeans.CMeansPartitioner(**kwargs)[source]

Bases: pyFTS.partitioners.partitioner.Partitioner

build(data)[source]

Perform the partitioning of the Universe of Discourse

Parameters:data – training data
Returns:
pyFTS.partitioners.CMeans.c_means(k, dados, tam)[source]
pyFTS.partitioners.CMeans.distance(x, y)[source]
pyFTS.partitioners.Entropy module

C. H. Cheng, R. J. Chang, and C. A. Yeh, “Entropy-based and trapezoidal fuzzification-based fuzzy time series approach for forecasting IT project cost,” Technol. Forecast. Social Change, vol. 73, no. 5, pp. 524–542, Jun. 2006.

class pyFTS.partitioners.Entropy.EntropyPartitioner(**kwargs)[source]

Bases: pyFTS.partitioners.partitioner.Partitioner

Huarng Entropy Partitioner

build(data)[source]

Perform the partitioning of the Universe of Discourse

Parameters:data – training data
Returns:
pyFTS.partitioners.Entropy.PMF(data, threshold)[source]
pyFTS.partitioners.Entropy.bestSplit(data, npart)[source]
pyFTS.partitioners.Entropy.entropy(data, threshold)[source]
pyFTS.partitioners.Entropy.informationGain(data, thres1, thres2)[source]
pyFTS.partitioners.Entropy.splitAbove(data, threshold)[source]
pyFTS.partitioners.Entropy.splitBelow(data, threshold)[source]
pyFTS.partitioners.FCM module

S. T. Li, Y. C. Cheng, and S. Y. Lin, “A FCM-based deterministic forecasting model for fuzzy time series,” Comput. Math. Appl., vol. 56, no. 12, pp. 3052–3063, Dec. 2008. DOI: 10.1016/j.camwa.2008.07.033.

class pyFTS.partitioners.FCM.FCMPartitioner(**kwargs)[source]

Bases: pyFTS.partitioners.partitioner.Partitioner

build(data)[source]

Perform the partitioning of the Universe of Discourse

Parameters:data – training data
Returns:
pyFTS.partitioners.FCM.fuzzy_cmeans(k, data, size, m, deltadist=0.001)[source]
pyFTS.partitioners.FCM.fuzzy_distance(x, y)[source]
pyFTS.partitioners.FCM.membership(val, vals)[source]
pyFTS.partitioners.Grid module

Even Length Grid Partitioner

class pyFTS.partitioners.Grid.GridPartitioner(**kwargs)[source]

Bases: pyFTS.partitioners.partitioner.Partitioner

Even Length Grid Partitioner

build(data)[source]

Perform the partitioning of the Universe of Discourse

Parameters:data – training data
Returns:
class pyFTS.partitioners.Grid.PreFixedGridPartitioner(**kwargs)[source]

Bases: pyFTS.partitioners.Grid.GridPartitioner

Prefixed UoD with Even Length Grid Partitioner

pyFTS.partitioners.Huarng module
pyFTS.partitioners.Singleton module

Even Length Grid Partitioner

class pyFTS.partitioners.Singleton.SingletonPartitioner(**kwargs)[source]

Bases: pyFTS.partitioners.partitioner.Partitioner

Singleton Partitioner: Create singleton fuzzy sets for each distinct value in UoD

build(data: list)[source]

Perform the partitioning of the Universe of Discourse

Parameters:data – training data
Returns:
pyFTS.partitioners.Simple module

Simple Partitioner for manually informed fuzzy sets

class pyFTS.partitioners.Simple.SimplePartitioner(**kwargs)[source]

Bases: pyFTS.partitioners.partitioner.Partitioner

Simple Partitioner for manually informed fuzzy sets

append(name, mf, parameters, **kwargs)[source]

Append a new partition (fuzzy set) to the partitioner

Parameters:
  • name – Fuzzy set name
  • mf – One of the pyFTS.common.Membership functions
  • parameters – A list with the parameters for the membership function
  • kwargs – Optional arguments for the fuzzy set
append_complex(fs)[source]
pyFTS.partitioners.SubClust module

Chiu, Stephen L. “Fuzzy model identification based on cluster estimation.” Journal of Intelligent & fuzzy systems 2.3 (1994): 267-278.

class pyFTS.partitioners.SubClust.SubClustPartitioner(**kwargs)[source]

Bases: pyFTS.partitioners.partitioner.Partitioner

Subtractive Clustering Partitioner

build(data)[source]

Perform the partitioning of the Universe of Discourse

Parameters:data – training data
Returns:
pyFTS.partitioners.SubClust.imax(vec)[source]
pyFTS.partitioners.SubClust.subclust(data, ra, rb, eps_sup, eps_inf)[source]
pyFTS.partitioners.Util module
pyFTS.partitioners.parallel_util module
pyFTS.probabilistic package
Module contents

Probability Distribution objects

Submodules
pyFTS.probabilistic.ProbabilityDistribution module
pyFTS.probabilistic.kde module
Submodules
pyFTS.conf module
Module contents

pyFTS - A Python library for Fuzzy Time Series models

How to reference pyFTS?

https://zenodo.org/badge/DOI/10.5281/zenodo.597359.svg

Silva, P. C. L. et al. pyFTS: Fuzzy Time Series for Python. Belo Horizonte. 2018. DOI: 10.5281/zenodo.597359. Url: <https://doi.org/10.5281/zenodo.597359>