问题描述
我能够毫无问题地编译代码,并生成图表.
我想使用不同的数据源.目前他们使用的是股票价格:
d1 = datetime.datetime(2003, 01, 01)d2 = datetime.datetime(2008, 01, 01)符号字典 = {'TOT': '总计','XOM': '埃克森美孚','CVX': '雪佛龙','COP': '康菲石油',......}符号,名称 = np.array(symbol_dict.items()).T报价 = [finance.quotes_historical_yahoo(symbol, d1, d2, asobject=True)对于符号中的符号]open = np.array([q.open for q in引号]).astype(np.float)close = np.array([q.close for q in引号]).astype(np.float)
quotes
返回什么?我知道这是每只股票的价格,但我得到的是这样的信息:
[rec.array([ (datetime.date(2003, 1, 2), 2003, 1, 2, 731217.0,28.12235692134198, 28.5, 28.564279672963064, 28.09825204398083, 12798800.0, 28.5),(datetime.date(2003, 1, 3), 2003, 1, 3, 731218.0, 28.329084507042257, 28.53, 28.634476056338034, 28.28840.30, 28.288409017)(datetime.date(2003, 1, 6), 2003, 1, 6, 731221.0, 28.482778999450247, 29.23, 29.406761957119297, 28.46761957119297, 28.4607940, 28.46778921.0, 28.46778940....,
- 我想输入我自己的数据集.你能给我一个数据集的例子,我可以输入到
quotes
中吗?
完整代码在这里:
http://scikit-learn.org/dev/auto_examples/applications/plot_stock_market.html
如果你在 ipython 中执行 finance.quotes_historical_yahoo?
它会告诉你:
在[53]:finance.quotes_historical_yahoo?类型:函数字符串形式:<函数quotes_historical_yahoo at 0x10f311d70>文件:/Users/dvelkov/src/matplotlib/lib/matplotlib/finance.py定义:finance.quotes_historical_yahoo(ticker, date1, date2, asobject=False,adjusted=True, cachename=None)文档字符串:获取 date1 和 date2 之间股票代码的历史数据.日期 1 和date2 是日期时间实例或(年、月、日)序列.有关输出格式的说明,请参阅 :func:`parse_yahoo_historical`和 *asobject* 和 *adjusted* kwargs....(更多东西)
所以我们检查parse_yahoo_historical
:
在[54]:finance.parse_yahoo_historical?类型:函数字符串形式:文件:/Users/dvelkov/src/matplotlib/lib/matplotlib/finance.py定义:finance.parse_yahoo_historical(fh,adjusted=True,asobject=False)文档字符串:解析来自雅虎财经的文件句柄 fh 中的历史数据.*调整*如果为 True(默认),将开盘价、收盘价、最高价和最低价替换为它们的调整值.调整是按比例因子,S =调整后关闭/关闭.调整后价格为实际价格乘以 S.音量未调整,因为它已经向后拆分调整通过雅虎.如果你想计算交易的美元,乘以交易量由调整后关闭,无论您是否选择调整后= 真|假.*作为对象*如果为 False(默认为与早期版本兼容)返回包含的元组列表d、开、关、高、低、成交量如果 None(首选替代 False),则返回对应于元组列表的二维 ndarray.否则返回一个 numpy recarray日期、年、月、日、d、开、关、高、低、音量,adjusted_close其中 d 是日期的浮动点表示,由 date2num 返回,日期是 python 标准库 datetime.date 实例.这个夸格的名字是一个历史文物.以前,True 返回了一本 cbook Bunch持有一维 ndarrays.numpy recarray 的行为是与 Bunch 非常相似.
在您的情况下,您使用的是 asobject=True
,因此您得到的格式是 date、year、month、day、d、open、close、high、low、volume、adjusted_close代码>.
I've been wildly curious about machine learning, and I'm using this to learn.
I was able to compile the code without issue, and generate the graph.
I would like to use a different data source. Currently they are using stock prices:
d1 = datetime.datetime(2003, 01, 01)
d2 = datetime.datetime(2008, 01, 01)
symbol_dict = {
'TOT': 'Total',
'XOM': 'Exxon',
'CVX': 'Chevron',
'COP': 'ConocoPhillips',
...
...
}
symbols, names = np.array(symbol_dict.items()).T
quotes = [finance.quotes_historical_yahoo(symbol, d1, d2, asobject=True)
for symbol in symbols]
open = np.array([q.open for q in quotes]).astype(np.float)
close = np.array([q.close for q in quotes]).astype(np.float)
- what does
quotes
return? I understand it is price per stock, but I am getting something like this:
- i would like to input my own dataset. can you please give me an example of a dataset that I can input into
quotes
?
the entire code is here:
http://scikit-learn.org/dev/auto_examples/applications/plot_stock_market.html
If you execute finance.quotes_historical_yahoo?
in ipython it would tell you:
In [53]: finance.quotes_historical_yahoo?
Type: function
String Form:<function quotes_historical_yahoo at 0x10f311d70>
File: /Users/dvelkov/src/matplotlib/lib/matplotlib/finance.py
Definition: finance.quotes_historical_yahoo(ticker, date1, date2, asobject=False, adjusted=True, cachename=None)
Docstring:
Get historical data for ticker between date1 and date2. date1 and
date2 are datetime instances or (year, month, day) sequences.
See :func:`parse_yahoo_historical` for explanation of output formats
and the *asobject* and *adjusted* kwargs.
...(more stuff)
So we check parse_yahoo_historical
:
In [54]: finance.parse_yahoo_historical?
Type: function
String Form:<function parse_yahoo_historical at 0x10f996ed8>
File: /Users/dvelkov/src/matplotlib/lib/matplotlib/finance.py
Definition: finance.parse_yahoo_historical(fh, adjusted=True, asobject=False)
Docstring:
Parse the historical data in file handle fh from yahoo finance.
*adjusted*
If True (default) replace open, close, high, and low prices with
their adjusted values. The adjustment is by a scale factor, S =
adjusted_close/close. Adjusted prices are actual prices
multiplied by S.
Volume is not adjusted as it is already backward split adjusted
by Yahoo. If you want to compute dollars traded, multiply volume
by the adjusted close, regardless of whether you choose adjusted
= True|False.
*asobject*
If False (default for compatibility with earlier versions)
return a list of tuples containing
d, open, close, high, low, volume
If None (preferred alternative to False), return
a 2-D ndarray corresponding to the list of tuples.
Otherwise return a numpy recarray with
date, year, month, day, d, open, close, high, low,
volume, adjusted_close
where d is a floating poing representation of date,
as returned by date2num, and date is a python standard
library datetime.date instance.
The name of this kwarg is a historical artifact. Formerly,
True returned a cbook Bunch
holding 1-D ndarrays. The behavior of a numpy recarray is
very similar to the Bunch.
In your case you are using asobject=True
so the format you get is date, year, month, day, d, open, close, high, low, volume, adjusted_close
.
这篇关于为机器学习选择正确的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!