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


Python BigML.create_ensemble方法代码示例

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


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

示例1: BigML

# 需要导入模块: from bigml.api import BigML [as 别名]
# 或者: from bigml.api.BigML import create_ensemble [as 别名]
api = BigML()

# <codecell>

# Create source instance with train dataset
train_source = api.create_source('train.csv')

# <codecell>

# Create a BigML dataset from source instance
train_dataset = api.create_dataset(train_source)

# <codecell>

# Fit a model to the dataset
model = api.create_ensemble(train_dataset)

# <codecell>

# Read the test dataset
test_X = pd.read_csv('test.csv')
test_y = pd.read_csv('test_target.csv')
test_set = test_X.T.to_dict().values()

# <codecell>

# Holds predictions from all the samples in test set
prediction = []

for x in test_set:
    # Get predictions for complete test set
开发者ID:rishy,项目名称:phishing-websites,代码行数:33,代码来源:BigML_classification.py

示例2: BigML

# 需要导入模块: from bigml.api import BigML [as 别名]
# 或者: from bigml.api.BigML import create_ensemble [as 别名]
from bigml.api import BigML
api = BigML()

source1 = api.create_source("iris.csv")
api.ok(source1)

dataset1 = api.create_dataset(source1, \
    {'name': u'iris dataset'})
api.ok(dataset1)

ensemble1 = api.create_ensemble(dataset1, \
    {'name': u'my_ensemble_name'})
api.ok(ensemble1)
开发者ID:ABourcevet,项目名称:bigmler,代码行数:15,代码来源:reify_ensemble.py

示例3: BigMLTester

# 需要导入模块: from bigml.api import BigML [as 别名]
# 或者: from bigml.api.BigML import create_ensemble [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

示例4: BigML

# 需要导入模块: from bigml.api import BigML [as 别名]
# 或者: from bigml.api.BigML import create_ensemble [as 别名]
 from bigml.api import BigML
 api = BigML()
 source1_file = "iris.csv"
 args = \
     {u'fields': {u'000000': {u'name': u'sepal length', u'optype': u'numeric'},
                  u'000001': {u'name': u'sepal width', u'optype': u'numeric'},
                  u'000002': {u'name': u'petal length', u'optype': u'numeric'},
                  u'000003': {u'name': u'petal width', u'optype': u'numeric'},
                  u'000004': {u'name': u'species',
                              u'optype': u'categorical',
                              u'term_analysis': {u'enabled': True}}},
      }
 source2 = api.create_source(source1_file, args)
 api.ok(source2)
 
 args = \
     {u'objective_field': {u'id': u'000004'},
      }
 dataset1 = api.create_dataset(source2, args)
 api.ok(dataset1)
 
 args = \
     {u'ensemble_sample': {u'rate': 1, u'replacement': True, u'seed': u'bigml'},
               u'seed': u'BigML',
      u'stat_pruning': False}
 ensemble1 = api.create_ensemble(dataset1, args)
 api.ok(ensemble1)
 
开发者ID:shantanusharma,项目名称:bigmler,代码行数:29,代码来源:reify_ensemble.py

示例5: main

# 需要导入模块: from bigml.api import BigML [as 别名]
# 或者: from bigml.api.BigML import create_ensemble [as 别名]
def main(args=sys.argv[1:]):
    """Parses command-line parameters and calls the actual main function.

    """
    parser = argparse.ArgumentParser(description="Market sentiment analysis", epilog="BigML, Inc")

    # source with activity data
    parser.add_argument("--data", action="store", dest="data", default="data", help="Full path to data with csv files")

    # create private links or not
    parser.add_argument("--share", action="store_true", default=True, help="Share created resources or not")

    args = parser.parse_args(args)

    if not args.data:
        sys.exit("You need to provide a valid path to a data directory")

    api = BigML()

    name = "UpOrDown?"

    log("Creating sources...")
    csvs = glob.glob(os.path.join(args.data, "*.csv"))
    sources = []
    for csv in csvs:
        source = api.create_source(csv)
        api.ok(source)
        sources.append(source)

    log("Creating datasets...")
    datasets = []
    for source in sources:
        dataset = api.create_dataset(source)
        api.ok(dataset)
        datasets.append(dataset)

    new_datasets = []
    for dataset in datasets:
        new_dataset = api.create_dataset(dataset, {"new_fields": new_fields(), "all_fields": False})
        new_datasets.append(new_dataset)

    log("Merging datasets...")
    multi_dataset = api.create_dataset(new_datasets, {"name": name})
    api.ok(multi_dataset)

    # Create training and test set for evaluation
    log("Splitting dataset...")
    training, test = training_test_split(api, multi_dataset)

    log("Creating a model using the training dataset...")
    model = api.create_model(training, {"name": name + " (80%)"})
    api.ok(model)

    # Creating an evaluation
    log("Evaluating model against the test dataset...")
    eval_args = {"name": name + " - Single model: 80% vs 20%"}
    evaluation_model = api.create_evaluation(model, test, eval_args)
    api.ok(evaluation_model)

    log("Creating an ensemble using the training dataset...")
    ensemble = api.create_ensemble(training, {"name": name})
    api.ok(ensemble)

    # Creating an evaluation
    log("Evaluating ensemble against the test dataset...")
    eval_args = {"name": name + " - Ensemble: 80% vs 20%"}
    evaluation_ensemble = api.create_evaluation(ensemble, test, eval_args)
    api.ok(evaluation_ensemble)

    log("Creating model for the full dataset...")
    model = api.create_model(multi_dataset, {"name": name})
    api.ok(model)

    # Create private links
    if args.share:
        log("Sharing resources...")
        dataset_link = share_resource(api, multi_dataset)
        model_link = share_resource(api, model)
        evaluation_model_link = share_resource(api, evaluation_model)
        evaluation_ensemble_link = share_resource(api, evaluation_ensemble)
        log(dataset_link)
        log(model_link)
        log(evaluation_model_link)
        log(evaluation_ensemble_link)
开发者ID:jaor,项目名称:upordown,代码行数:86,代码来源:upordown.py

示例6: BigML

# 需要导入模块: from bigml.api import BigML [as 别名]
# 或者: from bigml.api.BigML import create_ensemble [as 别名]
from bigml.api import BigML

api = BigML()

source1 = api.create_source("iris.csv")
api.ok(source1)

dataset1 = api.create_dataset(source1, {"name": u"iris dataset"})
api.ok(dataset1)

ensemble1 = api.create_ensemble(dataset1, {"name": u"my_ensemble_name", "seed": u"BigML"})
api.ok(ensemble1)
开发者ID:bigmlcom,项目名称:bigmler,代码行数:14,代码来源:reify_ensemble.py


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