本文整理汇总了Python中bigml.api.BigML.create_model方法的典型用法代码示例。如果您正苦于以下问题:Python BigML.create_model方法的具体用法?Python BigML.create_model怎么用?Python BigML.create_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bigml.api.BigML
的用法示例。
在下文中一共展示了BigML.create_model方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bigml
# 需要导入模块: from bigml.api import BigML [as 别名]
# 或者: from bigml.api.BigML import create_model [as 别名]
def bigml( train_csv, test_csv, result_csv ):
api = BigML(dev_mode=True)
# train model
start_training = timer()
source_train = api.create_source(train_csv)
dataset_train = api.create_dataset(source_train)
model = api.create_model(dataset_train)
end_training = timer()
print('Training model.')
print('Training took %i Seconds.' % (end_training - start_training) );
# test create_model
start_test = timer()
source_test = api.create_source(test_csv)
dataset_test = api.create_dataset(source_test)
batch_prediction = api.create_batch_prediction(
model,
dataset_test,
{
"name": "census prediction",
"all_fields": True,
"header": False,
"confidence": False
}
)
# wait until batch processing is finished
while api.get_batch_prediction(batch_prediction)['object']['status']['progress'] != 1:
print api.get_batch_prediction(batch_prediction)['object']['status']['progress']
time.sleep(1)
end_test = timer()
print('Testing took %i Seconds' % (end_test - start_test) );
api.download_batch_prediction(batch_prediction['resource'], filename=result_csv)
# cleanup
api.delete_source(source_train)
api.delete_source(source_test)
api.delete_dataset(dataset_train)
api.delete_dataset(dataset_test)
api.delete_model(model)
示例2: BigML
# 需要导入模块: from bigml.api import BigML [as 别名]
# 或者: from bigml.api.BigML import create_model [as 别名]
from bigml.api import BigML
api = BigML()
source1 = api.create_source("iris.csv")
api.ok(source1)
dataset1 = api.create_dataset(source1)
api.ok(dataset1)
model1 = api.create_model(dataset1)
api.ok(model1)
batchprediction1 = api.create_batch_prediction(model1, dataset1, {"name": u"my_batch_prediction_name"})
api.ok(batchprediction1)
示例3: BigML
# 需要导入模块: from bigml.api import BigML [as 别名]
# 或者: from bigml.api.BigML import create_model [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'})
api.ok(dataset1)
model1 = api.create_model(dataset1, \
{'name': u'iris'})
api.ok(model1)
prediction1 = api.create_prediction(model1, \
{u'petal length': 0.5}, \
{'name': u'my_prediction_name'})
api.ok(prediction1)
示例4: BigML
# 需要导入模块: from bigml.api import BigML [as 别名]
# 或者: from bigml.api.BigML import create_model [as 别名]
#@see: http://bigml.readthedocs.org/en/latest/#local-predictions
from bigml.api import BigML
api = BigML('smarkit',"37b903bf765414b5e1c3164061cee5fa57e7e6ad",storage='./storage')
source = api.create_source('./data/red_bule_balls_2003.csv')
api.pprint(api.get_fields(source))
dataset = api.create_dataset(source)
model = api.create_model(dataset)
prediction = api.create_prediction(model, {'red':[1,2,3,4,5,6],'blue':7})
#prediction
api.pprint(prediction)
示例5: BigML
# 需要导入模块: from bigml.api import BigML [as 别名]
# 或者: from bigml.api.BigML import create_model [as 别名]
from bigml.api import BigML
api = BigML()
source1 = api.create_source("iris.csv")
api.ok(source1)
dataset1 = api.create_dataset(source1)
api.ok(dataset1)
model1 = api.create_model(dataset1, \
{'name': u'my_model_name'})
api.ok(model1)
示例6: BigML
# 需要导入模块: from bigml.api import BigML [as 别名]
# 或者: from bigml.api.BigML import create_model [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'split_candidates': 32}
model1 = api.create_model(dataset1, args)
api.ok(model1)
示例7: main
# 需要导入模块: from bigml.api import BigML [as 别名]
# 或者: from bigml.api.BigML import create_model [as 别名]
def main(args=sys.argv[1:]):
"""Parses command-line parameters and calls the actual main function.
"""
parser = argparse.ArgumentParser(
description="Dataset analysis",
epilog="BigML, Inc")
# source with activity data
parser.add_argument('--source',
action='store',
dest='source',
default=None,
help="Full path to file")
# create private links or not
parser.add_argument('--share',
action='store_true',
default=False,
help="Share created resources or not")
# weight models or not
parser.add_argument('--balance',
action='store_true',
default=False,
help="Weight model or not")
args = parser.parse_args(args)
if not args.source:
sys.exit("You need to provide a valid path to a source")
api = BigML()
name = "Sean's activity"
log("Creating source...")
source_args = {'name': name}
source = api.create_source(args.source, source_args)
if not api.ok(source):
sys.exit("Source isn't ready...")
log("Creating dataset...")
dataset = api.create_dataset(source)
if not api.ok(dataset):
sys.exit("Dataset isn't ready...")
log("Transforming dataset...")
# Extends dataset with new field for previous activity, previous duration,
# start day, and start hour. Removes first column, start, and end fields.
new_dataset_args = {
'name': name,
'new_fields': new_fields(),
'all_but': excluded_fields()}
new_dataset = api.create_dataset(dataset, new_dataset_args)
if not api.ok(new_dataset):
sys.exit("Dataset isn't ready...")
# Set objective field to activity
fields = Fields(new_dataset['object']['fields'])
objective_id = fields.field_id('activity')
new_dataset_args = {
'objective_field': {'id': objective_id}}
new_dataset = api.update_dataset(new_dataset, new_dataset_args)
# Create training and test set for evaluation
log("Splitting dataset...")
training, test = train_test_split(api, new_dataset)
log("Creating a model using the training dataset...")
model_args = {
'objective_field': objective_id,
'balance_objective': args.balance,
'name': training['object']['name']}
model = api.create_model(training, model_args)
if not api.ok(model):
sys.exit("Model isn't ready...")
# Creating an evaluation
log("Evaluating model against the test dataset...")
eval_args = {
'name': name + ' - 80% vs 20%'}
evaluation = api.create_evaluation(model, test, eval_args)
if not api.ok(evaluation):
sys.exit("Evaluation isn't ready...")
log("Creating model for the full dataset...")
model = api.create_model(new_dataset, model_args)
if not api.ok(model):
sys.exit("Model isn't ready...")
# Create private links
if args.share:
log("Sharing resources...")
dataset_private_link = share_dataset(api, new_dataset)
model_private_link = share_model(api, model)
evaluation_private_link = share_evaluation(api, evaluation)
log(dataset_private_link)
log(model_private_link)
log(evaluation_private_link)
示例8: main
# 需要导入模块: from bigml.api import BigML [as 别名]
# 或者: from bigml.api.BigML import create_model [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)