Skip to content
Snippets Groups Projects
Commit 02bd4734 authored by bbauvin's avatar bbauvin
Browse files

Working with any case of iteration and multiclass

parent 71d49e95
Branches
Tags
No related merge requests found
......@@ -18,7 +18,7 @@ from . import MultiviewClassifiers
from .Multiview.ExecMultiview import ExecMultiview, ExecMultiview_multicore
from .Monoview.ExecClassifMonoView import ExecMonoview, ExecMonoview_multicore
from .utils import GetMultiviewDb as DB
from .ResultAnalysis import resultAnalysis, analyzeLabels, analyzeIterResults, analyzeIterLabels, genNamesFromRes, getResults
from .ResultAnalysis import getResults #resultAnalysis, analyzeLabels, analyzeIterResults, analyzeIterLabels, genNamesFromRes,
from .utils import execution, Dataset, Multiclass
from . import Metrics
......
......@@ -52,7 +52,10 @@ def initTrainTest(X, Y, classificationIndices):
trainIndices, testIndices, testIndicesMulticlass = classificationIndices
X_train = extractSubset(X, trainIndices)
X_test = extractSubset(X, testIndices)
if testIndicesMulticlass != []:
X_test_multiclass = extractSubset(X, testIndicesMulticlass)
else:
X_test_multiclass = []
y_train = Y[trainIndices]
y_test = Y[testIndices]
return X_train, y_train, X_test, y_test, X_test_multiclass
......
......@@ -459,7 +459,7 @@ def publishIterBiclassMetricsScores(iterResults, directory, labelsDictionary, cl
def iterCmap(statsIter):
cmapList = ["red", "0.0"]
for i in range(statsIter):
cmapList.append(str((i+1)/statsIter))
cmapList.append(str(float((i+1))/statsIter))
cmap = mpl.colors.ListedColormap(cmapList)
bounds = [-100*statsIter-0.5, -0.5]
for i in range(statsIter):
......@@ -658,14 +658,14 @@ def getResults(results, statsIter, nbMulticlass, benchmarkArgumentDictionaries,
analyzeIterMulticlass(multiclassResults, directory, statsIter, metrics, dataBaseName, nbExamples)
else:
biclassResults = analyzeBiclass(results, benchmarkArgumentDictionaries, statsIter, metrics)
analyzebiclassIter(biclassResults, metrics, statsIter, directory, labelsDictionary, dataBaseName)
analyzebiclassIter(biclassResults, metrics, statsIter, directory, labelsDictionary, dataBaseName, nbExamples)
else:
if nbMulticlass>1:
biclassResults = analyzeBiclass(results, benchmarkArgumentDictionaries, statsIter, metrics)
multiclassResults = analyzeMulticlass(results, statsIter, benchmarkArgumentDictionaries, nbExamples, nbLabels, multiclassLabels,
metrics, classificationIndices, directories)
else:
analyzeBiclass(results)
biclassResults = analyzeBiclass(results, benchmarkArgumentDictionaries, statsIter, metrics)
......
......@@ -52,7 +52,7 @@ def makeMeNoisy(viewData, randomState, percentage=15):
return noisyViewData
def getPlausibleDBhdf5(features, pathF, name, NB_CLASS, LABELS_NAME, nbView=3,
def getPlausibleDBhdf5(features, pathF, name, NB_CLASS=3, LABELS_NAME="", nbView=3,
nbClass=2, datasetLength=347, randomStateInt=42):
"""Used to generate a plausible dataset to test the algorithms"""
randomState = np.random.RandomState(randomStateInt)
......@@ -64,6 +64,33 @@ def getPlausibleDBhdf5(features, pathF, name, NB_CLASS, LABELS_NAME, nbView=3,
if exc.errno != errno.EEXIST:
raise
datasetFile = h5py.File(pathF + "/Plausible.hdf5", "w")
if NB_CLASS == 2:
CLASS_LABELS = np.array([0 for _ in range(datasetLength/2)] + [1 for _ in range(datasetLength-datasetLength/2)])
for viewIndex in range(nbView):
viewData = np.array([np.zeros(nbFeatures) for _ in range(datasetLength/2)] +
[np.ones(nbFeatures)for _ in range(datasetLength-datasetLength/2)])
fakeOneIndices = randomState.randint(0, datasetLength/2, int(datasetLength / 12))
fakeZeroIndices = randomState.randint(datasetLength/2, datasetLength-datasetLength/2, int(datasetLength / 12))
viewData[fakeOneIndices] = np.ones((len(fakeOneIndices), nbFeatures))
viewData[fakeZeroIndices] = np.zeros((len(fakeZeroIndices), nbFeatures))
viewData = makeMeNoisy(viewData, randomState)
viewDset = datasetFile.create_dataset("View" + str(viewIndex), viewData.shape, data=viewData.astype(np.uint8))
viewDset.attrs["name"] = "View" + str(viewIndex)
viewDset.attrs["sparse"] = False
labelsDset = datasetFile.create_dataset("Labels", CLASS_LABELS.shape)
labelsDset[...] = CLASS_LABELS
labelsDset.attrs["name"] = "Labels"
labelsDset.attrs["names"] = ["No".encode(), "Yes".encode()]
metaDataGrp = datasetFile.create_group("Metadata")
metaDataGrp.attrs["nbView"] = nbView
metaDataGrp.attrs["nbClass"] = 2
metaDataGrp.attrs["datasetLength"] = len(CLASS_LABELS)
datasetFile.close()
datasetFile = h5py.File(pathF + "Plausible.hdf5", "r")
LABELS_DICTIONARY = {0: "No", 1: "Yes"}
return datasetFile, LABELS_DICTIONARY
elif NB_CLASS >= 3:
firstBound = int(datasetLength / 3)
rest = datasetLength - 2*int(datasetLength / 3)
scndBound = 2*int(datasetLength / 3)
......
......@@ -6,7 +6,9 @@ def genMulticlassLabels(labels, multiclassMethod, classificationIndices):
if multiclassMethod == "oneVersusOne":
nbLabels = len(set(list(labels)))
if nbLabels == 2:
classificationIndices = [[trainIndices, testIndices, []] for trainIndices, testIndices in classificationIndices]
classificationIndices = [[trainIndices for trainIndices, _ in classificationIndices],
[testIndices for _, testIndices in classificationIndices],
[[] for _ in classificationIndices]]
return [labels], [(0,1)], [classificationIndices]
else:
combinations = itertools.combinations(np.arange(nbLabels), 2)
......
......@@ -264,7 +264,7 @@ def genKFolds(statsIter, nbFolds, statsIterRandomStates):
foldsList.append(sklearn.model_selection.StratifiedKFold(n_splits=nbFolds, random_state=randomState))
return foldsList
else:
return sklearn.model_selection.StratifiedKFold(n_splits=nbFolds, random_state=statsIterRandomStates)
return [sklearn.model_selection.StratifiedKFold(n_splits=nbFolds, random_state=statsIterRandomStates)]
def initViews(DATASET, args):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment