{"id":27431001,"url":"https://github.com/bigmlcom/bigml-swift","last_synced_at":"2025-07-25T15:09:36.790Z","repository":{"id":140668761,"uuid":"50190628","full_name":"bigmlcom/bigml-swift","owner":"bigmlcom","description":"BigML REST API Bindings for Swift","archived":false,"fork":false,"pushed_at":"2018-03-09T18:37:17.000Z","size":384,"stargazers_count":3,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T15:51:37.665Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bigmlcom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-01-22T15:48:08.000Z","updated_at":"2023-04-26T22:24:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"8f30f3da-737f-4063-aba1-ec7613ff3e6e","html_url":"https://github.com/bigmlcom/bigml-swift","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bigmlcom/bigml-swift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigmlcom%2Fbigml-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigmlcom%2Fbigml-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigmlcom%2Fbigml-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigmlcom%2Fbigml-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bigmlcom","download_url":"https://codeload.github.com/bigmlcom/bigml-swift/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigmlcom%2Fbigml-swift/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267023219,"owners_count":24022915,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-14T15:28:17.460Z","updated_at":"2025-07-25T15:09:36.785Z","avatar_url":"https://github.com/bigmlcom.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"BigML Swift Bindings\n=====================\n\nIn this repository you'll find an open source Swift library that\ngives you a simple binding to interact with `BigML \u003chttps://bigml.com\u003e`.\n\nBigML makes machine learning easy by taking care of the details\nrequired to add data-driven decisions and predictive power to your\ncompany. Unlike other machine learning services, BigML creates\n[beautiful predictive models](https://bigml.com/gallery/models) that\ncan be easily understood and interacted with.\n\nThe BigML @(language) bindings allow you to interact with `BigML.io \u003chttps://bigml.io/\u003e`, the API for BigML. You can use it to easily\ncreate, retrieve, list, update, and delete BigML resources (i.e.,\nsources, datasets, models and, predictions, and `many more \u003chttps://bigml.com/developers/\u003e`). Additionally, they also provide a\nfew ML algorithms that can be run locally, i.e. offline, such as to\nmake a prediction from a model, calculate an anomaly score, etc.\n\nThis module is licensed under the [Apache License, Version\n2.0](http://www.apache.org/licenses/LICENSE-2.0.html).\n\n\nSupport\n-------\n\nPlease report problems and bugs to our [BigML.io issue\ntracker](https://github.com/bigmlcom/io/issues).\n\nDiscussions about the different bindings take place in the general\n[BigML mailing list](http://groups.google.com/group/bigml).\n\nRequirements\n------------\n\n`bigml-swift` is compatible with Swift 2.0 and requires Xcode 7.0+.\n\n\nImporting the module\n--------------------\n\nTo use BigML Swift SDK you can drag the `bigml-swift` folder on to\nyour Xcode project.\n\nThen, when you need to call a method from `bigml-swift` inside a file\nof yours, put the following directive on top of it:\n\n    @import bigmlSwift\n\n\nAuthentication\n--------------\n\nAll the requests to BigML.io must be authenticated using your username\nand [API key](https://bigml.com/account/apikey) and are always\ntransmitted over HTTPS.\n\nKnowing that, connecting to BigML is a breeze. You just need to\nexecute:\n\n```\nlet api = BMLConnector(username:\"your-username-here\",\n    apiKey:\"your-api-key-here\")\n```\n\n\nQuick Start\n-----------\n\nImagine that you want to use [this csv\nfile](https://static.bigml.com/csv/iris.csv) containing the [Iris\nflower dataset](http://en.wikipedia.org/wiki/Iris_flower_data_set)_ to\npredict the species of a flower whose ``sepal length`` is ``5`` and\nwhose ``sepal width`` is ``2.5``. A preview of the dataset is shown\nbelow. It has 4 numeric fields: ``sepal length``, ``sepal width``,\n``petal length``, ``petal width`` and a categorical field: ``species``.\nBy default, BigML considers the last field in the dataset as the\nobjective field (i.e., the field that you want to generate predictions\nfor).\n\n\n    sepal length,sepal width,petal length,petal width,species\n    5.1,3.5,1.4,0.2,Iris-setosa\n    4.9,3.0,1.4,0.2,Iris-setosa\n    4.7,3.2,1.3,0.2,Iris-setosa\n    ...\n    5.8,2.7,3.9,1.2,Iris-versicolor\n    6.0,2.7,5.1,1.6,Iris-versicolor\n    5.4,3.0,4.5,1.5,Iris-versicolor\n    ...\n    6.8,3.0,5.5,2.1,Iris-virginica\n    5.7,2.5,5.0,2.0,Iris-virginica\n    5.8,2.8,5.1,2.4,Iris-virginica\n\nYou can easily generate a prediction following these steps::\n\n```\nlet api = BMLConnector(username:\"your-username-here\",\n    apiKey:\"your-api-key-here\")\n\nlet source = BMLMinimalResource(name:\"My Data source\",\n    type:BMLResourceType.File,\n    uuid:\"./tests/data/iris.csv\")\n\n// All requests are asynchronous and have a completion block\napi!.createResource(BMLResourceType.Source,\n     name: \"testCreateDatasource\",\n     from: source) { (resource, error) -\u003e Void in\n\n         let myDatasource = resource!\n         api!.createResource(BMLResourceType.Dataset,\n           name: \"My first dataset\",\n           from: myDatasource) { (resource, error) -\u003e Void in\n\n              let myModel = resource!\n              api!.createResource(BMLResourceType.Model,\n                name: \"My first model\",\n                from: myModel) { (resource, error) -\u003e Void in\n\n                   let pModel = Model(jsonModel: resource!.jsonDefinition)\n                   let prediction = pModel.predict([\n                        \"sepal width\": 3.15,\n                        \"petal length\": 4.07,\n                        \"petal width\": 1.51],\n                     options: [\"byName\" : true])\n\n                   print(\"Final Prediction: \\(prediction)\")\n                }\n           }\n     }\n}\n```\n\n\nDataset\n-------\n\nIf you want to get some basic statistics for each field you can\nretrieve the fields from the dataset as follows to get a dictionary\nkeyed by field id:\n\n\n    api.getResource(BMLResourceType.Dataset,\n       uuid: datasetUuid) { (resource, error) -\u003e Void in\n          print_r(resource!.jsonDefinition[\"fields\"])\n    }\n\n\n\nThe field filtering options are also available using a query string\nexpression, for instance:\n\n\n    api.listResources(BMLResourceType.Dataset,\n       filters: [\"limit\" : \"5\"]) {  (resource, error) -\u003e Void in\n          //-- process resource\n    }\n\n\n\nlimits the number of fields that will be included in dataset to 20.\n\nModel\n-----\n\nOne of the greatest things about BigML is that the models that it\ngenerates for you are fully white-boxed.  To get the explicit\ntree-like predictive model for the example above:\n\n\n    api.getResource(BMLResourceType.Model,\n       uuid: modelUuid) { (resource, error) -\u003e Void in\n          //-- process resource\n    }\n\n\n\nAgain, filtering options are also available using a query string\nexpression, for instance:\n\n\n    api.listResources(BMLResourceType.Model,\n       filters: [\"limit\" : \"5\"]) {  (resource, error) -\u003e Void in\n          //-- process resource\n    }\n\n\n\nlimits the number of fields that will be included in model to 5.\n\nProjects\n---------\n\nA special kind of resource is ``project``. Projects are repositories\nfor resources, intended to fulfill organizational purposes. Each project can\ncontain any other kind of resource, but the project that a certain resource\nbelongs to is determined by the one used in the ``source``\nthey are generated from. Thus, when a source is created\nand assigned a certain ``project_id``, the rest of resources generated from\nthis source will remain in this project.\n\nThe REST calls to manage the ``project`` resemble the ones used to manage the\nrest of resources. When you create a ``project``:\n\n```\napi!.createResource(BMLResourceType.Project,\n     name: \"my first project\") { (resource, error) -\u003e Void in\n        //-- process resource\n}\n```\n\nthe resulting resource is similar to the rest of resources, although shorter::\n\n    {'code': 201,\n     'resource': 'project/54a1bd0958a27e3c4c0002f0',\n     'location': 'http://bigml.io/andromeda/project/54a1bd0958a27e3c4c0002f0',\n     'object': {'category': 0,\n                'updated': '2014-12-29T20:43:53.060045',\n                'resource': 'project/54a1bd0958a27e3c4c0002f0',\n                'name': 'my first project',\n                'created': '2014-12-29T20:43:53.060013',\n                'tags': [],\n                'private': True,\n                'dev': None,\n                'description': ''},\n     'error': None}\n\nand you can use its project id to get, update or delete it:\n\n\n**Important**: Deleting a non-empty project will also delete **all resources**\nassigned to it, so please be extra-careful when doing it.\n\nCreating sources\n----------------\n\nTo create a source from a local data file, you can use the create_source method. The only required parameter is the path to the data file (or file-like object). You can use a second optional parameter to specify any of the options for source creation described in the [BigML API documentation](https://bigml.com/developers).\n\nHere’s a sample invocation::\n\n```\nlet source = BMLMinimalResource(name:\"My Data source\",\n    type:BMLResourceType.File,\n    uuid:\"./tests/data/iris.csv\")\n\napi!.createResource(BMLResourceType.Source,\n     name: \"testCreateDatasource\",\n     options: [\"source_parser\" : [\"header\" : false, \"missing_tokens\" : [\"x\"]]]\n     from: source) { (resource, error) -\u003e Void in\n        //-- process resource\n     }\n```\n\n\nor you may want to create a source from a file in a remote location::\n\n```\napi!.createResource(BMLResourceType.Source,\n     name: \"testCreateDatasource\",\n     options: [\"remote\" : \"s3://bigml-public/csv/iris.csv\"]) {\n     (resource, error) -\u003e Void in\n        //-- process resource\n     }\n```\n\n\nCreating datasets\n-----------------\n\nOnce you have created a source, you can create a dataset. The only\nrequired argument to create a dataset is a source id.  You can add any\nof the optional arguments accepted by BigML and documented in `the\nDatasets section of the Developer’s documentation\n\u003chttps://bigml.com/developers/datasets\u003e`.\n\nFor example, to create a dataset named “my dataset” with the first\n1024 bytes of a source, you can execute the following call:\n\n```\napi!.createResource(BMLResourceType.Dataset,\n     name: \"testCreateDataset\",\n     options: [\"size\" : 1024]\n     from: source) { (resource, error) -\u003e Void in\n        //-- process resource\n     }\n```\n\n\nYou can also extract samples from an existing dataset and generate a\nnew one with them with the following call:\n\n```\napi!.createResource(BMLResourceType.Dataset,\n     name: \"testCloneDataset\",\n     options: [\"sample_rate\" : 0.8],\n     from: originDataset) { (resource, error) -\u003e Void in\n        //-- process resource\n     }\n```\n\n\n\nCreating models\n---------------\n\nOnce you have created a dataset you can create a model from it.  If\nyou don’t select one, the model will use the last field of the dataset\nas objective field.  The only required argument to create a model is a\ndataset id.  You can also include in the request all the additional\narguments accepted by BigML and documented in [the Models section of\nthe Developer’s documentation](https://bigml.com/developers/models).\n\nFor example, to create a model only including the first two fields and the first 10 instances in the dataset, you can use the following invocation::\n\n```\napi!.createResource(BMLResourceType.Model,\n     name: \"testCreateModel\",\n     options: [\"name\" : \"my model\",\n         \"input_fields\" : [\"000000\", \"000001\"],\n         \"range\" : [1, 10]],\n     from: dataset) { (resource, error) -\u003e Void in\n              //-- process resource\n}\n```\n\n\nthe model is scheduled for creation.\n\nCreating clusters\n-----------------\n\nIf your dataset has no fields showing the objective information to\npredict for the training data, you can still build a cluster that will\ngroup similar data around some automatically chosen points\n(centroids).  Again, the only required argument to create a cluster is\nthe dataset id.  You can also include in the request all the\nadditional arguments accepted by BigML and documented in `the Clusters\nsection of the Developer’s documentation\n\u003chttps://bigml.com/developers/clusters\u003e`.\n\nLet’s create a cluster from a given dataset:\n\n```\napi!.createResource(BMLResourceType.Cluster,\n     name: \"testCreateCluster\",\n     options: [\"k\" : 5],\n     from: dataset) { (resource, error) -\u003e Void in\n              //-- process resource\n}\n```\n\n\nthat will create a cluster with 5 centroids.\n\nCreating anomaly detectors\n--------------------------\n\nIf your problem is finding the anomalous data in your dataset, you can\nbuild an anomaly detector, that will use iforest to single out the\nanomalous records. Again, the only required argument to create an\nanomaly detector is the dataset id. You can also include in the\nrequest all the additional arguments accepted by BigML and documented\nin the `Anomaly detectors section of the Developer’s documentation\n\u003chttps://bigml.com/developers/anomalies\u003e`_.\n\nLet’s create an anomaly detector from a given dataset:\n\n```\napi!.createResource(BMLResourceType.Anomaly,\n     name: \"testCreateAnomaly\",\n     from: dataset) { (resource, error) -\u003e Void in\n              //-- process resource\n}\n```\n\n\nCreating associations\n---------------------\n\nTo find relations between the field values you can create an association\ndiscovery resource. The only required argument to create an association\nis a dataset id.\nYou can also\ninclude in the request all the additional arguments accepted by BigML\nand documented in the [Association section of the Developer's\ndocumentation](https://bigml.com/developers/associations)_.\n\nFor example, to create an association only including the first two fields and\nthe first 10 instances in the dataset, you can use the following\ninvocation:\n\n```\napi!.createResource(BMLResourceType.Association,\n     name: \"testCreateAssociation\",\n     options: [\"input_fields\" : [\"000000\", \"000001\"],\n               \"range\" : [1, 10]],\n     from: dataset) { (resource, error) -\u003e Void in\n              //-- process resource\n}\n```\n\n\nAssociations can also be created from lists of datasets. Just use the\nlist of ids as the first argument in the api call:\n\n```\napi!.createResource(BMLResourceType.Association,\n     name: \"testCreateAssociation\",\n     options: [\"input_fields\" : [\"000000\", \"000001\"],\n               \"range\" : [1, 10]],\n     from: dataset) { (resource, error) -\u003e Void in\n              //-- process resource\n}\n```\n\n\nCreating predictions\n--------------------\n\nYou can now use the model resource identifier together with some input parameters to ask for predictions, using the create_prediction method.\nYou can also give the prediction a name:\n\n```\napi!.createResource(BMLResourceType.Prediction,\n     name: \"testCreatePrediction\",\n     options: [\"input_data\" : [\"sepal length\" : 5,\n               \"sepal width\" : 2.5]],\n     from: model) { (resource, error) -\u003e Void in\n              //-- process resource\n}\n```\n\nCreating centroids\n------------------\n\nTo obtain the centroid associated to new input data, you can now use\nthe create_centroid method.  Give the method a cluster identifier and\nthe input data to obtain the centroid.  You can also give the centroid\npredicition a name:\n\n```\napi!.createResource(BMLResourceType.Centroid,\n     name: \"testCreatePrediction\",\n     options: [ \"input_data\" : [\"pregnancies\" : 0,\n                                            \"plasma glucose\" : 118,\n                                            \"blood pressure\" : 84,\n                                            \"triceps skin thickness\" : 47,\n                                            \"insulin\" : 230,\n                                            \"bmi\" : 45.8,\n                                            \"diabetes pedigree\" : 0.551,\n                                            \"age\" : 31,\n                                            \"diabetes\" : \"true\"]],\n     from: cluster) { (resource, error) -\u003e Void in\n              //-- process resource\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigmlcom%2Fbigml-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbigmlcom%2Fbigml-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigmlcom%2Fbigml-swift/lists"}