lab-12-5-rnn_stock_prediction.py
GzuPark opened this issue · comments
If anyone sees below when this file run,
from numpy._distributor_init import NUMPY_MKL # requires numpy+mkl
ImportError: cannot import name 'NUMPY_MKL'
Check out ImportError: cannot import name NUMPY_MKL
and solution to download here
Thanks. Do you know which numpy calls in the file cause this issue? Perhaps, we can replace it.
This problem occurred on the line from sklearn.preprocessing import MinMaxScaler
.
If we can edit scaler = MinMaxScaler(feature_range=(0, 1))
and xy = scaler.fit_transform(xy)
, we will solve the problem another way.
def MinMaxScaler(data):
num_row = np.shape(data)[0]
num_col = np.shape(data)[1]
array = np.zeros((num_row, num_col))
for i in range(num_col):
input = data[:,i]
array[:,i] = (input - np.min(input)) / (np.max(input) - np.min(input))
return array
If we use above function, we can do it!! Also, we don't need to use sklearn.preprocessing
package.
(lab-12-5 and lab-12-6)
It can be done in two lines though.
def MinMaxScaler(data):
numerator = data - np.min(data, 0)
denominator = np.max(data, 0) - np.min(data, 0)
return numerator/ (denominator + 1e-8) # noise should be added to prevent zero division
I can do that. The vectorized version is 8 times faster than the loop
In [9]: %timeit -n 1000 MinMaxScaler1(A)
1000 loops, best of 3: 81.8 µs per loop
In [10]: %timeit -n 1000 MinMaxScaler2(A)
1000 loops, best of 3: 11.3 µs per loop