Skip to content

MinMaxScaler not working in this example  #1

@mfethe1

Description

@mfethe1

Everything runs normally up until the MinMaxScaler is called in the for loop.

high_prices = df.loc[:,'High'].as_matrix()
low_prices = df.loc[:,'Low'].as_matrix()
mid_prices = (high_prices+low_prices)/2.0

print(mid_prices)
[20.25 19.865 20.34 ... 27.97 27.62 27.3425]
main:1: FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.
main:2: FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.

smoothing_window_size = 2500
for di in range(0,10000,smoothing_window_size):
scaler.fit(train_data[di:di+smoothing_window_size,:])
train_data[di:di+smoothing_window_size,:] = scaler.transform(train_data[di:di+smoothing_window_size,:])

You normalize the last bit of remaining data

scaler.fit(train_data[di+smoothing_window_size:,:])
train_data[di+smoothing_window_size:,:] = scaler.transform(train_data[di+smoothing_window_size:,:])
Traceback (most recent call last):

File "", line 3, in
scaler.fit(train_data[di:di+smoothing_window_size,:])

File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\preprocessing\data.py", line 325, in fit
return self.partial_fit(X, y)

File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\preprocessing\data.py", line 353, in partial_fit
force_all_finite="allow-nan")

File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 550, in check_array
context))

ValueError: Found array with 0 sample(s) (shape=(0, 1)) while a minimum of 1 is required by MinMaxScaler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions