cryptocurrency-price-prediction icon indicating copy to clipboard operation
cryptocurrency-price-prediction copied to clipboard

prepare_data throws errors

Open DocMinus opened this issue 4 years ago • 4 comments

When callling the prepare_data function, I get a ton of errors, due to line two X_train = extract_window_data(train_data, window_len, zero_base) i.e. I can't even replicate the results (no matter if the logic is erroneous or not judging by comments on the blog and the issue list).


TypeError Traceback (most recent call last) C:\Python\Miniconda3\envs\mlenv\lib\site-packages\pandas\core\ops_init_.py in na_op(x, y) 967 try: --> 968 result = expressions.evaluate(op, str_rep, x, y, **eval_kwargs) 969 except TypeError:

C:\Python\Miniconda3\envs\mlenv\lib\site-packages\pandas\core\computation\expressions.py in evaluate(op, op_str, a, b, use_numexpr, **eval_kwargs) 220 if use_numexpr: --> 221 return _evaluate(op, op_str, a, b, **eval_kwargs) 222 return _evaluate_standard(op, op_str, a, b)

C:\Python\Miniconda3\envs\mlenv\lib\site-packages\pandas\core\computation\expressions.py in _evaluate_standard(op, op_str, a, b, **eval_kwargs) 69 with np.errstate(all="ignore"): ---> 70 return op(a, b) 71

TypeError: unsupported operand type(s) for /: 'str' and 'str'

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last) in 1 train, test, X_train, X_test, y_train, y_test = prepare_data( ----> 2 hist, target_col, window_len=window_len, zero_base=zero_base, test_size=test_size)

in prepare_data(df, target_col, window_len, zero_base, test_size) 4 train_data, test_data = train_test_split(df, test_size=test_size) 5 # this row throws error ----> 6 X_train = extract_window_data(train_data, window_len, zero_base) 7 X_test = extract_window_data(test_data, window_len, zero_base) 8 y_train = train_data[target_col][window_len:].values

in extract_window_data(df, window_len, zero_base) 4 tmp = df[idx: (idx + window_len)].copy() 5 if zero_base: ----> 6 tmp = normalise_zero_base(tmp) 7 window_data.append(tmp.values) 8 return np.array(window_data)

in normalise_zero_base(df) 1 def normalise_zero_base(df): ----> 2 return df / df.iloc[0] - 1 3 4 def normalise_min_max(df): 5 return (df - df.min()) / (data.max() - df.min())

C:\Python\Miniconda3\envs\mlenv\lib\site-packages\pandas\core\ops_init_.py in f(self, other, axis, level, fill_value) 1497 pass_op = op if axis in [0, "columns", None] else na_op 1498 return _combine_series_frame( -> 1499 self, other, pass_op, fill_value=fill_value, axis=axis, level=level 1500 ) 1501 else:

C:\Python\Miniconda3\envs\mlenv\lib\site-packages\pandas\core\ops_init_.py in _combine_series_frame(self, other, func, fill_value, axis, level) 1398 1399 # default axis is columns -> 1400 return self._combine_match_columns(other, func, level=level) 1401 1402

C:\Python\Miniconda3\envs\mlenv\lib\site-packages\pandas\core\frame.py in _combine_match_columns(self, other, func, level) 5397 left, right = self.align(other, join="outer", axis=1, level=level, copy=False) 5398 assert left.columns.equals(right.index) -> 5399 return ops.dispatch_to_series(left, right, func, axis="columns") 5400 5401 def _combine_const(self, other, func):

C:\Python\Miniconda3\envs\mlenv\lib\site-packages\pandas\core\ops_init_.py in dispatch_to_series(left, right, func, str_rep, axis) 594 raise NotImplementedError(right) 595 --> 596 new_data = expressions.evaluate(column_op, str_rep, left, right) 597 598 result = left._constructor(new_data, index=left.index, copy=False)

C:\Python\Miniconda3\envs\mlenv\lib\site-packages\pandas\core\computation\expressions.py in evaluate(op, op_str, a, b, use_numexpr, **eval_kwargs) 219 use_numexpr = use_numexpr and _bool_arith_check(op_str, a, b) 220 if use_numexpr: --> 221 return _evaluate(op, op_str, a, b, **eval_kwargs) 222 return _evaluate_standard(op, op_str, a, b) 223

C:\Python\Miniconda3\envs\mlenv\lib\site-packages\pandas\core\computation\expressions.py in _evaluate_standard(op, op_str, a, b, **eval_kwargs) 68 _store_test_result(False) 69 with np.errstate(all="ignore"): ---> 70 return op(a, b) 71 72

C:\Python\Miniconda3\envs\mlenv\lib\site-packages\pandas\core\ops_init_.py in column_op(a, b) 582 583 def column_op(a, b): --> 584 return {i: func(a.iloc[:, i], b.iloc[i]) for i in range(len(a.columns))} 585 586 elif isinstance(right, ABCSeries):

C:\Python\Miniconda3\envs\mlenv\lib\site-packages\pandas\core\ops_init_.py in (.0) 582 583 def column_op(a, b): --> 584 return {i: func(a.iloc[:, i], b.iloc[i]) for i in range(len(a.columns))} 585 586 elif isinstance(right, ABCSeries):

C:\Python\Miniconda3\envs\mlenv\lib\site-packages\pandas\core\ops_init_.py in wrapper(left, right) 1046 1047 with np.errstate(all="ignore"): -> 1048 result = na_op(lvalues, rvalues) 1049 return construct_result( 1050 left, result, index=left.index, name=res_name, dtype=None

C:\Python\Miniconda3\envs\mlenv\lib\site-packages\pandas\core\ops_init_.py in na_op(x, y) 968 result = expressions.evaluate(op, str_rep, x, y, **eval_kwargs) 969 except TypeError: --> 970 result = masked_arith_op(x, y, op) 971 972 return missing.dispatch_fill_zeros(op, x, y, result)

C:\Python\Miniconda3\envs\mlenv\lib\site-packages\pandas\core\ops_init_.py in masked_arith_op(x, y, op) 462 if mask.any(): 463 with np.errstate(all="ignore"): --> 464 result[mask] = op(xrav[mask], y) 465 466 result, changed = maybe_upcast_putmask(result, ~mask, np.nan)

TypeError: unsupported operand type(s) for /: 'str' and 'str'

DocMinus avatar Feb 07 '21 21:02 DocMinus

Yes It's throwing error

hirenvadher954 avatar Mar 27 '21 06:03 hirenvadher954

I am experiencing the same problem... how can it be fixed?

gekigek99 avatar Mar 30 '21 23:03 gekigek99

I personally haven't bothered with this code anymore since the method isn't that good. And since the author doesn't seem to care, it's not worth the effort. Probably better to go through e.g. Pytorch stock market prediction tutorial and use it with crypto instead.

DocMinus avatar Apr 06 '21 11:04 DocMinus

@DocMinus nice suggestion... Do you have some good tutorials, links to share?

gekigek99 avatar Apr 06 '21 11:04 gekigek99