本文整理汇总了Python中bigml.api.BigML.list_sources方法的典型用法代码示例。如果您正苦于以下问题:Python BigML.list_sources方法的具体用法?Python BigML.list_sources怎么用?Python BigML.list_sources使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bigml.api.BigML
的用法示例。
在下文中一共展示了BigML.list_sources方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BigMLTester
# 需要导入模块: from bigml.api import BigML [as 别名]
# 或者: from bigml.api.BigML import list_sources [as 别名]
class BigMLTester(ForestTester):
api = None
authenticated = False
source_res = None
ensemble_res = None
logger = None
train_time = -1
predict_time = -1
results = None
test_data = None
def __init__(self,*args,**kwargs):
print args
print kwargs
bigml_user = kwargs.get('bigml_user',None)
bigml_key = kwargs.get('bigml_key',None)
ForestTester.__init__(self,*args,**kwargs)
self.authenticate(bigml_user,bigml_key)
self.logger = logging.getLogger(__name__)
self.logger.addHandler(logging.FileHandler('BigMLTester.log'))
self.logger.setLevel(logging.DEBUG)
def authenticate(self,bigml_user,bigml_key):
"""
initialize the BigML API, do a short test to check authentication
"""
self.api = BigML(username=bigml_user,api_key=bigml_key)
result = self.api.list_sources()
if result['code'] == 200:
self.authenticated = True
else:
self.authenticated = False
def upload_source(self,filename):
"""
Upload a sourcefile to BigML. Return resource value.
"""
assert self.authenticated, 'Not authenticated!'
# check if source file has already been uploaded
query_string = 'name={}'.format(filename)
matching_sources = self.api.list_sources(query_string)['objects']
if len(matching_sources) > 0:
source = matching_sources[0]
self.logger.info('{0} is already present in BigML'.format(basename(filename)))
else:
self.logger.info('uploading source to BigML...')
source = self.api.create_source(filename,{'name':filename})
# enter polling loop until source becomes ready
check_resource(source['resource'],self.api.get_source)
return source['resource']
def make_dataset(self,source_res):
"""
Create a BigML dataset from the given source resource. Returns dataset
resource value.
"""
assert self.authenticated, 'Not authenticated!'
# check if dataset has already been created
query_string = 'source={}'.format(source_res)
matching_datasets = self.api.list_datasets(query_string)['objects']
if len(matching_datasets) > 0:
dataset = matching_datasets[0]
self.logger.info('A dataset already exits for this source')
else:
filename = self.api.get_source(source_res)['object']['file_name']
datasetname = "{0}'s dataset".format(filename)
dataset = self.api.create_dataset(source_res,{'name':datasetname})
# enter polling loop until dataset becomes ready
check_resource(dataset['resource'],self.api.get_dataset)
return dataset['resource']
def train_ensemble(self,train_data):
assert self.authenticated, 'Not authenticated!'
ensemble_args = {'number_of_models':self.n_trees,
'sample_rate':self.sample_rate,
'randomize':self.randomize,
'replacement':self.bootstrap,
'tlp':5}
ensemble = self.api.create_ensemble(train_data,ensemble_args)
self.ensemble_res = ensemble['resource']
# enter polling loop until ensemble becomes ready
ensemble = check_resource(self.ensemble_res,self.api.get_ensemble)
self.logger.info('Ensemble is ready')
self.train_time = ensemble['object']['status']['elapsed']/1000
def test_ensemble(self,test_file):
assert self.authenticated, 'Not authenticated!'
# download a local copy of the ensemble
self.logger.info('Creating local ensemble')
#.........这里部分代码省略.........