Skip to content
Snippets Groups Projects
Commit 5cc4a555 authored by Baptiste Bauvin's avatar Baptiste Bauvin
Browse files

name changed

parent 4d630a8a
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 5051 deletions
import numpy as np
from multiview_platform.mono_multi_view_classifiers.multiview_classifiers.additions.diversity_utils import \
GlobalDiversityFusionClassifier
classifier_class_name = "EntropyFusion"
class EntropyFusion(GlobalDiversityFusionClassifier):
def diversity_measure(self, classifiers_decisions, combination, y):
_, nb_view, nb_examples = classifiers_decisions.shape
scores = np.zeros((nb_view, nb_examples), dtype=int)
for view_index, classifier_index in enumerate(combination):
scores[view_index] = np.logical_not(
np.logical_xor(
classifiers_decisions[classifier_index, view_index],
y)
)
entropy_scores = np.sum(scores, axis=0)
nb_view_matrix = np.zeros((nb_examples),
dtype=int) + nb_view - entropy_scores
entropy_score = np.mean(
np.minimum(entropy_scores, nb_view_matrix).astype(float) / (
nb_view - int(nb_view / 2)))
return entropy_score
import numpy as np
from ..multiview_classifiers.additions.late_fusion_utils import \
LateFusionClassifier
from ..utils.dataset import get_examples_views_indices
classifier_class_name = "MajorityVoting"
class VotingIndecision(Exception):
pass
class MajorityVoting(LateFusionClassifier):
def __init__(self, random_state, classifiers_names=None,
classifier_configs=None, weights=None, nb_cores=1, rs=None):
self.need_probas = False
LateFusionClassifier.__init__(self, random_state=random_state,
classifiers_names=classifiers_names,
classifier_configs=classifier_configs,
nb_cores=nb_cores,
weights=weights,
rs=rs)
def predict(self, X, example_indices=None, view_indices=None):
examples_indices, view_indices = get_examples_views_indices(X,
example_indices,
view_indices)
self._check_views(view_indices)
n_examples = len(examples_indices)
votes = np.zeros((n_examples, X.get_nb_class(example_indices)),
dtype=float)
monoview_decisions = np.zeros((len(examples_indices), X.nb_view),
dtype=int)
for index, view_index in enumerate(view_indices):
monoview_decisions[:, index] = self.monoview_estimators[
index].predict(
X.get_v(view_index, examples_indices))
for example_index in range(n_examples):
for view_index, feature_classification in enumerate(
monoview_decisions[example_index, :]):
votes[example_index, feature_classification] += self.weights[
view_index]
nb_maximum = len(
np.where(votes[example_index] == max(votes[example_index]))[0])
if nb_maximum == X.nb_view:
raise VotingIndecision(
"Majority voting can't decide, each classifier has voted for a different class")
predicted_labels = np.argmax(votes, axis=1)
# Can be upgraded by restarting a new classification process if
# there are multiple maximums ?:
# while nbMaximum>1:
# relearn with only the classes that have a maximum number of vote
return predicted_labels
from sklearn.svm import SVC
from .additions.jumbo_fusion_utils import BaseJumboFusion
from ..monoview.monoview_utils import CustomUniform, CustomRandint
classifier_class_name = "SVMJumboFusion"
class SVMJumboFusion(BaseJumboFusion):
def __init__(self, random_state=None, classifiers_names=None,
classifier_configs=None, nb_cores=1, weights=None,
nb_monoview_per_view=1, C=1.0, kernel="rbf", degree=2,
rs=None):
self.need_probas = False
BaseJumboFusion.__init__(self, random_state,
classifiers_names=classifiers_names,
classifier_configs=classifier_configs,
nb_cores=nb_cores, weights=weights,
nb_monoview_per_view=nb_monoview_per_view,
rs=rs)
self.param_names += ["C", "kernel", "degree"]
self.distribs += [CustomUniform(), ["rbf", "poly", "linear"],
CustomRandint(2, 5)]
self.aggregation_estimator = SVC(C=C, kernel=kernel, degree=degree)
self.C = C
self.kernel = kernel
self.degree = degree
def set_params(self, C=1.0, kernel="rbf", degree=1, **params):
super(SVMJumboFusion, self).set_params(**params)
self.C = C
self.degree = degree
self.kernel = kernel
self.aggregation_estimator.set_params(C=C, kernel=kernel, degree=degree)
return self
import numpy as np
from multiview_platform.mono_multi_view_classifiers import monoview_classifiers
from .additions.fusion_utils import BaseFusionClassifier
from ..multiview.multiview_utils import get_available_monoview_classifiers, \
BaseMultiviewClassifier, ConfigGenerator
from ..utils.dataset import get_examples_views_indices
from ..utils.multiclass import get_mc_estim, MultiClassWrapper
# from ..utils.dataset import get_v
classifier_class_name = "WeightedLinearEarlyFusion"
class WeightedLinearEarlyFusion(BaseMultiviewClassifier, BaseFusionClassifier):
"""
WeightedLinearEarlyFusion
Parameters
----------
random_state
view_weights
monoview_classifier_name
monoview_classifier_config
Attributes
----------
"""
def __init__(self, random_state=None, view_weights=None,
monoview_classifier_name="decision_tree",
monoview_classifier_config={}):
BaseMultiviewClassifier.__init__(self, random_state=random_state)
self.view_weights = view_weights
self.monoview_classifier_name = monoview_classifier_name
self.short_name = "early_fusion"
if monoview_classifier_name in monoview_classifier_config:
self.monoview_classifier_config = monoview_classifier_config[
monoview_classifier_name]
self.monoview_classifier_config = monoview_classifier_config
# monoview_classifier_module = getattr(monoview_classifiers,
# self.monoview_classifier_name)
# monoview_classifier_class = getattr(monoview_classifier_module,
# monoview_classifier_module.classifier_class_name)
self.monoview_classifier = self.init_monoview_estimator(monoview_classifier_name, monoview_classifier_config)
self.param_names = ["monoview_classifier_name",
"monoview_classifier_config"]
self.distribs = [get_available_monoview_classifiers(),
ConfigGenerator(get_available_monoview_classifiers())]
self.classed_params = []
self.weird_strings = {}
def set_params(self, monoview_classifier_name="decision_tree",
monoview_classifier_config={}, **params):
self.monoview_classifier_name = monoview_classifier_name
self.monoview_classifier = self.init_monoview_estimator(
monoview_classifier_name,
monoview_classifier_config)
self.monoview_classifier_config = self.monoview_classifier.get_params()
self.short_name = "early_fusion"
return self
def get_params(self, deep=True):
return {"random_state": self.random_state,
"view_weights": self.view_weights,
"monoview_classifier_name": self.monoview_classifier_name,
"monoview_classifier_config": self.monoview_classifier_config}
def fit(self, X, y, train_indices=None, view_indices=None):
train_indices, X = self.transform_data_to_monoview(X, train_indices,
view_indices)
self.used_views = view_indices
if np.unique(y[train_indices]).shape[0] > 2 and \
not (isinstance(self.monoview_classifier, MultiClassWrapper)):
self.monoview_classifier = get_mc_estim(self.monoview_classifier,
self.random_state,
multiview=False,
y=y[train_indices])
self.monoview_classifier.fit(X, y[train_indices])
self.monoview_classifier_config = self.monoview_classifier.get_params()
return self
def predict(self, X, example_indices=None, view_indices=None):
_, X = self.transform_data_to_monoview(X, example_indices, view_indices)
self._check_views(self.view_indices)
predicted_labels = self.monoview_classifier.predict(X)
return predicted_labels
def transform_data_to_monoview(self, dataset, example_indices,
view_indices):
"""Here, we extract the data from the HDF5 dataset file and store all
the concatenated views in one variable"""
example_indices, self.view_indices = get_examples_views_indices(dataset,
example_indices,
view_indices)
if self.view_weights is None:
self.view_weights = np.ones(len(self.view_indices), dtype=float)
else:
self.view_weights = np.array(self.view_weights)
self.view_weights /= float(np.sum(self.view_weights))
X = self.hdf5_to_monoview(dataset, example_indices)
return example_indices, X
def hdf5_to_monoview(self, dataset, examples):
"""Here, we concatenate the views for the asked examples """
monoview_data = np.concatenate(
[dataset.get_v(view_idx, examples)
for view_weight, (index, view_idx)
in zip(self.view_weights, enumerate(self.view_indices))]
, axis=1)
return monoview_data
# def set_monoview_classifier_config(self, monoview_classifier_name, monoview_classifier_config):
# if monoview_classifier_name in monoview_classifier_config:
# self.monoview_classifier.set_params(**monoview_classifier_config[monoview_classifier_name])
# else:
# self.monoview_classifier.set_params(**monoview_classifier_config)
import numpy as np
from ..multiview_classifiers.additions.late_fusion_utils import \
LateFusionClassifier
from ..utils.dataset import get_examples_views_indices
classifier_class_name = "WeightedLinearLateFusion"
class WeightedLinearLateFusion(LateFusionClassifier):
def __init__(self, random_state, classifiers_names=None,
classifier_configs=None, weights=None, nb_cores=1, rs=None):
self.need_probas = True
LateFusionClassifier.__init__(self, random_state=random_state,
classifiers_names=classifiers_names,
classifier_configs=classifier_configs,
nb_cores=nb_cores, weights=weights, rs=rs)
def predict(self, X, example_indices=None, view_indices=None):
example_indices, view_indices = get_examples_views_indices(X,
example_indices,
view_indices)
self._check_views(view_indices)
view_scores = []
for index, viewIndex in enumerate(view_indices):
view_scores.append(
np.array(self.monoview_estimators[index].predict_proba(
X.get_v(viewIndex, example_indices))) * self.weights[index])
view_scores = np.array(view_scores)
predicted_labels = np.argmax(np.sum(view_scores, axis=0), axis=1)
return predicted_labels
import os
import plotly
import pandas as pd
def get_duration(results):
df = pd.DataFrame(columns=["hps", "fit", "pred"], )
for classifier_result in results:
df.at[classifier_result.get_classifier_name(),
"hps"] = classifier_result.hps_duration
df.at[classifier_result.get_classifier_name(),
"fit"] = classifier_result.fit_duration
df.at[classifier_result.get_classifier_name(),
"pred"] = classifier_result.pred_duration
return df
def plot_durations(durations, directory, database_name, durations_stds=None): # pragma: no cover
file_name = os.path.join(directory, database_name + "-durations")
durations.to_csv(file_name+"_dataframe.csv")
fig = plotly.graph_objs.Figure()
if durations_stds is None:
durations_stds = pd.DataFrame(0, durations.index, durations.columns)
else:
durations_stds.to_csv(file_name+"_stds_dataframe.csv")
fig.add_trace(plotly.graph_objs.Bar(name='Hyper-parameter Optimization',
x=durations.index,
y=durations['hps'],
error_y=dict(type='data',
array=durations_stds["hps"]),
marker_color="grey"))
fig.add_trace(plotly.graph_objs.Bar(name='Fit (on train set)',
x=durations.index,
y=durations['fit'],
error_y=dict(type='data',
array=durations_stds["fit"]),
marker_color="black"))
fig.add_trace(plotly.graph_objs.Bar(name='Prediction (on test set)',
x=durations.index,
y=durations['pred'],
error_y=dict(type='data',
array=durations_stds["pred"]),
marker_color="lightgrey"))
fig.update_layout(title="Durations for each classfier",
yaxis_title="Duration (s)")
fig.update_layout(paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)')
plotly.offline.plot(fig, filename=file_name + ".html", auto_open=False)
\ No newline at end of file
# Import built-in modules
import logging
import os
import matplotlib as mpl
# Import third party modules
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import plotly
from matplotlib.patches import Patch
# Import own Modules
def get_example_errors(groud_truth, results):
r"""Used to get for each classifier and each example whether the classifier
has misclassified the example or not.
Parameters
----------
ground_truth : numpy array of 0, 1 and -100 (if multiclass)
The array with the real labels of the examples
results : list of MonoviewResult and MultiviewResults objects
A list containing all the resluts for all the mono- & multi-view
experimentations.
Returns
-------
example_errors : dict of np.array
For each classifier, has an entry with a `np.array` over the examples,
with a 1 if the examples was
well-classified, a 0 if not and if it's multiclass classification, a
-100 if the examples was not seen during
the one versus one classification.
"""
example_errors = {}
for classifier_result in results:
error_on_examples = np.equal(classifier_result.full_labels_pred,
groud_truth).astype(int)
unseen_examples = np.where(groud_truth == -100)[0]
error_on_examples[unseen_examples] = -100
example_errors[
classifier_result.get_classifier_name()] = error_on_examples
return example_errors
def publish_example_errors(example_errors, directory, databaseName,
labels_names, example_ids, labels): # pragma: no cover
logging.debug("Start:\t Label analysis figure generation")
base_file_name = os.path.join(directory, databaseName + "-" )
nb_classifiers, nb_examples, classifiers_names, \
data_2d, error_on_examples = gen_error_data(example_errors)
np.savetxt(base_file_name + "2D_plot_data.csv", data_2d, delimiter=",")
np.savetxt(base_file_name + "bar_plot_data.csv", error_on_examples,
delimiter=",")
plot_2d(data_2d, classifiers_names, nb_classifiers, base_file_name,
example_ids=example_ids, labels=labels)
plot_errors_bar(error_on_examples, nb_examples,
base_file_name, example_ids=example_ids)
logging.debug("Done:\t Label analysis figures generation")
def publish_all_example_errors(iter_results, directory,
stats_iter,
example_ids, labels): # pragma: no cover
logging.debug(
"Start:\t Global label analysis figure generation")
nb_examples, nb_classifiers, data, \
error_on_examples, classifier_names = gen_error_data_glob(iter_results,
stats_iter)
np.savetxt(os.path.join(directory, "clf_errors.csv"), data, delimiter=",")
np.savetxt(os.path.join(directory, "example_errors.csv"), error_on_examples,
delimiter=",")
plot_2d(data, classifier_names, nb_classifiers,
os.path.join(directory, ""), stats_iter=stats_iter,
example_ids=example_ids, labels=labels)
plot_errors_bar(error_on_examples, nb_examples, os.path.join(directory, ""),
example_ids=example_ids)
logging.debug(
"Done:\t Global label analysis figures generation")
def gen_error_data(example_errors):
r"""Used to format the error data in order to plot it efficiently. The
data is saves in a `.csv` file.
Parameters
----------
example_errors : dict of dicts of np.arrays
A dictionary conatining all the useful data. Organized as :
`example_errors[<classifier_name>]["error_on_examples"]` is a np.array
of ints with a
- 1 if the classifier `<classifier_name>` classifier well the example,
- 0 if it fail to classify the example,
- -100 if it did not classify the example (multiclass one versus one).
Returns
-------
nbClassifiers : int
Number of different classifiers.
nbExamples : int
NUmber of examples.
nbCopies : int
The number of times the data is copied (classifier wise) in order for
the figure to be more readable.
classifiers_names : list of strs
The names fo the classifiers.
data : np.array of shape `(nbClassifiers, nbExamples)`
A matrix with zeros where the classifier failed to classifiy the
example, ones where it classified it well
and -100 if the example was not classified.
error_on_examples : np.array of shape `(nbExamples,)`
An array counting how many classifiers failed to classifiy each
examples.
"""
nb_classifiers = len(example_errors)
nb_examples = len(list(example_errors.values())[0])
classifiers_names = list(example_errors.keys())
data_2d = np.zeros((nb_examples, nb_classifiers))
for classifierIndex, (classifier_name, error_on_examples) in enumerate(
example_errors.items()):
data_2d[:, classifierIndex] = error_on_examples
error_on_examples = np.sum(data_2d, axis=1) / nb_classifiers
return nb_classifiers, nb_examples, classifiers_names, data_2d, error_on_examples
def gen_error_data_glob(iter_results, stats_iter):
nb_examples = next(iter(iter_results.values())).shape[0]
nb_classifiers = len(iter_results)
data = np.zeros((nb_examples, nb_classifiers), dtype=int)
classifier_names = []
for clf_index, (classifier_name, error_data) in enumerate(
iter_results.items()):
data[:, clf_index] = error_data
classifier_names.append(classifier_name)
error_on_examples = np.sum(data, axis=1) / (
nb_classifiers * stats_iter)
return nb_examples, nb_classifiers, data, error_on_examples, \
classifier_names
def plot_2d(data, classifiers_names, nb_classifiers, file_name, labels=None,
stats_iter=1, use_plotly=True, example_ids=None): # pragma: no cover
r"""Used to generate a 2D plot of the errors.
Parameters
----------
data : np.array of shape `(nbClassifiers, nbExamples)`
A matrix with zeros where the classifier failed to classifiy the example, ones where it classified it well
and -100 if the example was not classified.
classifiers_names : list of str
The names of the classifiers.
nb_classifiers : int
The number of classifiers.
file_name : str
The name of the file in which the figure will be saved ("error_analysis_2D.png" will be added at the end)
minSize : int, optinal, default: 10
The minimum width and height of the figure.
width_denominator : float, optional, default: 1.0
To obtain the image width, the number of classifiers will be divided by this number.
height_denominator : float, optional, default: 1.0
To obtain the image width, the number of examples will be divided by this number.
stats_iter : int, optional, default: 1
The number of statistical iterations realized.
Returns
-------
"""
fig, ax = plt.subplots(nrows=1, ncols=1, )
label_index_list = np.concatenate([np.where(labels == i)[0] for i in
np.unique(
labels)])
cmap, norm = iter_cmap(stats_iter)
cax = plt.imshow(data[np.flip(label_index_list), :], cmap=cmap, norm=norm,
aspect='auto')
plt.title('Errors depending on the classifier')
ticks = np.arange(0, nb_classifiers, 1)
tick_labels = classifiers_names
plt.xticks(ticks, tick_labels, rotation="vertical")
plt.yticks([], [])
plt.ylabel("Examples")
cbar = fig.colorbar(cax, ticks=[-100 * stats_iter / 2, 0, stats_iter])
cbar.ax.set_yticklabels(['Unseen', 'Always Wrong', 'Always Right'])
fig.savefig(file_name + "error_analysis_2D.png", bbox_inches="tight",
transparent=True)
plt.close()
### The following part is used to generate an interactive graph.
if use_plotly:
# [np.where(labels==i)[0] for i in np.unique(labels)]
hover_text = [[example_ids[example_index] + " failed " + str(
stats_iter - data[
example_index, classifier_index]) + " time(s), labelled " + str(
labels[example_index])
for classifier_index in range(data.shape[1])]
for example_index in range(data.shape[0])]
fig = plotly.graph_objs.Figure()
fig.add_trace(plotly.graph_objs.Heatmap(
x=list(classifiers_names),
y=[example_ids[label_ind] for label_ind in label_index_list],
z=data[label_index_list, :],
text=[hover_text[label_ind] for label_ind in label_index_list],
hoverinfo=["y", "x", "text"],
colorscale="Greys",
colorbar=dict(tickvals=[0, stats_iter],
ticktext=["Always Wrong", "Always Right"]),
reversescale=True), )
fig.update_yaxes(title_text="Examples", showticklabels=True)
fig.update_layout(paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)')
fig.update_xaxes(showticklabels=True, )
plotly.offline.plot(fig, filename=file_name + "error_analysis_2D.html",
auto_open=False)
del fig
def plot_errors_bar(error_on_examples, nb_examples, file_name,
use_plotly=True, example_ids=None): # pragma: no cover
r"""Used to generate a barplot of the muber of classifiers that failed to classify each examples
Parameters
----------
error_on_examples : np.array of shape `(nbExamples,)`
An array counting how many classifiers failed to classifiy each examples.
classifiers_names : list of str
The names of the classifiers.
nb_classifiers : int
The number of classifiers.
nb_examples : int
The number of examples.
file_name : str
The name of the file in which the figure will be saved ("error_analysis_2D.png" will be added at the end)
Returns
-------
"""
fig, ax = plt.subplots()
x = np.arange(nb_examples)
plt.bar(x, 1-error_on_examples)
plt.title("Number of classifiers that failed to classify each example")
fig.savefig(file_name + "error_analysis_bar.png", transparent=True)
plt.close()
if use_plotly:
fig = plotly.graph_objs.Figure([plotly.graph_objs.Bar(x=example_ids, y=1-error_on_examples)])
fig.update_layout(paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)')
plotly.offline.plot(fig, filename=file_name + "error_analysis_bar.html",
auto_open=False)
def iter_cmap(statsIter): # pragma: no cover
r"""Used to generate a colormap that will have a tick for each iteration : the whiter the better.
Parameters
----------
statsIter : int
The number of statistical iterations.
Returns
-------
cmap : matplotlib.colors.ListedColorMap object
The colormap.
norm : matplotlib.colors.BoundaryNorm object
The bounds for the colormap.
"""
cmapList = ["red", "0.0"] + [str(float((i + 1)) / statsIter) for i in
range(statsIter)]
cmap = mpl.colors.ListedColormap(cmapList)
bounds = [-100 * statsIter - 0.5, -0.5]
for i in range(statsIter):
bounds.append(i + 0.5)
bounds.append(statsIter + 0.5)
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
return cmap, norm
import os
import plotly
import pandas as pd
import numpy as np
from ..monoview.monoview_utils import MonoviewResult
def get_feature_importances(result, feature_names=None):
r"""Extracts the feature importance from the monoview results and stores
them in a dictionnary :
feature_importance[view_name] is a pandas.DataFrame of size n_feature*n_clf
containing a score of importance for each feature.
Parameters
----------
result : list of results
Returns
-------
feature_importances : dict of pd.DataFrame
The dictionary containing all the feature importance for each view as
pandas DataFrames
"""
feature_importances = {}
for classifier_result in result:
if isinstance(classifier_result, MonoviewResult):
if classifier_result.view_name not in feature_importances:
feature_importances[classifier_result.view_name] = pd.DataFrame(
index=feature_names)
if hasattr(classifier_result.clf, 'feature_importances_'):
feature_importances[classifier_result.view_name][
classifier_result.classifier_name] = classifier_result.clf.feature_importances_
else:
feature_importances[classifier_result.view_name][
classifier_result.classifier_name] = np.zeros(
classifier_result.n_features)
return feature_importances
def publish_feature_importances(feature_importances, directory, database_name,
feature_stds=None): # pragma: no cover
for view_name, feature_importance in feature_importances.items():
if not os.path.exists(os.path.join(directory, "feature_importances")):
os.mkdir(os.path.join(directory, "feature_importances"))
file_name = os.path.join(directory, "feature_importances",
database_name + "-" + view_name
+ "-feature_importances")
if feature_stds is not None:
feature_std = feature_stds[view_name]
feature_std.to_csv(file_name + "_dataframe_stds.csv")
else:
feature_std = pd.DataFrame(data=np.zeros(feature_importance.shape),
index=feature_importance.index,
columns=feature_importance.columns)
plot_feature_importances(file_name, feature_importance, feature_std)
def plot_feature_importances(file_name, feature_importance, feature_std): # pragma: no cover
feature_importance.to_csv(file_name + "_dataframe.csv")
hover_text = [["-Feature :" + str(feature_name) +
"<br>-Classifier : " + classifier_name +
"<br>-Importance : " + str(
feature_importance.loc[feature_name][classifier_name]) +
"<br>-STD : " + str(
feature_std.loc[feature_name][classifier_name])
for classifier_name in list(feature_importance.columns)]
for feature_name in list(feature_importance.index)]
fig = plotly.graph_objs.Figure(data=plotly.graph_objs.Heatmap(
x=list(feature_importance.columns),
y=list(feature_importance.index),
z=feature_importance.values,
text=hover_text,
hoverinfo=["text"],
colorscale="Greys",
reversescale=False))
fig.update_layout(
xaxis={"showgrid": False, "showticklabels": False, "ticks": ''},
yaxis={"showgrid": False, "showticklabels": False, "ticks": ''})
fig.update_layout(paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)')
plotly.offline.plot(fig, filename=file_name + ".html", auto_open=False)
del fig
#
# import numpy as np
# import pandas as pd
# import matplotlib.pyplot as plt
# import os
# from matplotlib.patches import Patch
#
#
# def plot_results_noise(directory, noise_results, metric_to_plot, name,
# width=0.1):
# avail_colors = ["tab:blue", "tab:orange", "tab:brown", "tab:gray",
# "tab:olive", "tab:red", ]
# colors = {}
# lengend_patches = []
# noise_levels = np.array([noise_level for noise_level, _ in noise_results])
# df = pd.DataFrame(
# columns=['noise_level', 'classifier_name', 'mean_score', 'score_std'], )
# if len(noise_results) > 1:
# width = np.min(np.diff(noise_levels))
# for noise_level, noise_result in noise_results:
# classifiers_names, meaned_metrics, metric_stds = [], [], []
# for noise_result in noise_result:
# classifier_name = noise_result[0].split("-")[0]
# if noise_result[1] is metric_to_plot:
# classifiers_names.append(classifier_name)
# meaned_metrics.append(noise_result[2])
# metric_stds.append(noise_result[3])
# if classifier_name not in colors:
# try:
# colors[classifier_name] = avail_colors.pop(0)
# except IndexError:
# colors[classifier_name] = "k"
# classifiers_names, meaned_metrics, metric_stds = np.array(
# classifiers_names), np.array(meaned_metrics), np.array(metric_stds)
# sorted_indices = np.argsort(-meaned_metrics)
# for index in sorted_indices:
# row = pd.DataFrame(
# {'noise_level': noise_level,
# 'classifier_name': classifiers_names[index],
# 'mean_score': meaned_metrics[index],
# 'score_std': metric_stds[index]}, index=[0])
# df = pd.concat([df, row])
# plt.bar(noise_level, meaned_metrics[index], yerr=metric_stds[index],
# width=0.5 * width, label=classifiers_names[index],
# color=colors[classifiers_names[index]])
# for classifier_name, color in colors.items():
# lengend_patches.append(Patch(facecolor=color, label=classifier_name))
# plt.legend(handles=lengend_patches, loc='lower center',
# bbox_to_anchor=(0.5, 1.05), ncol=2)
# plt.ylabel(metric_to_plot)
# plt.title(name)
# plt.xticks(noise_levels)
# plt.xlabel("Noise level")
# plt.savefig(os.path.join(directory, name + "_noise_analysis.png"))
# plt.close()
# df.to_csv(os.path.join(directory, name + "_noise_analysis.csv"))
from . import dataset, execution, hyper_parameter_search, transformations
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment