Machine Learning Cheat Sheet Github



Supervised learning superstitions cheat sheet. This notebook contains my notes and beliefs about several commonly-used supervised learning algorithms. My dream is that it will be useful as a quick reference or for people who are studying for machine learning interviews/quizzes/etc. After some setup code, the methods discussed are: Logistic. Cheat Sheet Translator(s) Reviewer(s) Supervised Learning Yuta Tran Unsupervised Learning Tran, Wataru, Yoshiyuki, Yuta Wataru, Yoshiyuki, Yuta Algebra and Calculus Rob Kamuela Probabilities and Statistics Nao Yuta Convolutional Neural Nets Tran, Yoshiyuki Duy, Yoshiyuki, Wataru Recurrent Neural Nets Hideaki Yoshiyuki.

iOS Machine Learning Architecture & Tools

In this article, the most common tools for creating intelligent iOS applications will be presented. However, a separate article dedicated to each one of the tools is needed and will be posted as we progress with the Machine Learning fundamentals that every iOS developer needs to know series. Let’s begin the journey of exploring the Machine Learning world in iOS by getting to know a bit about the architecture and available tools.

In the picture, we can see a high-level architecture of how Machine Learning works natively in iOS apps. For us, as developers, interesting parts are only Core ML and everything above it + Create ML. With the knowledge of how to use these frameworks, iOS developers can implement extraordinary features. Add Turi Create and coremltools knowledge to the bag and you are quite dangerous in the iOS world of Machine Learning and Artificial Intelligence.

Core ML

Core ML framework is dedicated to accessing and running already pre-trained Machine Learning models in the iOS apps with Swift language. Core ML is also a basis for native domain-specific ML frameworks, like Visual, Natural Language, Speech and Sound Analysis. These frameworks run Machine Learning models under the hood and Core ML is at the center of this. A lot more about these frameworks are covered in the next article 2/5 Native domain-specific Machine Learning frameworks for iOS developers.

Besides using the previously mentioned domain-specific ML frameworks, by interacting directly with Core ML developers can run ML models (that can be downloaded here) directly in the iOS projects. Core ML provides a consistent API to interact with any compatible .mlmodel model. Here are the basic steps to make the Machine Learning model work with Core ML:

  • Drag & drop the ML model to the iOS project.
  • Initialize the model by its name let model = MyModel() (as you would initialize any class).
  • Provide input with a required format to the model.
  • Receive the output (prediction) from the model.

More information about how to use .mlmodel models with Core ML will be provided in the article dedicated just for the Core ML: 3/5 How to use a custom Core ML model in the iOS App

To sum up - Core ML enables at least two powerful ways of implementing Machine Learning powered features:

  1. Use and enrich the functionality of native domain-specific ML frameworks

  2. Run the custom ML models

Either using native domain-specific ML-powered frameworks or running the custom ML models cover most of the cases when the iOS developer needs to interact with ML. Most often this is all that is needed to implement that super awesome feature that boosts the intelligence of the iOS application. But what if the developer’s ambitions are much higher than that? What if the desired feature is so unique that no available Core ML models .mlmodel available on the internet fit?

Converting third-party Machine Learning models to Core ML format

You might end up finding a Machine Learning model that fits the requirements and does exactly what you need, but the problem is this model is not in .mlmodel format. Worry no more!

The coremltools is a suite of Python scripts that is capable of converting from the most popular Machine Learning models created with deep learning frameworks like TensorFlow, PyTorch, Keras, Caffe as well as classical machine learning frameworks like LIBSVM, scikit-learn, and XGBoost to the .mlmodel format. Converting the models is only one of the functionality that coremltools provide. The coremltools also contains supporting tools for editing and validation of the models.

We will go more in the depth on how to use coremltools to convert the third-party model to the .mlmodel format in the 5/5 How to run any Machine Learning model in the iOS App article. However, if you are in the urgent need to start using the coremltools ASAP - coremltools documentation is the place you want to hit first!

But what if requirements for implementing a Machine Learning powered feature cannot be met by leveraging any of the already available models found on the internet? Very likely that training a custom Machine Learning model by using the unique data reflecting your app’s users is what you need.

Creating and Training custom Machine Learning models for iOS applications

Dear iOS engineer, prepare to put the ML engineer’s hat on and step into the land of actual Machine Learning. With the Create ML or Turi Create tools the unique Machine Learning models can be created by training them with the data gathered from the users or obtained from other channels. Although this might feel like something new and uncomfortable at first - the moment a custom model trained by yourself returns intelligent results - the number of endorphins released by your brains will overcompensate all the previous hustle.

There are many very powerful and flexible frameworks for creating and training Machine Learning models. We will focus only on frameworks provided by Apple. There are two of them:

  1. Create ML

    Create ML comes as two separate components - a Create ML macOS App and a Create ML framework. Both of them have very similar functionality. The main difference is that the Create ML macOS App provides an easy to use graphical interface:

    When creating and training a model with the Create ML framework you rely on writing code. Almost all the same could be achieved no matter which way we go. Here are the features supported by Create ML as of the time of writing:

    • Images
      • Image classification
      • Object detection
      • Style transfer
    • Video
      • Action classification
      • Style transfer
    • Motion
      • Activity classification
    • Sound
      • Sound classification
    • Text
      • Text classification
      • Word tagging
    • Tabular
      • Tabular classification
      • Tabular regression
      • Recommendation

    Create ML is available only on the macOS, which means that models need to be created and trained on your machine and imported to the iOS project. Creating and training models from scratch in the iOS app is not possible as hardware is still not there. Hopefully, it will change soon. However, some specific kinds of models can be updated with on-device training, but it is not a straightforward process and this topic will be covered in future articles.

  2. Turi Create

    Initially, Turi Create was created by a startup called “Turi”. Apple acquired this startup in 2016 and open-sourced its software. Turi Create is a Python package. Yes, you heard it right - Python. But don’t get scared, it is easy to use and a very powerful tool. More accurate would be to call it not a tool, but a collection of task-based tools. Here are what tasks and features can be created with it:

    • Recommender Systems
    • Image Classification
    • Drawing Classification
    • Sound Classification
    • Image Similarity
    • Object Detection
    • One-Shot Object Detection
    • Style Transfer
    • Activity Classifier
    • Text Classifier

    Although much of the capabilities are very similar to what Create ML does - Turi Create is much more flexible. It is possible to select specific algorithms for each problem.

    Besides creating and training Machine Learning models and exporting them to the Core ML format, Create ML offers other very important features. You will be surprised, but when working on Machine Learning tasks, very often most of the time is spent on working with data, not creating and training the models. Turi Create provides tools for working with data and visualizing it which is super important.

    The more in-depth information and actual examples of using both Create ML and Turi Create tools will be covered in the 4/5 Training Machine Learning models for the iOS App with Create ML and Turi Create article.

(Bonus) iOS Machine Learning Tools Cheat-Sheet

There are quite some tools available for implementing cool Machine Learning powered features. Here I provide a cheat-sheet that I believe should help to select the tools in a way that is the simplest and most efficient for iOS developers comfortable with Swift language and the Apple development world.

I’d love to hear your opinion about it. Feel free to open the discussion in the comments and share what you think!

Concepts#

AzureML provides two basic assets for working with data:

  • Datastore
  • Dataset

Datastore#

Provides an interface for numerous Azure Machine Learning storage accounts.

Each Azure ML workspace comes with a default datastore:

ws = Workspace.from_config()

which can also be accessed directly from the Azure Portal (under the sameresource group as your Azure ML Workspace).

Datastores are attached to workspaces and are used to store connection information to Azure storage services so you can refer to them by name and don't need to remember the connection information and secret used to connect to the storage services.

Use this class to perform management operations, including register, list, get, and remove datastores.

Dataset#

A dataset is a reference to data - either in a datastore or behind a public URL.

Datasets provide enhaced capabilities including data lineage (with the notion of versioned datasets).

Get Datastore#

Default datastore#

Each workspace comes with a default datastore.

Register datastore#

Connect to, or create, a datastore backed by one of the multipleabove for more details.

Read from Datastore#

Reference data in a Datastore in your code, for example to use in a remote setting.

DataReference#

First, connect to your basic assets: Workspace, ComputeTarget and Datastore.

ws: Workspace = Workspace.from_config()
compute_target: ComputeTarget = ws.compute_targets['<compute-target-name>']

Create a DataReference, either as mount:

Sheet
data_ref = ds.path('<path/on/datastore>').as_mount()

or as download:

data_ref = ds.path('<path/on/datastore>').as_download()

To mount a datastore the workspace need to have read and write access to the underlying storage. For readonly datastore as_download is the only option.

Consume DataReference in ScriptRunConfig#

Add this DataReference to a ScriptRunConfig as follows.

source_directory='.',
arguments=[str(data_ref)],# returns environment variable $AZUREML_DATAREFERENCE_example_data
)
config.run_config.data_references[data_ref.data_reference_name]= data_ref.to_config()

The command-line argument str(data_ref) returns the environment variable $AZUREML_DATAREFERENCE_example_data.Finally, data_ref.to_config() instructs the run to mount the data to the compute target and to assign theabove environment variable appropriately.

Without specifying argument#

Specify a path_on_compute to reference your data without the need for command-line arguments.

data_ref = ds.path('<path/on/datastore>').as_mount()
source_directory='.',
Learning

Machine Learning Cheat Sheet Github Answers

compute_target=compute_target,
config.run_config.data_references[data_ref.data_reference_name]= data_ref.to_config()

Create Dataset#

From local data#

Upload to datastore#

To upload a local directory ./data/:

datastore.upload(src_dir='./data', target_path='<path/on/datastore>', overwrite=True)

This will upload the entire directory ./data from local to the default datastore associatedto your workspace ws.

Create dataset from files in datastore#

To create a dataset from a directory on a datastore at <path/on/datastore>:

dataset = Dataset.File.from_files(path=(datastore,'<path/on/datastore>'))

Github Commands Cheat Sheet

Use Dataset#

ScriptRunConfig#

To reference data from a dataset in a ScriptRunConfig you can either mount or download thedataset using:

Machine Learning Cheat Sheet Github Download

  • dataset.as_mount(path_on_compute) : mount dataset to a remote run
  • dataset.as_download(path_on_compute) : download the dataset to a remote run

Path on compute Both as_mount and as_download accept an (optional) parameter path_on_compute.This defines the path on the compute target where the data is made available.

  • If None, the data will be downloaded into a temporary directory.
  • If path_on_compute starts with a / it will be treated as an absolute path. (If you havespecified an absolute path, please make sure that the job has permission to write to that directory.)
  • Otherwise it will be treated as relative to the working directory

Reference this data in a remote run, for example in mount-mode:

Machine Learning Github

config = ScriptRunConfig(source_directory='.', script='train.py', arguments=arguments)

and consumed in train.py:

data_dir = sys.argv[1]
print(' DATA ')

Hands On Machine Learning Github

print('LIST FILES IN DATA DIR...')

Machine Learning Cheat Sheet Pdf Github

print(')

For more details: ScriptRunConfig