skmultiuflow.data.FileStream
从文件资源建立一个流。
class skmultiflow.data.FileSteram(filepath,target_idx = -1,n_targets = 1, cat_features = None,allow_nan = False)
目前只支持csv文件,但是目标旨在支持不同格式。只要有一个方法能够正确读取,解析,并返回pandas的数据框,或者numpy.ndarray
参数:
参数 | 解释 |
---|---|
filepath | 数据文件路径 |
target_idx | 整型,可选的(默认值为-1):指标开始的列索引 |
n_target | 整型,可选的(默认值为1):指标数量 |
cat_features | 列表,可选的(默认值为None):与分类特征的位置相对应的索引列表。 |
allow_nan | 布尔,可选的(默认值为False):如果真,允许数据中的NaN(空值),否则,报错。 |
注意:
根据请求,流对象提供了大量样本,在某种程度上,旧的样本在以后不能被访问。这样做是为了正确模拟流文件。
示例:
# Imports
from skmultiflow.data.file_stream import FileStream
# Setup the stream
stream = FileStream("https://raw.githubusercontent.com/scikit-multiflow/"
"streaming-datasets/master/sea_stream.csv")
# Retrieving one sample
stream.next_sample()
>>>(array([[0.080429, 8.397187, 7.074928]]), array([0]))
# Retrieving 10 samples
stream.next_sample(10)
>>> (array([[1.42074 , 7.504724, 6.764101],
[0.960543, 5.168416, 8.298959],
[3.367279, 6.797711, 4.857875],
[9.265933, 8.548432, 2.460325],
[7.295862, 2.373183, 3.427656],
[9.289001, 3.280215, 3.154171],
[0.279599, 7.340643, 3.729721],
[4.387696, 1.97443 , 6.447183],
[2.933823, 7.150514, 2.566901],
[4.303049, 1.471813, 9.078151]]),
array([0, 0, 1, 1, 1, 1, 0, 0, 1, 0]))
stream.n_remaining_samples()
>>>39989
stream.has_more_samples()
>>>True
方法:
方法 | 解释 |
---|---|
get_all samples(self) | 返回流的所有样本 |
get_data_info(self) | 从流中检索最小信息 |
get_info(self) | 收集,并返回估计器的配置信息 |
get_jparam(self[,deep]) | 获取估计器的参数 |
has_more_samples(self) | 检查流中是否有更多的样本 |
is_restartable(self) | 确定流是否可以重启 |
last_sample(self) | 在流中检索上个batch_size样本 |
n_remaining_samples(self) | 返回剩余样本需要估计的数量 |
next_sample(self[,batch_size]) | 返回流中的下一个样本 |
prepare_for_use() | 为流的使用准备 |
reset(self) | 将检测器重置为初始状态 |
restart(self) | 流重启 |
set_params(self,**params) | 设置此估计器的参数 |
属性:
属性 | 解释 |
---|---|
cat_features_idx | 获取特征索引列表 |
features_names | 检索特征的名称 |
n_cat_features | 检索特征的数量 |
n_num_features | 检索数值特征的数量 |
n_targets | 获取目标数量 |
target_idx | 获取当Y开始时列的数量 |
target_names | 检索目标名称 |
target_values | 检索流中每个目标的目标值 |