WillKoehrsen / Data-Analysis

Data Science Using Python

Home Page:https://medium.com/@williamkoehrsen/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RuntimeWarning: invalid value encountered in sign

cnubathula opened this issue · comments

Hi ,

Iam getting below errors while executing evaluate_prediction. iam new for python coding, could you please help to fix these errors.

Error Details:

itc.evaluate_prediction(nshares=1000)
Initial log joint probability = -45.8545
Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes
99 1875.53 0.0011384 310.13 0.8018 0.8018 119
Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes
199 1882.67 0.0103854 113.906 0.7416 0.7416 249
Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes
299 1886.69 0.000409105 76.9431 1 1 376
Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes
399 1887.11 0.000591786 99.5287 0.7763 0.7763 494
Iter log prob ||dx|| ||grad|| alpha alpha0 # evals Notes
499 1887.19 1.44516e-007 75.1071 1 1 618
Optimization terminated normally:
Convergence detected: relative gradient magnitude is below tolerance
C:\Users\687488\stocker\stocker.py:524: RuntimeWarning: invalid value encountered in sign
test['correct'] = (np.sign(test['pred_diff']) == np.sign(test['real_diff'])) * 1
C:\Users\687488\stocker\stocker.py:615: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
test_pred_increase['pred_profit'] = prediction_profit
You played the stock market in ITI from 2017-11-07 00:00:00 to 2018-11-07 00:00:00 with 1000 shares.

When the model predicted an increase, the price increased 42.01% of the time.
When the model predicted a decrease, the price decreased 62.82% of the time.

The total profit using the Prophet model = $-37100.00.
The Buy and Hold strategy profit = $-63100.00.

Thanks for playing the stock market!

C:\Users\687488\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib_init_.py:886: MatplotlibDeprecationWarning:
examples.directory is deprecated; in the future, examples will be found relative to the 'datapath' directory.
"found relative to the 'datapath' directory.".format(key))
C:\Users\687488\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib_init_.py:855: MatplotlibDeprecationWarning:
examples.directory is deprecated; in the future, examples will be found relative to the 'datapath' directory.
"found relative to the 'datapath' directory.".format(key))
C:\Users\687488\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib_init_.py:846: MatplotlibDeprecationWarning:
The text.latex.unicode rcparam was deprecated in Matplotlib 2.2 and will be removed in 3.1.
"2.2", name=key, obj_type="rcparam", addendum=addendum)

I have this problem too but I solved it.
You can view my pull request.

Thanks for update. as per pull request i have replace code but no luck iam getting below error.

Python 3.7.1 (default, Oct 28 2018, 08:39:03) [MSC v.1912 64 bit (AMD64)] :: Anaconda custom (64-bit) on win32
Type "help", "copyright", "credits" or "license" for more information.

from stocker import *
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\687488\stocker\stocker.py", line 525
test['correct'] = (np.sign(test['pred_diff'][1:]) == np.sign(test['real_diff'][1:])) * 1
^
TabError: inconsistent use of tabs and spaces in indentation

inconsistent use of tabs and spaces in indentation

That is a little wired. Are you using the latest pull request?
It works fine on my computer and I can't see anything wrong with tabs or spaces.
Maybe you can try add [1:] in the right place manually?

I am pretty sure that

RuntimeWarning: invalid value encountered in sign

This warning is caused by test['correct'] = (np.sign(test['pred_diff']) == np.sign(test['real_diff'])) * 1 ^ And by adding [1:] begind test[''] will solve this.