Predictive Models: Build once, Run Anywhere

我们发布了开源的新版本Python bindings。这个新的version aims at showing how the BigML API can be used to build predictive models capable of generating predictions locally or remotely. You can get full access to the code atGithuband read the full documentation at阅读文档

更新的完整列表包括(请鼓卷,请):

Development Mode

We recently introduced afree sandbox帮助开发人员在较小的数据集上使用BIGML播放,而不必担心beplay2网页登陆信用。在新的Python绑定中,您可以在开发模式下使用BIGML,并且可以免费创建所beplay2网页登陆有小于1MB的数据集和模型:

from bigml.api import BigML api = BigML(dev_mode=True)

远程来源

You can now create new“远程”来源using URLs. For example, the following snippet would allow you to create a new source using loan funding data from Lending Club.

source = api.create_source(“ https://www.lendingclub.com/filedownload.action?file = infundingstats.csv&type = gen”)

The URLs to create remote sources can be http or https with basic realm authentication (e.g.,https://test:test@static.bigml.com/csv/iris.csv) or Amazon S3 buckets (e.g., s3://bigml-public/csv/iris.csv) or even Microsoft Azure blobs (e.g., azure://csv/iris.csv?AccountName=bigmlpublic)

Bigger files streamed with Poster

In the first version we were using the fabulouspython请求http库to fulfill all the HTTPS communications with BigML. However, we realized thatPoster更适合流式传输大型文件,这主要是因为它在发送之前不需要将整个文件加载到内存中。由于传输时间很长,我们还添加了一个文本进度栏,让您看到到目前为止上传了多少个字节。

新来源的进度栏

异步上传

上传大文件可能需要一段时间,具体取决于您的可用带宽。我们添加了一个async标志以实现异步创建新来源。

source = api.create_source(“ sales2012.csv”,async = true)

You can then monitor that source to check the progress. Once the upload is finished the variable will contain the BigML resource.

>>> source {'代码':202,'resource':none,'位置':none,'object':{'status':{'progress':0.48,'message':'上传中的上传','代码':6}},'错误':none}

Local Models

如果您导入新的Modelclass you will be able to create a local version of a BigML model that you can use to make predictions locally, generate an IF-THEN rule version of your model, or even a Python function that implements the model. This is as easy as:

从BigMbeplay2网页登陆l.API导入BigMl从BigMl.model导入模型API = BigMl(dev_mode = true)source = api.create_source('https:/https://static.bigml.com/csv/iribeplay体育官网网站s.csv/iris.csv'源)模型= api.create_model(数据集)模型= api.get_model(模型)local_model = model(model)

This code not only will generate a model like the one depicted below in your dashboard at BigML.com but also a local model that would be able to use to generate local predictions or to translate into a set of IF-THEN rules or even into Python code.

Local Predictions

使用本地模型进行预测具有很大的优势:它们不会花费任何东西。对于需要极端延迟或没有网络连接的情况,它们也是一个好主意。权衡是,您将失去BigML跟踪或改善模型性能的能力。beplay2网页登陆

>>>local_model.predict({"petal length": 3, "petal width": 1}) petal length > 2.45 AND petal width <= 1.65 AND petal length <= 4.95 => Iris-versicolor

Rule Generation

Many organizations use rule engines to implement certain business logic. IF-THEN rules are a great way of capturing a white-box predictive model, as they are a human-readable language common to any actor in the organization. That’s a big advantage when you need to share it with, let’s say, the marketing department to adapt their strategies or the CEO to approve it. You can easily get the rules that implement a BigML predictive model as follows:

>>> local_model.rules() IF petal length > 2.45 AND IF petal width > 1.65 AND IF petal length > 5.05 THEN species = Iris-virginica IF petal length <= 5.05 AND IF sepal width > 2.9 AND IF sepal length > 5.95 AND IF petal length > 4.95 THEN species = Iris-versicolor IF petal length <= 4.95 THEN species = Iris-virginica IF sepal length <= 5.95 THEN species = Iris-versicolor IF sepal width <= 2.9 THEN species = Iris-virginica IF petal width <= 1.65 AND IF petal length > 4.95 AND IF sepal length > 6.05 THEN species = Iris-virginica IF sepal length <= 6.05 AND IF sepal width > 2.45 THEN species = Iris-versicolor IF sepal width <= 2.45 THEN species = Iris-virginica IF petal length <= 4.95 THEN species = Iris-versicolor IF petal length <= 2.45 THEN species = Iris-setosa

Python代

Local models can also be used to generate a Python function that implements the predictive model as a sequence of IF statements. For example:

>>> local_model.python() def predict_species(sepal_length=5.77889, sepal_width=3.02044, petal_length=4.34142, petal_width=1.32848): if (petal_length > 2.45): if (petal_width > 1.65): if (petal_length > 5.05): return 'Iris-virginica' if (petal_length <= 5.05): if (sepal_width > 2.9): if (sepal_length > 5.95): if (petal_length > 4.95): return 'Iris-versicolor' if (petal_length <= 4.95): return 'Iris-virginica' if (sepal_length <= 5.95): return 'Iris-versicolor' if (sepal_width <= 2.9): return 'Iris-virginica' if (petal_width <= 1.65): if (petal_length > 4.95): if (sepal_length > 6.05): return 'Iris-virginica' if (sepal_length <= 6.05): if (sepal_width > 2.45): return 'Iris-versicolor' if (sepal_width <= 2.45): return 'Iris-virginica' if (petal_length <= 4.95): return 'Iris-versicolor' if (petal_length <= 2.45): return 'Iris-setosa'

因此,使用BigML API的这种新绑定,只有几行Python可以beplay2网页登陆上传大数据集,创建预测模型,然后自动生成Python代码,该代码将在您自己的应用程序中实现预测模型。多么酷啊?请记住,您可以从Githuband read the full documentation at阅读文档

4 comments

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account.(Log Out/Change)

Google照片

您正在使用Google帐户评论。(Log Out/Change)

推特picture

You are commenting using your Twitter account.(Log Out/Change)

Facebook photo

您正在使用您的Facebook帐户发表评论。(Log Out/Change)

Connecting to %s