pyFTS - Fuzzy Time Series for Python¶
What is pyFTS Library?¶
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) .
![]() |
![]() |
![]() |
![]() |
pyFTS Quick Start¶
How to install pyFTS?¶
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:
- Data preprocessing: Data transformation functions contained at pyFTS.common.Transformations, like differentiation, Box-Cox, scaling and normalization.
- 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:
- the number of intervals
- which fuzzy membership function (on pyFTS.common.Membership)
- partition scheme (GridPartitioner, EntropyPartitioner, FCMPartitioner, HuarngPartitioner)
Check out the jupyter notebook on notebooks/Partitioners.ipynb for sample codes.
- 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.
- 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.
- Defuzzyfication: This step transform the fuzzy forecast into a real number.
- 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.
A short tutorial on Fuzzy Time Series¶
Part I: Introduction to the Fuzzy Logic, Fuzzy Time Series and the pyFTS library.
Part II: High order, weighted and multivariate methods and a case study of solar energy forecasting..
pyFTS¶
pyFTS package¶
Subpackages¶
pyFTS.benchmarks package¶
pyFTS module for benchmarking the FTS models
pyFTS.common package¶
Activation functions for Time Series Classification
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:
-
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
-
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.
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.
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
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
-
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)]
-
key
¶ key function
-
-
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
-
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_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
-
pyFTS.common.transformations package¶
-
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
¶
-
-
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
¶
-
-
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
-
-
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)
-
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
¶
-
-
class
pyFTS.common.transformations.smoothing.
AveragePooling
(**kwargs)[source]¶ Bases:
pyFTS.common.transformations.transformation.Transformation
-
class
pyFTS.common.transformations.smoothing.
ExponentialSmoothing
(**kwargs)[source]¶ Bases:
pyFTS.common.transformations.transformation.Transformation
-
class
pyFTS.common.transformations.smoothing.
MaxPooling
(**kwargs)[source]¶ Bases:
pyFTS.common.transformations.transformation.Transformation
-
class
pyFTS.common.transformations.smoothing.
MovingAverage
(**kwargs)[source]¶ Bases:
pyFTS.common.transformations.transformation.Transformation
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:
-
-
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.data package¶
Module for pyFTS standard datasets facilities
-
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
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
-
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
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/.
Bitcoin to USD quotations
Daily averaged index, by business day, from 2010 to 2018.
DJI - Dow Jones
Daily averaged index, by business day, from 1985 to 2017.
Source: https://finance.yahoo.com/quote/%5EGSPC/history?p=%5EGSPC
Yearly University of Alabama enrollments from 1971 to 1992.
Ethereum to USD quotations
Daily averaged index, by business day, from 2016 to 2018.
FOREX market EUR-GBP pair.
Daily averaged quotations, by business day, from 2016 to 2018.
FOREX market EUR-USD pair.
Daily averaged quotations, by business day, from 2016 to 2018.
FOREX market GBP-USD pair.
Daily averaged quotations, by business day, from 2016 to 2018.
INMET - Instituto Nacional Meteorologia / Brasil
Belo Horizonte station, from 2000-01-01 to 31/12/2012
Source: http://www.inmet.gov.br
Hourly Malaysia eletric load and tempeature
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
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/
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
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
- 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
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:
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, 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:
- 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
Monthly sunspot numbers from 1749 to May 2016
Source: https://www.esrl.noaa.gov/psd/gcos_wgsp/Timeseries/SUNSPOT/
pyFTS.distributed package¶
pyFTS.hyperparam package¶
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.models package¶
Fuzzy Time Series methods
Meta FTS that aggregates other FTS methods
FTS methods with incremental/online learning
Multivariate Fuzzy Time Series methods
-
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
-
-
class
pyFTS.models.multivariate.flrg.
FLRG
(**kwargs)[source]¶ Bases:
pyFTS.common.flrg.FLRG
Multivariate Fuzzy Logical Rule Group
-
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
-
-
class
pyFTS.models.multivariate.partitioner.
MultivariatePartitioner
(**kwargs)[source]¶ Bases:
pyFTS.partitioners.partitioner.Partitioner
Base class for partitioners which use the MultivariateFuzzySet
-
build
(data)[source]¶ Perform the partitioning of the Universe of Discourse
Parameters: data – training data Returns:
-
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
-
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
-
-
class
pyFTS.models.multivariate.grid.
GridCluster
(**kwargs)[source]¶ Bases:
pyFTS.models.multivariate.partitioner.MultivariatePartitioner
A cartesian product of all fuzzy sets of all variables
-
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
-
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
-
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
-
width
= None¶ Pertubation function that affects the width of the membership function
-
width_params
= None¶ Parameters for width pertubation function
-
-
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
-
class
pyFTS.models.nonstationary.flrg.
NonStationaryFLRG
(LHS, **kwargs)[source]¶ Bases:
pyFTS.common.flrg.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
-
-
class
pyFTS.models.nonstationary.partitioners.
PolynomialNonStationaryPartitioner
(data, part, **kwargs)[source]¶ Bases:
pyFTS.partitioners.partitioner.Partitioner
Non Stationary Universe of Discourse Partitioner
-
class
pyFTS.models.nonstationary.partitioners.
SimpleNonStationaryPartitioner
(data, part, **kwargs)[source]¶ Bases:
pyFTS.partitioners.partitioner.Partitioner
Non Stationary Universe of Discourse Partitioner
Pertubation functions for Non Stationary Fuzzy Sets
Fuzzy time series with nonstationary fuzzy sets, for heteroskedastic data
-
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
-
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
-
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
-
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
-
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:
-
mask
= None¶ A string with datetime formating mask
-
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.partitioners package¶
Module for pyFTS Universe of Discourse partitioners.
-
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:
-
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.
-
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
-
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
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
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.
Even Length Grid Partitioner
-
class
pyFTS.partitioners.Grid.
GridPartitioner
(**kwargs)[source]¶ Bases:
pyFTS.partitioners.partitioner.Partitioner
Even Length Grid Partitioner
-
class
pyFTS.partitioners.Grid.
PreFixedGridPartitioner
(**kwargs)[source]¶ Bases:
pyFTS.partitioners.Grid.GridPartitioner
Prefixed UoD with Even Length Grid Partitioner
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
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
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
Submodules¶
pyFTS.conf module¶
Module contents¶
pyFTS - A Python library for Fuzzy Time Series models
How to reference pyFTS?¶
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>