Skip to content

Deprecated

This is the reference to the functions contained in deprecated. For now, they are all accesible directly through machine-learning-datasets and you don't need to use the deprecated namespace.

Common Utility Functions

encode_classification_error_vector(y_true, y_pred)

Encodes the classification error vector.

Parameters:

Name Type Description Default
y_true Union[Series, ndarray]

The true classification labels.

required
y_pred Union[Series, ndarray]

The predicted classification labels.

required

Returns:

Type Description
Tuple[ndarray, Dict]

Tuple[np.ndarray, Dict]: A tuple containing the encoded error vector and the error labels.

Example

y_true = np.array([1, 0, 1, 0]) y_pred = np.array([0, 0, 1, 1]) encode_classification_error_vector(y_true, y_pred) (array([3, 4, 1, 2]), {0: 'FP', 1: 'FN', 2: 'TP', 3: 'TN'})

Source code in machine_learning_datasets/deprecated.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def encode_classification_error_vector(
        y_true:Union[pd.Series, np.ndarray],
        y_pred:Union[pd.Series, np.ndarray]
    ) -> Tuple[np.ndarray, Dict]:
    """Encodes the classification error vector.

    Args:
        y_true (Union[pd.Series, np.ndarray]): The true classification labels.
        y_pred (Union[pd.Series, np.ndarray]): The predicted classification labels.

    Returns:
        Tuple[np.ndarray, Dict]: A tuple containing the encoded error vector and the error labels.

    Example:
        >>> y_true = np.array([1, 0, 1, 0])
        >>> y_pred = np.array([0, 0, 1, 1])
        >>> encode_classification_error_vector(y_true, y_pred)
        (array([3, 4, 1, 2]), {0: 'FP', 1: 'FN', 2: 'TP', 3: 'TN'})
    """
    warnings.warn('This method is deprecated.', DeprecationWarning, stacklevel=2)
    error_vector = (y_true * 2) - y_pred
    error_vector = np.where(error_vector==0, 4, error_vector + 1)
    error_vector = np.where(error_vector==3, 0, error_vector - 1)
    error_vector = np.where(error_vector==3, error_vector, error_vector + 1)
    error_labels = {0:'FP', 1:'FN', 2:'TP', 3:'TN'}
    return error_vector, error_labels

plot_3dim_decomposition(Z, y_labels, y_names, save_name=None)

Plots a 3-dimensional decomposition of the given data.

Parameters:

Name Type Description Default
Z Union[DataFrame, ndarray]

The input data.

required
y_labels ArrayLike

The labels for the data points.

required
y_names Dict

A dictionary mapping label indices to their names.

required
save_name Optional[str]

The name to save the plot as. Defaults to None.

None

Returns:

Type Description
None

None

Source code in machine_learning_datasets/deprecated.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def plot_3dim_decomposition(
        Z:Union[pd.DataFrame, np.ndarray],
        y_labels:ArrayLike,
        y_names:Dict,
        save_name:Optional[str] = None
    ) -> None:
    """Plots a 3-dimensional decomposition of the given data.

    Parameters:
        Z (Union[pd.DataFrame, np.ndarray]): The input data.
        y_labels (ArrayLike): The labels for the data points.
        y_names (Dict): A dictionary mapping label indices to their names.
        save_name (Optional[str], optional): The name to save the plot as. Defaults to None.

    Returns:
        None
    """
    warnings.warn('This method is deprecated.', DeprecationWarning, stacklevel=2)
    if len(y_names) > 2:
        cmap = 'plasma_r'
    else:
        cmap = 'viridis'
    fig, axs = plt.subplots(1, 3, figsize = (16,4))
    fig.subplots_adjust(hspace=0, wspace=0.3)
    scatter = axs[0].scatter(Z[:,0], Z[:,1],\
                             c=y_labels, alpha=0.5, cmap=cmap)
    legend = axs[0].legend(*scatter.legend_elements(), loc='best')
    for n in y_names.keys():
        legend.get_texts()[n].set_text(y_names[n])
    axs[0].set_xlabel('x', fontsize = 12)
    axs[0].set_ylabel('y', fontsize = 12)
    scatter = axs[1].scatter(Z[:,1], Z[:,2],\
                   c=y_labels, alpha=0.5, cmap=cmap)
    legend = axs[1].legend(*scatter.legend_elements(), loc='best')
    for n in y_names.keys():
        legend.get_texts()[n].set_text(y_names[n])
    axs[1].set_xlabel('y', fontsize = 12)
    axs[1].set_ylabel('z', fontsize = 12)
    axs[2].scatter(Z[:,0], Z[:,2],\
                   c=y_labels, alpha=0.5, cmap=cmap)
    legend = axs[2].legend(*scatter.legend_elements(), loc='best')
    for n in y_names.keys():
        legend.get_texts()[n].set_text(y_names[n])
    axs[2].set_xlabel('x', fontsize = 12)
    axs[2].set_ylabel('z', fontsize = 12)
    if save_name is not None:
        plt.savefig(save_name+'_3dim.png', dpi=300, bbox_inches="tight")
    plt.show()