willkoehrsen / data-analysis Goto Github PK
View Code? Open in Web Editor NEWData Science Using Python
Home Page: https://medium.com/@williamkoehrsen/
License: MIT License
Data Science Using Python
Home Page: https://medium.com/@williamkoehrsen/
License: MIT License
ValueError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\pandas\core\internals\managers.py in create_block_manager_from_blocks(blocks, axes)
1650 blocks = [make_block(values=blocks[0],
-> 1651 placement=slice(0, len(axes[0])))]
1652
~\Anaconda3\lib\site-packages\pandas\core\internals\blocks.py in make_block(values, placement, klass, ndim, dtype, fastpath)
3094
-> 3095 return klass(values, ndim=ndim, placement=placement)
3096
~\Anaconda3\lib\site-packages\pandas\core\internals\blocks.py in init(self, values, placement, ndim)
86 'Wrong number of items passed {val}, placement implies '
---> 87 '{mgr}'.format(val=len(self.values), mgr=len(self.mgr_locs)))
88
ValueError: Wrong number of items passed 2, placement implies 14998
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
in
1 # Run the by hand implementation
----> 2 by_hand_coefs = linear_regression(X, y)
3 print('Intercept calculated by hand:', by_hand_coefs[0])
4 print('Slope calculated by hand: ', by_hand_coefs[1])
in linear_regression(X, y)
3 def linear_regression(X, y):
4 # Equation for linear regression coefficients
----> 5 beta = np.matmul(np.matmul(np.linalg.inv(np.matmul(X.T, X)), X.T), y)
6 return beta
~\Anaconda3\lib\site-packages\pandas\core\generic.py in array_wrap(self, result, context)
1907 def array_wrap(self, result, context=None):
1908 d = self._construct_axes_dict(self._AXIS_ORDERS, copy=False)
-> 1909 return self._constructor(result, **d).finalize(self)
1910
1911 # ideally we would define this to avoid the getattr checks, but
~\Anaconda3\lib\site-packages\pandas\core\frame.py in init(self, data, index, columns, dtype, copy)
422 else:
423 mgr = init_ndarray(data, index, columns, dtype=dtype,
--> 424 copy=copy)
425
426 # For data is list-like, or Iterable (will consume into list)
~\Anaconda3\lib\site-packages\pandas\core\internals\construction.py in init_ndarray(values, index, columns, dtype, copy)
165 values = maybe_infer_to_datetimelike(values)
166
--> 167 return create_block_manager_from_blocks([values], [columns, index])
168
169
~\Anaconda3\lib\site-packages\pandas\core\internals\managers.py in create_block_manager_from_blocks(blocks, axes)
1658 blocks = [getattr(b, 'values', b) for b in blocks]
1659 tot_items = sum(b.shape[0] for b in blocks)
-> 1660 construction_error(tot_items, blocks[0].shape[1:], axes, e)
1661
1662
~\Anaconda3\lib\site-packages\pandas\core\internals\managers.py in construction_error(tot_items, block_shape, axes, e)
1689 raise ValueError("Empty data passed with indices specified.")
1690 raise ValueError("Shape of passed values is {0}, indices imply {1}".format(
-> 1691 passed, implied))
1692
1693
ValueError: Shape of passed values is (2, 2), indices imply (2, 14998)
`
When running following cell:
exercise = pd.read_csv('data/exercise.csv')
calories = pd.read_csv('data/calories.csv')
df = pd.merge(exercise, calories, on = 'User_ID')
df = df[df['Calories'] < 300]
df = df.reset_index()
df['Intercept'] = 1
df.head()
KeyError: 'User_ID'
When I inspect data/exercise.csv, it only reads following:
version https://git-lfs.github.com/spec/v1
oid sha256:aaae7b1c1502cab499ef7b68ddc118d13596b47855968a142a6db1424eba13c9
size 230245
I guess the data from csv is missing.
df = pd.read_csv('building_one.csv', header=[0, 1], index_col=False)
produces a
ValueError: index_col must only contain row numbers when specifying a multi-index header.
Hello,
My question is that in the grid search it came out that n_jobs should be put to None and verbose should be 0. Does that mean I change values only in RandomForestRegressor or should I also change them in grid_search_ad?
Thank you for your help in the matter
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)
When trying to retrieve stats in Python 3.7.3, I get the following IndexError:
>>> from retrieval import get_data
>>> df = get_data(fname='stats.html')
Found 3 entries in table.
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/multiprocessing/pool.py", line 121, in worker
result = (True, func(*args, **kwds))
File "/Users/user/Dropbox/Projects/Test/Stats/retrieval.py", line 128, in process_entry
IndexError: list index out of range
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/user/Dropbox/Projects/Test/Stats/retrieval.py", line 227, in get_data
return process_in_parallel(t, processes=processes)
File "/Users/user/Dropbox/Projects/Test/Stats/retrieval.py", line 174, in process_in_parallel
for i, r in enumerate(pool.imap_unordered(process_entry, table_rows_str)):
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/multiprocessing/pool.py", line 748, in next
raise value
IndexError: list index out of range
Line 128 in retrieval is:
tags = [li.text for li in tags[0].find_all('li')]
Any idea what the problem might be?
Hi,
Great tutorial.
The section where pm.sample is called looks like the following.
Context for the model
with pm.Model() as normal_model:
# The prior for the model parameters will be a normal distribution
family = pm.glm.families.Normal()
# Creating the model requires a formula and data (and optionally a family)
pm.GLM.from_formula(formula, data = X_train, family = family)
# Perform Markov Chain Monte Carlo sampling
normal_trace = pm.sample(draws=2000, chains = 2, tune = 500, njobs=-1)
It gives me an errors as given below
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-108-f2e8efe4a0b2> in <module>
9
10 # Perform Markov Chain Monte Carlo sampling
---> 11 normal_trace = pm.sample(draws=2000, chains = 2, tune = 500, njobs=-1)
/usr/local/lib/python3.6/dist-packages/pymc3/sampling.py in sample(draws, step, init, n_init, start, trace, chain_idx, chains, cores, tune, progressbar, model, random_seed, discard_tuned_samples, compute_convergence_checks, **kwargs)
394 start_, step = init_nuts(init=init, chains=chains, n_init=n_init,
395 model=model, random_seed=random_seed,
--> 396 progressbar=progressbar, **kwargs)
397 if start is None:
398 start = start_
/usr/local/lib/python3.6/dist-packages/pymc3/sampling.py in init_nuts(init, chains, n_init, model, random_seed, progressbar, **kwargs)
1513 'Unknown initializer: {}.'.format(init))
1514
-> 1515 step = pm.NUTS(potential=potential, model=model, **kwargs)
1516
1517 return start, step
/usr/local/lib/python3.6/dist-packages/pymc3/step_methods/hmc/nuts.py in __init__(self, vars, max_treedepth, early_max_treedepth, **kwargs)
150 `pm.sample` to the desired number of tuning steps.
151 """
--> 152 super().__init__(vars, **kwargs)
153
154 self.max_treedepth = max_treedepth
/usr/local/lib/python3.6/dist-packages/pymc3/step_methods/hmc/base_hmc.py in __init__(self, vars, scaling, step_scale, is_cov, model, blocked, potential, dtype, Emax, target_accept, gamma, k, t0, adapt_step_size, step_rand, **theano_kwargs)
70 vars = inputvars(vars)
71
---> 72 super().__init__(vars, blocked=blocked, model=model, dtype=dtype, **theano_kwargs)
73
74 self.adapt_step_size = adapt_step_size
/usr/local/lib/python3.6/dist-packages/pymc3/step_methods/arraystep.py in __init__(self, vars, model, blocked, dtype, **theano_kwargs)
226
227 func = model.logp_dlogp_function(
--> 228 vars, dtype=dtype, **theano_kwargs)
229
230 # handle edge case discovered in #2948
/usr/local/lib/python3.6/dist-packages/pymc3/model.py in logp_dlogp_function(self, grad_vars, **kwargs)
721 varnames = [var.name for var in grad_vars]
722 extra_vars = [var for var in self.free_RVs if var.name not in varnames]
--> 723 return ValueGradFunction(self.logpt, grad_vars, extra_vars, **kwargs)
724
725 @property
/usr/local/lib/python3.6/dist-packages/pymc3/model.py in __init__(self, cost, grad_vars, extra_vars, dtype, casting, **kwargs)
460
461 self._theano_function = theano.function(
--> 462 inputs, [self._cost_joined, grad], givens=givens, **kwargs)
463
464 def set_extra_values(self, extra_vars):
TypeError: function() got an unexpected keyword argument 'njobs'
There are som lines in the jupyter-notebook that needs to be refactored. Thx for this. Se below.
The plotly.plotly module is deprecated,
please install the chart-studio package and use the
chart_studio.plotly module instead
I have been trying to reproduce the comparison with the google trends file, buy I keep getting this error and I have not been able to figure out why, is it a problem with the data type of the tesla_chnagepoints data values?
Thanks in advance, great tutorial!!!
File "/Users/ManuelRivera/anaconda3/lib/python3.7/site-packages/matplotlib/axis.py", line 1553, in convert_units
f'units: {x!r}') from e
ConversionError: Failed to convert value(s) to axis units: ['2010-09-27 00:00:00', '2010-12-27 00:00:00', '2011-03-25 00:00:00', '2011-06-23 00:00:00', '2011-09-22 00:00:00', '2011-12-20 00:00:00', '2012-03-21 00:00:00', '2012-06-20 00:00:00', '2012-09-18 00:00:00', '2012-12-18 00:00:00', '2013-03-21 00:00:00', '2013-06-19 00:00:00', '2013-09-17 00:00:00', '2013-12-13 00:00:00', '2014-03-18 00:00:00', '2014-06-16 00:00:00', '2014-09-12 00:00:00', '2014-12-11 00:00:00', '2015-03-13 00:00:00', '2015-06-11 00:00:00', '2015-09-10 00:00:00', '2015-12-08 00:00:00', '2016-03-09 00:00:00', '2016-06-08 00:00:00', '2016-09-06 00:00:00']
@WillKoehrsen
Need assistance with the above error . Happens with all versions of stocker, with the changed ix and so on including the default.
Hi Will, thanks for the excellent tutorial. I cloned your repository and want to run it locally on my computer. However, I find that some data files are lfs files which I cannot load them directly. How can I restore the original files?
When I tried running stocker.py on my local machine, this is the error that I got
ImportError: C extension: No module named 'pandas._libs.tslibs.conversion' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
Wondering how to define on setup extension how to handle specific notebook config to support multiple kernels like Python and R.
Any suggestion?
Hi there,
Pls consider to load data from local CSV.
`
# Initialization requires a ticker symbol
def __init__(self, ticker, exchange='WIKI', csv_repository=""):
# Enforce capitalization
ticker = ticker.upper()
# Symbol is used for labeling plots
self.symbol = ticker
# Use Personal Api Key
#quandl.ApiConfig.api_key = 'xxxxxxxxxxxxxxxxxxxxxxxx'
if exchange in "CSV":
print("Load from CSV file...")
stock = pd.read_csv(self.symbol_to_path(ticker,csv_repository), index_col='Date',
parse_dates=True,
# usecols=['Date', 'Open','High','Low','Adj Close','Volume'],
na_values=['nan'])
#print(stock.head(5))
else:
# Retrieval the financial data from QUANDL
try:
stock = quandl.get('%s/%s' % (exchange, ticker))
except Exception as e:
print('Error Retrieving Data.')
print(e)
return
...
`
Check my modified version here: https://github.com/asfolcini/stocker/blob/master/stocker.py
You might want to change this line
I use Python 3.7.7.
When I run
from retrieval import process_in_parallel, get_table_rows
table_rows = get_table_rows(fname='stats.html')
df = process_in_parallel(table_rows=table_rows, processes=25)
df.head()
It returns these errors.
objc[14401]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[14401]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
objc[14411]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[14411]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
objc[14412]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[14412]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
...
objc[14405]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[14405]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
Do you know anything about how to fix these errors?
Have you looked at creating some IPython line or block magic (%slack
or %%slack
) to support issuing Slack commands from notebook code cells?
I'm think that your Interacting with Slack.ipynb probably contains many of the necessary ingredients already?
Hi all, I configured the system and installed the required libraries. Doing so in a virtual environment. So, I activate the environment to have libraries available and then try to run Jupyter opening the notebook I want to work with using this command:
jupyter notebook D:\Projects\stocker\Stocker_test.ipynb
being stocker the folder in which I downloaded Stocker files. However, if fails and does not recognises fbprophet.
The message is "ModuleNotFoundError: No module named 'fbprophet'". Any suggestion how to solve this? Other libraries seem to be loading properly. Thanks
I have an error when I try to run the command
# Write graph to a png file
graph.write_png('tree.png');
The error bellow happens even if I have the tree.dot file and installed pip install graphviz
FileNotFoundError Traceback (most recent call last)
/usr/lib/python3.6/site-packages/pydot.py in create(self, prog, format, encoding)
1914 arguments=arguments,
-> 1915 working_dir=tmp_dir,
1916 )
/usr/lib/python3.6/site-packages/pydot.py in call_graphviz(program, arguments, working_dir, **kwargs)
135 stdout=subprocess.PIPE,
--> 136 **kwargs
137 )
/usr/lib/python3.6/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors)
708 errread, errwrite,
--> 709 restore_signals, start_new_session)
710 except:
/usr/lib/python3.6/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
1343 err_msg += ': ' + repr(err_filename)
-> 1344 raise child_exception_type(errno_num, err_msg, err_filename)
1345 raise child_exception_type(err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'dot': 'dot'
During handling of the above exception, another exception occurred:
FileNotFoundError Traceback (most recent call last)
<ipython-input-26-800bf34d174d> in <module>()
1 # Write graph to a png file
----> 2 graph.write_png('tree.png');
/usr/lib/python3.6/site-packages/pydot.py in new_method(path, f, prog, encoding)
1732 self.write(
1733 path, format=f, prog=prog,
-> 1734 encoding=encoding)
1735 name = 'write_{fmt}'.format(fmt=frmt)
1736 self.__setattr__(name, new_method)
/usr/lib/python3.6/site-packages/pydot.py in write(self, path, prog, format, encoding)
1815 f.write(s)
1816 else:
-> 1817 s = self.create(prog, format, encoding=encoding)
1818 with io.open(path, mode='wb') as f:
1819 f.write(s)
/usr/lib/python3.6/site-packages/pydot.py in create(self, prog, format, encoding)
1920 args[1] = '"{prog}" not found in path.'.format(
1921 prog=prog)
-> 1922 raise OSError(*args)
1923 else:
1924 raise
FileNotFoundError: [Errno 2] "dot" not found in path.
Many of these projects are written up on my Towards Data Science Medium page.
can you share links to each code folder pls?
In the mentioned file we are selecting 6 features and further performing predictions using 6 features but the heading and comment says we are selecting 5 features(ref cell no. 22 in the notebook).
First of all, your prediction algorithms are very good.
But the current implementation is looking into only NASDAQ I guess. How can I get the stock predictions for the tickers/symbols (companies) which are in other exchanges like Singapore, China, India, London ?
I tried with those. But they are not working.
Hangs on PyStan installations a fail on windows 10 and Python 3.6. Any ideas why? Thanks.
Getting this message:
Message=cannot import name 'Stocker' from 'stocker' (C:\Users\Colter\AppData\Local\Programs\Python\Python38\lib\site-packages\stocker\__init__.py)
Source=C:\Users\Colter\source\repos\Stockbroker\Stockbroker\Stockbroker.py
StackTrace:
File "C:\Users\Colter\source\repos\Stockbroker\Stockbroker\Stockbroker.py", line 2, in <module>
from stocker import Stocker
This is my code:
`import tensorflow
from stocker import Stocker
amazon = Stocker('AMZN')`
Not sure what to do here?
Edit: Sorry for the double post. The page 404d when I posted it.
Medium data links in Widgets-Overview.ipynb
and Widgets-Overview-Extended Work.ipynb
are incorrect.
df = pd.read_parquet('https://github.com/WillKoehrsen/Data-Analysis/blob/master/medium/data/2019-01-26_stats?raw=true')
should be
df = pd.read_parquet('https://github.com/WillKoehrsen/Data-Analysis/blob/master/medium/data/medium_data_2019_01_26?raw=true')
I keep running into errors when I try 'pip install fbprophet' specifically it seems that the setup.py keep throwing the error does anyone have any suggestions?
I am getting this error
File "D:\anaconda\lib\site-packages\pandas\core\indexes\datetimes.py", line 133, in wrapper
TypeError: <class 'datetime.date'> type object 2015-03-27
Hi! Thanks for all your work. Great script.
When analyzing the CHGG stock vs search term Chegg I get an error ( full error below).
It doesn't give the failed "There are no search terms" because there are search terms ( link to term, https://trends.google.com/trends/explore?date=today%205-y&geo=US&q=chegg ).
But it won't take that search results and index it to the chart... it works for AMZN and Microsoft and broader search terms ie (college) but it yields electoral college, and college football as search terms.
Thanks for all your help in advance.
AttributeError Traceback (most recent call last)
in
----> 1 chegg.changepoint_date_analysis(search = 'chegg')
~\Projects\stocker.py in changepoint_date_analysis(self, search)
779
780 print('\n Top Related Queries: \n')
--> 781 #print(related_queries[search]['top'].head())
782
783 print('\n Rising Related Queries: \n')
AttributeError: 'NoneType' object has no attribute 'head'
from stocker import Stocker
ImportError Traceback (most recent call last)
in
----> 1 from stocker import Stocker
ImportError: cannot import name 'Stocker' from 'stocker' (C:\Users\SHIVSHAKTI\stocker.py)
please help with this issue why I cannot import ??
Hi Will, i can't reach the datasets(flights,flights,airlines) which you use for analysis, visualize would you share with proper way because i want to examine your code step by step with my local jupyter notebook.
HI WillKoehrsen,
Good Evening!!
Quandl website had stopped extracting latest data from NSE and BSE on 4th january 2019 onwards. This message is getting "As of January 9, 2019 this data feed will no longer be actively supported by the Quandl community. We will continue to host this data feed on Quandl, but we do not recommend using it for investment or analysis". Can you please provide update stocker.py code using nse.get_quote or alternate python library instead of quandl.get.
https://www.quandl.com/data/NSE-National-Stock-Exchange-of-India
Thanks in advance.
Error Retrieving Data....
(Status 400) (Quandl Error QEAx01) We could not recognize your API key. Please check your API key and try again.
error was given even after Quandl account was made, key was given, and a new key was given.
Hi there ! I just found what I think is a little error:
# same method but with a search term
msci.changepoint_date_analysis(search = 'Microsoft profit')
...
Top Related Queries:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-21-4e46f891db49> in <module>
1 # same method but with a search term
----> 2 msci.changepoint_date_analysis(search = 'Microsoft profit')
~\Documents\Programming\Luxurynsight\Finance\stocker.py in changepoint_date_analysis(self, search)
779
780 print('\n Top Related Queries: \n')
--> 781 print(related_queries[search]['top'].head())
782
783 print('\n Rising Related Queries: \n')
AttributeError: 'NoneType' object has no attribute 'head'
Another error was raised when running another query:
Top Related Queries:
query value
0 msci index 100
1 msci china 67
2 msci world 56
3 msci 指數 28
4 msci 中國 28
Rising Related Queries:
query value
0 msci 中國 130
1 msci world 50
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-26-080452be5a00> in <module>
1 # same method but with a search term
----> 2 msci.changepoint_date_analysis(search = 'msci')
~\Documents\Programming\Luxurynsight\Finance\stocker.py in changepoint_date_analysis(self, search)
787 trends = trends.resample('D')
788
--> 789 trends = trends.reset_index(level=0)
790 trends = trends.rename(columns={'date': 'ds', search: 'freq'})
791
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\resample.py in __getattr__(self, attr)
95 return self[attr]
96
---> 97 return object.__getattribute__(self, attr)
98
99 @property
AttributeError: 'DatetimeIndexResampler' object has no attribute 'reset_index'
Followed all examples listed and they seemed to work well, however when following the quandl page on api usage, I cannot load information from the Australian Securities Exchange.
s = Stocker(ticker="A2M", exchange="ASX/IBX2019")
Traceback (most recent call last):
File "/home/user/.local/lib/python3.5/site-packages/pandas/core/indexes/base.py", line 3078, in get_loc
return self._engine.get_loc(key)
File "pandas/_libs/index.pyx", line 140, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 162, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 1492, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 1500, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'Close'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/mnt/d/Users/Leo/Documents/MEGA/python/stocker/stocker.py", line 47, in __init__
stock['Adj. Close'] = stock['Close']
File "/home/user/.local/lib/python3.5/site-packages/pandas/core/frame.py", line 2688, in __getitem__
return self._getitem_column(key)
File "/home/user/.local/lib/python3.5/site-packages/pandas/core/frame.py", line 2695, in _getitem_column
return self._get_item_cache(key)
File "/home/user/.local/lib/python3.5/site-packages/pandas/core/generic.py", line 2489, in _get_item_cache
values = self._data.get(item)
File "/home/user/.local/lib/python3.5/site-packages/pandas/core/internals.py", line 4115, in get
loc = self.items.get_loc(item)
File "/home/user/.local/lib/python3.5/site-packages/pandas/core/indexes/base.py", line 3080, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas/_libs/index.pyx", line 140, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 162, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 1492, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 1500, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'Close'
This works for any asx stock I try.
I am trying to use prophet mode on TechM stock
model , model_data = techM.create_prophet_model()
AttributeError Traceback (most recent call last)
in ()
----> 1 model , model_data = techM.create_prophet_model()
~/AmanCode/Python/Stocker/stocker.py in create_prophet_model(self, days, resample)
447 stock_history = self.resample(stock_history)
448
--> 449 model.fit(stock_history)
450
451 # Make and predict for next year with future dataframe
~/anaconda3/lib/python3.6/site-packages/fbprophet/forecaster.py in fit(self, df, **kwargs)
834 try:
835 params = model.optimizing(
--> 836 dat, init=stan_init, iter=1e4, **kwargs)
837 except RuntimeError:
838 params = model.optimizing(
~/anaconda3/lib/python3.6/site-packages/pystan/model.py in optimizing(self, data, seed, init, sample_file, algorithm, verbose, as_vector, **kwargs)
470 data = {}
471 seed = pystan.misc._check_seed(seed)
--> 472 fit = self.fit_class(data, seed)
473
474 m_pars = fit._get_param_names()
AttributeError: 'StanModel' object has no attribute 'fit_class'"
I tried updating numpy as well as pystan , but still getting the same error ..
Running the first examples of Stocker I got this error regarding float conversion of time series.
>>> microsoft = Stocker('MSFT')
MSFT Stocker Initialized. Data covers 1986-03-13 to 2018-03-27.
>>> microsoft.buy_and_hold(start_date='2018-01-01', end_date='2018-01-16', nshares=100)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Programacion\Proyectos\WinPython\JupyterProyectos\Stocker\Data-Analysis-master\stocker\stocker.py", line 331, in buy_and_hold
start_price = float(self.stock[self.stock['Date'] == start_date]['Adj. Open'])
File "C:\Users\rcpoe\Anaconda3\envs\ml_env\lib\site-packages\pandas\core\series.py", line 118, in wrapper
"{0}".format(str(converter)))
TypeError: cannot convert the series to <class 'float'>
It seems related to pandas, the version I have is 0.23.4 as I installed dependencies using conda-forge to make it work (a lot of problems from fbprophet came when I tried to use pip). I will try to find a way to fix this and report back here, but any help will be appreciated as I am quite new to Pandas (and Python in general).
Hello! Interesting project - can I analyze as well Crypto data from Quandl instead of stocks?
If yes, what do I need to change / adapt?
ModuleNotFoundError Traceback (most recent call last)
in ()
----> 1 from stocker import Stocker
ModuleNotFoundError: No module named 'stocker'
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
Link to cell: https://colab.research.google.com/drive/1NBS2wwQmApALKCQrv86Wye4-QwpExq9S#scrollTo=KFpvknWXRRQ6
Would it be possible to have yahoo as a source for the stocker? QUANDL doesnt offer (for free) all world stocks.
Tks
Any plans to put Stocker on PyPi?
I really like the code but the graphs are not displaying anything at my end .. Please suggest .
Refereed below blog for everything :
https://towardsdatascience.com/the-next-level-of-data-visualization-in-python-dd6e99039d5e
I just had a question about how you installed your packages... I am having issues installing pystan because it requires a C++ compiler, however, I am not able to install one. This then affects the installation of fbprophet. If you could explain what you did, that would be of great help.
Thanks!
When I initial the Stocker instance, I can only load stock data up to 3/27/2018. I tried other ticker, same problem. Please help.
microsoft = Stocker(ticker='MSFT')
MSFT Stocker Initialized. Data covers 1986-03-13 to 2018-03-27.
Thanks.
Hi
I am running Stocker but the dates covered are only upto 2018-03-27 . Is there a fix possible for this ?
Hi,
As per the issue, df_summary in pymc3 has to be replaced with summary.
pymc-devs/pymc#3512
I came across it in https://github.com/WillKoehrsen/Data-Analysis/blob/master/bayesian_lr/Bayesian%20Linear%20Regression%20Project.ipynb
Hello, my Kernel always crashes when loading the data from like in cell 4 in the widgets tutorial:
df = pd.read_parquet('https://github.com/WillKoehrsen/Data-Analysis/blob/master/medium/data/medium_data_2019_01_26?raw=true')
this is my anaconda environment
# Name Version Build Channel
_tflow_select 2.2.0 eigen
absl-py 0.9.0 py36_0 conda-forge
arviz 0.7.0 py_0 conda-forge
asn1crypto 1.3.0 py36_0 conda-forge
astor 0.8.0 py36_0
attrs 19.3.0 py_0 conda-forge
backcall 0.1.0 py_0 conda-forge
blas 1.0 mkl conda-forge
bleach 3.1.4 pyh9f0ad1d_0 conda-forge
blinker 1.4 py36_0
bqplot 0.12.7 pyh9f0ad1d_0 conda-forge
bzip2 1.0.8 hfa6e2cd_2 conda-forge
ca-certificates 2020.1.1 0
cachetools 3.1.1 py_0 conda-forge
certifi 2020.4.5.1 py36_0
cffi 1.14.0 py36h7a1dbc1_0
cftime 1.1.1.2 py36hbd37c6d_0 conda-forge
chardet 3.0.4 py36_1003 conda-forge
chart-studio 1.1.0 py_0 plotly
click 7.1.1 py_0
cloudpickle 1.4.1 py_0 conda-forge
cmdstanpy 0.4.0 pypi_0 pypi
colorama 0.4.3 py_0 conda-forge
colorlover 0.3.0 py_0 conda-forge
convertdate 2.1.3 py_1000 conda-forge
cryptography 2.8 py36h7a1dbc1_0
cufflinks-py 0.17.3 py_0 conda-forge
curl 7.69.1 h1dcc11c_0 conda-forge
cycler 0.10.0 py36h009560c_0
cython 0.29.17 py36h003fed8_0 conda-forge
cytoolz 0.10.1 py36hfa6e2cd_0 conda-forge
dask-core 2.15.0 py_0 conda-forge
decorator 4.4.2 py_0 conda-forge
defusedxml 0.6.0 py_0 conda-forge
entrypoints 0.3 py36h9f0ad1d_1001 conda-forge
ephem 3.7.7.0 py36he774522_0
fastparquet 0.3.3 py36hc8d92b1_0 conda-forge
fbprophet 0.6 py36h6538335_0 conda-forge
freetype 2.9.1 ha9979f8_1
gast 0.2.2 py36_0
google-auth 1.13.1 py_0
google-auth-oauthlib 0.4.1 py_2 conda-forge
google-pasta 0.2.0 py_0
grpcio 1.27.2 py36h351948d_0
h5py 2.10.0 py36h5e291fa_0
hdf4 4.2.13 h712560f_2
hdf5 1.10.4 h7ebc959_0
holidays 0.10.1 py_0 conda-forge
icc_rt 2019.0.0 h0cc432a_1
icu 58.2 ha925a31_3
idna 2.9 py_1 conda-forge
imageio 2.8.0 py_0 conda-forge
importlib-metadata 1.6.0 py36h9f0ad1d_0 conda-forge
importlib_metadata 1.6.0 0 conda-forge
inflection 0.4.0 pypi_0 pypi
intel-openmp 2020.0 166
ipydatawidgets 4.0.1 py_0 conda-forge
ipykernel 5.2.1 py36h5ca1d4c_0 conda-forge
ipyscales 0.4.0 py_1 conda-forge
ipython 7.13.0 py36h9f0ad1d_2 conda-forge
ipython_genutils 0.2.0 py_1 conda-forge
ipyvolume 0.6.0a4 pyh9f0ad1d_0 conda-forge
ipywebrtc 0.5.0 py36_0 conda-forge
ipywidgets 7.5.1 py_0 conda-forge
jedi 0.17.0 py36h9f0ad1d_0 conda-forge
jinja2 2.11.2 pyh9f0ad1d_0 conda-forge
joblib 0.14.1 pypi_0 pypi
jpeg 9b hb83a4c4_2
jsonschema 3.2.0 py36h9f0ad1d_1 conda-forge
jupyter_client 6.1.3 py_0 conda-forge
jupyter_core 4.6.3 py36h9f0ad1d_1 conda-forge
keras 2.3.1 pypi_0 pypi
keras-applications 1.0.8 py_0
keras-preprocessing 1.1.0 py_1
kiwisolver 1.1.0 py36ha925a31_0
krb5 1.17.1 hdd46e55_0 conda-forge
libblas 3.8.0 15_mkl conda-forge
libcblas 3.8.0 15_mkl conda-forge
libcurl 7.69.1 h1dcc11c_0 conda-forge
liblapack 3.8.0 15_mkl conda-forge
libnetcdf 4.7.3 h1302dcc_0
libpng 1.6.37 h2a8f88b_0
libprotobuf 3.11.4 h7bd577a_0
libpython 2.1 py36_0
libsodium 1.0.17 h2fa13f4_0 conda-forge
libssh2 1.8.2 h642c060_2 conda-forge
libtiff 4.1.0 h56a325e_0
llvmlite 0.31.0 py36h9f0ad1d_1 conda-forge
lunarcalendar 0.0.9 py_0 conda-forge
lxml 4.5.0 pypi_0 pypi
m2w64-binutils 2.25.1 5
m2w64-bzip2 1.0.6 6
m2w64-crt-git 5.0.0.4636.2595836 2
m2w64-gcc 5.3.0 6
m2w64-gcc-ada 5.3.0 6
m2w64-gcc-fortran 5.3.0 6
m2w64-gcc-libgfortran 5.3.0 6
m2w64-gcc-libs 5.3.0 7
m2w64-gcc-libs-core 5.3.0 7
m2w64-gcc-objc 5.3.0 6
m2w64-gmp 6.1.0 2
m2w64-headers-git 5.0.0.4636.c0ad18a 2
m2w64-isl 0.16.1 2
m2w64-libiconv 1.14 6
m2w64-libmangle-git 5.0.0.4509.2e5a9a2 2
m2w64-libwinpthread-git 5.0.0.4634.697f757 2
m2w64-make 4.1.2351.a80a8b8 2
m2w64-mpc 1.0.3 3
m2w64-mpfr 3.1.4 4
m2w64-pkg-config 0.29.1 2
m2w64-toolchain 5.3.0 7
m2w64-toolchain_win-64 2.4.0 0 conda-forge
m2w64-tools-git 5.0.0.4592.90b8472 2
m2w64-windows-default-manifest 6.4 3
m2w64-winpthreads-git 5.0.0.4634.697f757 2
m2w64-zlib 1.2.8 10
markdown 3.1.1 py36_0
markupsafe 1.1.1 py36h68a101e_1 conda-forge
matplotlib-base 3.2.1 py36hf0cddfc_0 conda-forge
mistune 0.8.4 py36h68a101e_1001 conda-forge
mkl 2020.0 166
mkl-service 2.3.0 py36hb782905_0
mkl_fft 1.0.15 py36h14836fe_0
mkl_random 1.1.0 py36h675688f_0
more-itertools 8.2.0 pypi_0 pypi
msys2-conda-epoch 20160418 1
nbconvert 5.6.1 py36h9f0ad1d_1 conda-forge
nbformat 5.0.6 py_0 conda-forge
netcdf4 1.5.3 py36h012c1a0_0
networkx 2.4 py_1 conda-forge
notebook 6.0.3 py36_0 conda-forge
numba 0.48.0 py36he350917_0 conda-forge
numpy 1.18.3 pypi_0 pypi
oauthlib 3.1.0 py_0
olefile 0.46 py_0 conda-forge
openssl 1.1.1g he774522_0
opt-einsum 3.2.1 pypi_0 pypi
opt_einsum 3.1.0 py_0
packaging 20.1 py_0 conda-forge
pandas 1.0.3 py36h47e9c7a_0
pandas-datareader 0.8.1 pypi_0 pypi
pandoc 2.9.2.1 0 conda-forge
pandocfilters 1.4.2 py_1 conda-forge
parso 0.7.0 pyh9f0ad1d_0 conda-forge
pickleshare 0.7.5 py36h9f0ad1d_1001 conda-forge
pillow 7.0.0 py36hcc1f983_0
pip 20.0.2 py36_1
plotly 4.6.0 py_0 plotly
prometheus_client 0.7.1 py_0 conda-forge
prompt-toolkit 3.0.5 py_0 conda-forge
protobuf 3.11.4 py36h33f27b4_0
pyarrow 0.17.0 pypi_0 pypi
pyasn1 0.4.8 py_0 conda-forge
pyasn1-modules 0.2.7 py_0 conda-forge
pycparser 2.20 py_0 conda-forge
pygments 2.6.1 py_0 conda-forge
pyjwt 1.7.1 py36_0
pyopenssl 19.1.0 py36_0 conda-forge
pyparsing 2.4.6 py_0 conda-forge
pyqt 5.9.2 py36h6538335_2
pyreadline 2.1 py36_1
pyrsistent 0.16.0 py36h68a101e_0 conda-forge
pysocks 1.7.1 py36_0 conda-forge
pystan 2.19.0.0 pypi_0 pypi
python 3.6.10 h9f7ef89_1
python-cufflinks 0.17.3 py_0 conda-forge
python-dateutil 2.8.1 py_0 conda-forge
python-snappy 0.5.4 py36ha925a31_0
python_abi 3.6 1_cp36m conda-forge
pythreejs 2.2.0 pyh8c360ce_0 conda-forge
pytrends 4.7.2 pypi_0 pypi
pytz 2019.3 py_0 conda-forge
pywavelets 1.1.1 py36h7725771_1 conda-forge
pywin32 227 py36hfa6e2cd_0 conda-forge
pywinpty 0.5.7 py36_0 conda-forge
pyyaml 5.3.1 pypi_0 pypi
pyzmq 19.0.0 py36ha89082f_1 conda-forge
qt 5.9.7 vc14h73c81de_0
quandl 3.5.0 pypi_0 pypi
requests 2.23.0 py36_0 conda-forge
requests-oauthlib 1.3.0 py_0
retrying 1.3.3 py36_2
rsa 4.0 py_0 conda-forge
scikit-image 0.16.2 py36he350917_0 conda-forge
scikit-learn 0.22.2.post1 pypi_0 pypi
scipy 1.4.1 py36h9439919_0
send2trash 1.5.0 py_0 conda-forge
setuptools 46.1.3 py36_0
setuptools-git 1.2 pypi_0 pypi
sip 4.19.8 py36h6538335_0 conda-forge
six 1.14.0 py36_0 conda-forge
snappy 1.1.8 he025d50_1 conda-forge
sqlite 3.31.1 h2a8f88b_1
stocker 0.1.5 pypi_0 pypi
tensorboard 2.1.0 py3_0
tensorflow 2.1.0 eigen_py36hdbbabfe_0
tensorflow-base 2.1.0 eigen_py36h49b2757_0
tensorflow-estimator 2.1.0 pyhd54b08b_0
termcolor 1.1.0 py36_1 conda-forge
terminado 0.8.3 py36h9f0ad1d_1 conda-forge
testpath 0.4.4 py_0 conda-forge
thrift 0.11.0 py36h6538335_1001 conda-forge
tk 8.6.10 hfa6e2cd_0 conda-forge
toolz 0.10.0 py_0 conda-forge
tornado 6.0.4 py36he774522_1
traitlets 4.3.3 py36h9f0ad1d_1 conda-forge
traittypes 0.2.1 py_1 conda-forge
urllib3 1.25.8 py36_0
vc 14.1 h0510ff6_4
vs2015_runtime 14.16.27012 hf0eaf9b_1
wcwidth 0.1.9 pyh9f0ad1d_0 conda-forge
webencodings 0.5.1 py_1 conda-forge
werkzeug 0.14.1 py36_0
wheel 0.34.2 py36_0 conda-forge
widgetsnbextension 3.5.1 py36_0 conda-forge
win_inet_pton 1.1.0 py36_0 conda-forge
wincertstore 0.2 py36h7fe50ca_0
winpty 0.4.3 4 conda-forge
wrapt 1.12.1 py36he774522_1
xarray 0.15.1 py_0 conda-forge
xz 5.2.5 h2fa13f4_0 conda-forge
zeromq 4.3.2 h6538335_2 conda-forge
zipp 3.1.0 py_0 conda-forge
zlib 1.2.11 h62dcd97_4
zstd 1.3.7 h508b16e_0
when i try to use your code in pycharm it says that no module named stocker found.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.