当前位置: 首页>>代码示例>>Python>>正文


Python BigML.get_source方法代码示例

本文整理汇总了Python中bigml.api.BigML.get_source方法的典型用法代码示例。如果您正苦于以下问题:Python BigML.get_source方法的具体用法?Python BigML.get_source怎么用?Python BigML.get_source使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bigml.api.BigML的用法示例。


在下文中一共展示了BigML.get_source方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: BigMLTester

# 需要导入模块: from bigml.api import BigML [as 别名]
# 或者: from bigml.api.BigML import get_source [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')
#.........这里部分代码省略.........
开发者ID:cheesinglee,项目名称:random_forest_compare,代码行数:103,代码来源:bigml_tester.py


注:本文中的bigml.api.BigML.get_source方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。