'ValueError: setting an array element with a sequence while using MLPCLassifier on classifier.fit

I have this dataset (shape is (36,2)).

x is a numerical pattern, y is a binary class (0,1)

x y
[0.2, 0.3, 0.5 ..... 0.5] 0
[0.1, 0.4, 0.5 ..... 0.9] 1

and so on

Each x (array) has 18000 float values and I broke it down into several sections (in this case 18). Each section contains 1000 values with 50 overlapping values using this function:

def split_overlap(array,size,overlap):
result = []
while True:
    if len(array) <= size:
        result.append(array)
        return np.array(result)
    else:
        result.append(array[:size])
        array = array[size-overlap:]

and this is the code I used to process the x as the feature:

x = np.array([i for i in data.iloc[:,0]])  # pattern
x = [[float(i) for i in X.replace("]", "").replace("[", "").split(", ")] for X in x]
x = np.array([i[:17000] for i in x])
x = np.array([split_overlap(i, 1000, 50) for i in x])
x = np.array([i[:17] for i in x])

On the last line, I took the first 17 sections to make the x uniform because the last one has only 850 values (while the rest has 1000)

When I printed the shape, it came out as

x shape:  (36, 17)
y shape:  (36,)

And when I ran this:

x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.2, random_state=123)
classifier = MLPClassifier(hidden_layer_sizes=(400,400,150),
                           max_iter = 150, activation = 'relu',
                           solver = 'sgd', verbose = type_spec_from_value,
                           random_state = 762, learning_rate = 'invscaling',
                           early_stopping=False, warm_start=True
                           )
classifier.fit(x_train, y_train)

I got this error:

TypeError: only size-1 arrays can be converted to Python scalars
ValueError: setting an array element with a sequence.

Does anyone know what could have gone wrong in my code? Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source