I have this loop:
features = ['ca','tf','se','zz','rd','fbs','th','ex']
for i in range(1, len(features) + 1): # iterate and select next features
Sbest = []
input_f = features[:i]
y = data['target']
X = data[input_f]
model_= KMeans(n_clusters=2, random_state=0, init='k-means++', n_init=10, max_iter=100)
model_.fit(X)
precision,recall,fscore,support=score(y,model_.labels_,average='macro')
Sbest.append(input_f)
Sbest.append(round(fscore,2))
print(Sbest)
that gives me this output:
[['ca'], 0.62]
[['ca', 'tf'], 0.62]
[['ca', 'tf', 'se'], 0.71]
[['ca', 'tf', 'se', 'zz'], 0.71]
[['ca', 'tf', 'se', 'zz', 'rd'], 0.42]
[['ca', 'tf', 'se', 'zz', 'rd', 'fbs'], 0.12]
[['ca', 'tf', 'se', 'zz', 'rd', 'fbs', 'th'], 0.56]
[['ca', 'tf', 'se', 'zz', 'rd', 'fbs', 'th', 'ex'], 0.56]
but what I really want is that output could be a list as I want to sort it later; What I want is something like this:
[
[['ca'], 0.62],
[['ca', 'tf'], 0.62],
[['ca', 'tf', 'se'], 0.71],
[['ca', 'tf', 'se', 'zz'], 0.71],
[['ca', 'tf', 'se', 'zz', 'rd'], 0.42],
[['ca', 'tf', 'se', 'zz', 'rd', 'fbs'], 0.12],
[['ca', 'tf', 'se', 'zz', 'rd', 'fbs', 'th'], 0.56],
[['ca', 'tf', 'se', 'zz', 'rd', 'fbs', 'th', 'ex'], 0.56]
]
How do I convert this to a list?
a = [a]a=[]; a.append(sbest)?