简体   繁体   中英

Getting back a tuple when trying to normalize training data

I have a training and testing set. I need to normalize them but i can't seem to iterate over them i get this error TypeError: list indices must be integers or slices, not tuple . I will give a small part of the set just so you can see how it is structured. I've tried with enumerate and range but i get the same error.

training_data = [
    [3.6216, 8.6661, -2.8073, -0.44699, 0],
    [4.5459, 8.1674, -2.4586, -1.4621, 0],
    [3.866, -2.6383, 1.9242, 0.10645, 0],
    [3.4566, 9.5228, -4.0112, -3.5944, 0],
    [0.32924, -4.4552, 4.5718, -0.9888, 0],
    [4.3684, 9.6718, -3.9606, -3.1625, 0],
    [3.5912, 3.0129, 0.72888, 0.56421, 0],
    [2.0922, -6.81, 8.4636, -0.60216, 0],
]

Code:

def minMaxNrom(training_data, testing_data):
    for i in enumerate(training_data):
        for j in enumerate(training_data):
            new_data = training_data[i][j] - min(j) / max(j) - min(j)    

    for i in enumerate(testing_data):
        for j in enumerate(testing_data[i]):
            new_testing_data = testing_data[i][j] - min(j) / max(j) - min(j)


    return (new_data, new_testing_data)

for i in enumertae(list) generate a tuple , ie (index:value) , what you are looking for is index, so use for i,v in enumerate(list)

def minMaxNrom(training_data, testing_data):
    for i,v1 in enumerate(training_data):
        for j,v2 in enumerate(v1):
            new_data = training_data[i][j] - (min(v1) / max(v1)) - min(v1)    

    for i,v1 in enumerate(testing_data):
        for j,v2 in enumerate(v1):
            new_testing_data = testing_data[i][j] - (min(v1) / max(v1)) - min(v1)

    return (new_data, new_testing_data)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM