示例#1
0
def test_labeller_invalid_percentage():
    labeller = Labeller(size=6,
                        func=np.max,
                        func_params={},
                        percentiles=[101],
                        n_steps_future=2)
    with pytest.raises(ValueError):
        labeller.fit_transform_resample(X, signal)
示例#2
0
def test_labeller_shape():
    size = 4
    labeller = Labeller(size=size,
                        func=np.std,
                        func_params={},
                        percentiles=None,
                        n_steps_future=1)
    signal_transformed = labeller.fit_transform(signal)
    assert signal_transformed.shape == (20 - size + 1, )
示例#3
0
def test_labeller_with_percentage():
    size = 6
    n_steps_future = 1
    labeller = Labeller(size=size,
                        func=np.max,
                        func_params={},
                        percentiles=[100],
                        n_steps_future=n_steps_future)
    labeller.fit(X)
    assert np.max(X) == labeller.thresholds_[0]
示例#4
0
def test_labeller_resampled():
    size = 6
    labeller = Labeller(size=size,
                        func=np.max,
                        func_params={},
                        percentiles=None,
                        n_steps_future=1)
    x, y = labeller.fit_transform_resample(X, X)
    assert_almost_equal(
        y, np.array([5, 6, 7, 8, 9, 9, 9, 9, 9, 9, 5, 6, 7, 8, 9]))
    assert len(x) == len(y)

    # Test behaviour when n_steps_future = size - 1
    labeller.set_params(n_steps_future=size - 1)
    x, y = labeller.fit_transform_resample(X, X)
    assert_almost_equal(
        y, np.array([5, 6, 7, 8, 9, 9, 9, 9, 9, 9, 5, 6, 7, 8, 9]))
    assert len(x) == len(y)

    # Test behaviour when n_steps_future > size - 1
    labeller.set_params(n_steps_future=size)
    x, y = labeller.fit_transform_resample(X, X)
    assert_almost_equal(y, np.array([6, 7, 8, 9, 9, 9, 9, 9, 9, 5, 6, 7, 8,
                                     9]))
    assert len(x) == len(y)
示例#5
0
def test_labeller_transformed():
    size = 6
    n_steps_future = 1
    labeller = Labeller(size=size,
                        func=np.max,
                        func_params={},
                        percentiles=None,
                        n_steps_future=n_steps_future)
    x, y = labeller.fit_transform_resample(X, X)
    assert_almost_equal(x, X[(size - 2):-n_steps_future])
    assert len(x) == len(y)
#
# Let us say that we simply wish to predict the future of a time series from itself. This is very common in the study of financial markets for example. ``giotto-tda`` provides convenience classes for target preparation from a time series. This notebook only shows a very simple example: many more options are described in ``Labeller``'s documentation.
#
# 我们希望预测一个时间序列的未来。例如,这在金融市场研究中非常普遍。 giotto-tda提供了方便的类,用于根据时间序列进行目标准备。该笔记本仅显示一个非常简单的示例:Labeller的文档中描述了更多选项。
#
# If we wished to create a target ``y`` from ``X`` such that ``y[i]`` is equal to ``X[i + 1]``, while also modifying ``X`` and ``y`` so that they still have the same length, we could proceed as follows:
#
# 如果我们希望从“ X”创建目标“ y”,以使“ y [i]”等于“ X [i + 1]”,同时还要修改“ X”和``y''以便它们仍然具有相同的长度,我们可以按照以下步骤进行操作:

# In[23]:

from gtda.time_series import Labeller

X = np.arange(10)

Lab = Labeller(size=1, func=np.max)
Xl, yl = Lab.fit_transform_resample(X, X)
Xl, yl

# 注意,在这种情况下,我们将X的两个副本提供给fit_transform_resample!
# 这就是使用端到端管道为将来的拓扑预测做准备的样子。同样,鼓励您在混合中包括自己的非拓扑功能!

# In[24]:

SW = SlidingWindow(size=5)
TE = TakensEmbedding(time_delay=1, dimension=2)
VR = VietorisRipsPersistence()
Ampl = Amplitude()
RFR = RandomForestRegressor()

# Full pipeline including the regressor
示例#7
0
def test_labeller_params(size):
    labeller = Labeller(size=size)
    with pytest.raises(ValueError):
        labeller.fit(signal)