I'm pretty new to Python and I'm trying to build a test harness:
results = []
results2 = numpy.empty(shape=(0, 2))
for name, model in models:
kfold = KFold(n_splits=10, random_state=7, shuffle=True)
cv = cross_val_score(model, X, Y, cv=kfold, scoring='accuracy')
results.append((name, cv))
#results2 = numpy.append(results2, [[name, cv]], axis=0)
results.sort(key=lambda result: result[1].mean(), reverse=True)
results3 = numpy.array(results, dtype='object')
print(results3[:, 0])
print(results3[:, 1])
I'm running multiple models and want BOTH a list (sorted by the means()) and a box plot (also sorted by the means).
What I have now works, but I have to convert results into a numpy array to do the slicing to split out the name's and cv's.
I'm was trying to just put [name, cv] directly into a numpy array, but keep getting an error no matter what I try:
Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
I tried specifying dtype='object' on the numpy.empty, as well as an array of dtypes, but can't seem to get the syntax to work.
If the conversion to a numpy array works at the end, shouldn't it be possible to just insert it directly?