Exemple #1
0
 def test_magnitude_shape_plot(self):
     fd = fetch_weather()["data"]
     fd_temperatures = FDataGrid(data_matrix=fd.data_matrix[:, :, 0],
                                 sample_points=fd.sample_points,
                                 dataset_label=fd.dataset_label,
                                 axes_labels=fd.axes_labels[0:2])
     msplot = MagnitudeShapePlot(fd_temperatures,
                                 depth_method=modified_band_depth)
     np.testing.assert_allclose(
         msplot.points,
         np.array([[0.2591055, 3.15861149], [1.3811996, 0.91806814],
                   [0.94648379, 2.75695426], [2.11346208, 7.24045853],
                   [0.82557436, 0.82727771], [1.23249759, 0.22004329],
                   [-2.66259589, 0.96925352], [0.15827963, 1.00235557],
                   [-0.43751765, 0.66236714], [0.70695162, 0.66482897],
                   [0.73095525, 0.33165117], [3.48445368, 12.59745018],
                   [3.15539264, 13.85234879], [3.52759979, 10.49810783],
                   [3.95518808, 15.28317686], [-0.48486514, 0.5035343],
                   [0.64492781, 6.83385521], [-0.83185751, 0.81125541],
                   [-3.47125418, 1.10683451], [0.22241054, 1.76783493],
                   [-0.54402406, 0.95229119], [-1.71310618, 0.61875513],
                   [-0.44161441, 0.77815135], [0.13851408, 1.02560672],
                   [7.59909246, 40.82126568], [7.57868277, 36.03923856],
                   [7.12930634, 45.96866318], [0.05746528, 1.75817588],
                   [1.53092075, 8.85227], [-1.48696387, 0.22472872],
                   [-2.853082, 4.50814844], [-2.42297615, 1.46926902],
                   [-5.8873129, 5.35742609], [-5.44346193, 5.18338576],
                   [-16.38949483, 0.94027717]]))
     np.testing.assert_array_almost_equal(
         msplot.outliers,
         np.array([
             0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0,
             0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1
         ]))
 def test_magnitude_shape_plot(self):
     fd = fetch_weather()["data"]
     fd_temperatures = fd.coordinates[0]
     msplot = MagnitudeShapePlot(
         fd_temperatures, multivariate_depth=SimplicialDepth())
     np.testing.assert_allclose(msplot.points,
                                np.array([[0.2112587, 3.0322570],
                                          [1.2823448, 0.8272850],
                                          [0.8646544, 1.8619370],
                                          [1.9862512, 5.5287354],
                                          [0.7534918, 0.7203502],
                                          [1.1325291, 0.2808455],
                                          [-2.650529, 0.9702889],
                                          [0.1434387, 0.9159834],
                                          [-0.402844, 0.6413531],
                                          [0.6354411, 0.6934311],
                                          [0.5727553, 0.4628254],
                                          [3.0524899, 8.8008899],
                                          [2.7355803, 10.338497],
                                          [3.1179374, 7.0686220],
                                          [3.4944047, 11.479432],
                                          [-0.402532, 0.5253690],
                                          [0.5782190, 5.5400704],
                                          [-0.839887, 0.7350041],
                                          [-3.456470, 1.1156415],
                                          [0.2260207, 1.5071672],
                                          [-0.561562, 0.8836978],
                                          [-1.690263, 0.6392155],
                                          [-0.385394, 0.7401909],
                                          [0.1467050, 0.9090058],
                                          [7.1811993, 39.003407],
                                          [6.8943132, 30.968126],
                                          [6.6227164, 41.448548],
                                          [0.0726709, 1.5960063],
                                          [1.4450617, 8.7183435],
                                          [-1.459836, 0.2719813],
                                          [-2.824349, 4.5729382],
                                          [-2.390462, 1.5464775],
                                          [-5.869571, 5.3517279],
                                          [-5.426019, 5.1817219],
                                          [-16.34459, 0.9397117]]), rtol=1e-5)
     np.testing.assert_array_almost_equal(msplot.outliers,
                                          np.array(
                                              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                               0, 1, 1, 1, 1, 0, 0, 0, 0, 0,
                                               0, 0, 0, 0, 1, 1, 1, 0, 1, 0,
                                               0, 0, 0, 0, 1]))
Exemple #3
0
label_names = dataset["target_names"]
nlabels = len(label_names)
label_colors = colormap(np.arange(nlabels) / (nlabels - 1))

fd_temperatures.plot(group=dataset["target"],
                     group_colors=label_colors,
                     group_names=label_names)

##############################################################################
# The MS-Plot is generated. In order to show the results, the
# :func:`~skfda.exploratory.visualization.MagnitudeShapePlot.plot` method
# is used. Note that the colors have been specified before to distinguish
# between outliers or not. In particular the tones of the default colormap,
# (which is 'seismic' and can be customized), are assigned.

msplot = MagnitudeShapePlot(fdatagrid=fd_temperatures,
                            depth_method=modified_band_depth)

color = 0.3
outliercol = 0.7

msplot.color = color
msplot.outliercol = outliercol
msplot.plot()

##############################################################################
# To show the utility of the plot, the curves are plotted according to the
# distinction made by the MS-Plot (outliers or not) with the same colors.

fd_temperatures.plot(group=msplot.outliers.astype(int),
                     group_colors=msplot.colormap([color, outliercol]),
                     group_names=['nonoutliers', 'outliers'])
                    shape_outlier_peak, shape_outlier_sin,
                    shape_outlier_slope, magnitude_shape_outlier)

##############################################################################
# The data is plotted to show the curves we are working with.
labels = [0] * n_samples + [1] * 6

fd.plot(sample_labels=labels,
        label_colors=['lightgrey', 'black'])

##############################################################################
# The MS-Plot is generated. In order to show the results, the
# :func:`~skfda.exploratory.visualization.MagnitudeShapePlot.plot`
# method is used.

msplot = MagnitudeShapePlot(fdatagrid=fd)

msplot.plot()

##############################################################################
# To show the utility of the plot, the curves are plotted showing each outlier
# in a different color

labels = [0] * n_samples + [1, 2, 3, 4, 5, 6]
colors = ['lightgrey', 'orange', 'blue', 'black',
          'green', 'brown', 'lightblue']

fd.plot(sample_labels=labels,
        label_colors=colors)

##############################################################################
label_names = target.categories
nlabels = len(label_names)
label_colors = colormap(np.arange(nlabels) / (nlabels - 1))

fd_temperatures.plot(group=target.codes,
                     group_colors=label_colors,
                     group_names=label_names)

##############################################################################
# The MS-Plot is generated. In order to show the results, the
# :func:`~skfda.exploratory.visualization.MagnitudeShapePlot.plot` method
# is used. Note that the colors have been specified before to distinguish
# between outliers or not. In particular the tones of the default colormap,
# (which is 'seismic' and can be customized), are assigned.

msplot = MagnitudeShapePlot(fdatagrid=fd_temperatures,
                            multivariate_depth=SimplicialDepth())

color = 0.3
outliercol = 0.7

msplot.color = color
msplot.outliercol = outliercol
msplot.plot()

##############################################################################
# To show the utility of the plot, the curves are plotted according to the
# distinction made by the MS-Plot (outliers or not) with the same colors.

fd_temperatures.plot(group=msplot.outliers.astype(int),
                     group_colors=msplot.colormap([color, outliercol]),
                     group_names=['nonoutliers', 'outliers'])