# AI News, DevOps Pipeline for a Machine Learning Project

## DevOps Pipeline for a Machine Learning Project

A one-time activity is needed to dig into a data set, clean it, process it, optimize hyperparameters, call .fit() method, and present the results.

There are two different types of applications: Machine learning often expands functionality of existing applications — recommendations on a web shop, utterances classification in a chat bot, etc.

It means it will be part of the bigger cycle of adding new features, fixing bugs, or other reasons for frequent changes in overall code.

The main one was intent recognition where we decided to use our own instead of online services (such as wit.ai, luis.ai, api.ai) because we were using a person’s role, location, and more as additional features.

The standard application that manages this fast-moving environment is managed through the pipeline of version control, test, build, and deployment tools (CI/CD cycle).

from a software engineer submitting the code into central version control (for example github.com), through building and testing till deployment to the production environment.

We have started training data sets for our bot with a small labeled set and used selected utterances from this data set as testing scenarios.

As it grew, we moved it into a separate storage account and used a set of python scripts to clean it and split it into a train file and a test file.

Pros:• Easy fit to existing process• Full visibility of changes either in code or in data Cons:• Slow process• A lot of “failing builds” for no apparent reason or change in code• Complex management of training and testing data sets Pros:• Clear separation of responsibilities• Ability to use different languages / frameworks for each part (in our case python for machine learning and javascript for bot) Cons:• Risk of premature definition of services Our experience shows that there is no one-size-fits-all approach to combining traditional software engineering and machine learning in one project.

## When to change dev/test sets and metrics

You will learn how to build a successful machine learning project.

If you aspire to be a technical leader in AI, and know how to set direction for your team&#x27;s work, this course will show you how. Much

of this content has never been taught elsewhere, and is drawn from my experience building and shipping many deep learning products.

Understand complex ML settings, such as mismatched training/test sets, and comparing to and/or surpassing human-level performance -

## Learning Curves for Machine Learning

Diagnose Bias and Variance to Reduce Error When building machine learning models, we want to keep error as low as possible.

We'll work with a real world data set and try to predict the electrical energy output of a power plant.

If you're new to machine learning and have never tried scikit, a good place to start is this blog post.

In supervised learning, we assume there's a real relationship between feature(s) and target and estimate this unknown relationship with a model.

Provided the assumption is true, there really is a model, which we'll call $$f$$, which describes perfectly the relationship between features and target.

In practice, $$f$$ is almost always completely unknown, and we try to estimate it with a model $$\hat{f}$$ (notice the slight difference in notation between $$f$$ and $$\hat{f}$$).

If $$\hat{f}$$ doesn't change too much as we change training sets, the variance is low, which proves our point: the greater the bias, the lower the variance.

In most cases, a simple model performs poorly on training data, and it's extremely likely to repeat the poor performance on test data.

The error on the training instance will be 0, since it's quite easy to perfectly fit a single data point.

That's because the model is built around a single instance, and it almost certainly won't be able to generalize accurately on data that hasn't seen before.

In a nutshell, a learning curve shows how error changes as the training set size increases.

In the first row, where n = 1 (n is the number of training instances), the model fits perfectly that single training data point.

We'll try to build regression models that predict the hourly electrical energy output of a power plant.

As the data is stored in a .xlsx file, we use pandas' read_excel() function to read it in: Let's quickly decipher each column name: The PE column is the target variable, and it describes the net hourly electrical energy output.

All the other variables are potential features, and the values for each are actually hourly averages (not net values, like for PE).

According to the documentation of the data set, the vacuum level has an effect on steam turbines, while the other three variables affect the gas turbines.

At this step we'd normally put aside a test set, explore the training data thoroughly, remove any outliers, measure correlations, etc.

We'll do that using an 80:20 ratio, ending up with a training set of 7654 instances (80%), and a validation set of 1914 instances (20%).

For our case, here, we use these six sizes: An important thing to be aware of is that for each specified size a new model is trained.

If you're using cross-validation, which we'll do in this post, k models will be trained for each training size (where k is given by the number of folds used for cross-validation).

Let's inspect the other two variables to see what learning_curve() returned: Since we specified six training set sizes, you might have expected six values for each kind of score.

This happens because learning_curve() runs a k-fold cross-validation under the hood, where the value of k is given by what we specify for the cv parameter.

Below is a table for the training error scores to help you understand the process better: To plot the learning curves, we need only a single error score per training set size, not 5.

For this reason, in the next code cell we take the mean value of each row and also flip the signs of the error scores (as discussed above).

Such a high value is expected, since it's extremely unlikely that a model trained on a single data point can generalize accurately to 1914 new instances it hasn't seen in training.

When the training set size increases to 100, the training MSE increases sharply, while the validation MSE decreases likewise.

The linear regression model doesn't predict all 100 training points perfectly, so the training MSE is greater than 0.

This tells us something extremely important: adding more training data points won't lead to significantly better models.

So instead of wasting time (and possibly money) with collecting more data, we need to try something else, like switching to an algorithm that can build more complex models.

To avoid a misconception here, it's important to notice that what really won't help is adding more instances (rows) to the training data.

If the model fails to fit the training data well, it means it has high bias with respect to that set of data.

When such a model is tested on its training set, and then on a validation set, the training error will be low and the validation error will generally be high.

As we change training set sizes, this pattern continues, and the differences between training and validation errors will determine that gap between the two learning curves.

gap = validation\ error - training\ error \) So the bigger the difference between the two errors, the bigger the gap.

If the variance of a learning algorithm is low, then the algorithm will come up with simplistic and similar models as we change the training sets.

Generally, these other two fixes also work when dealing with a high bias and low variance problem: Let's see how an unregularized Random Forest regressor fares here.

One more important observation we can make here is that adding new training instances is very likely to lead to better models.

It still has potential to decrease and converge toward the training curve, similar to the convergence we see in the linear regression case.

So far, we can conclude that: At this point, here are a couple of things we could do to improve our model: In our case, we don't have any other readily available data.

Some steps you can take toward this goal include: Learning curves constitute a great tool to do a quick check on our models at every point in our machine learning workflow.

Provided the assumption is true, there is a true model $$f$$ that describes perfectly the relationship between $$X$$ and $$Y$$, like so: $$Y = f(X) + irreducible\ error \ \ \ \ \ \ \ \ \ \ \ \ \ \ (1)$$ But why is there an error?!

f(X) = \hat{f}(X) + reducible\ error \ \ \ \ \ \ \ \ \ \ \ \ \ \ (2)\) Replacing $$f(X)$$ in $$(1)$$ we get: $$Y = \hat{f}(X) + reducible\ error + irreducible\ error \ \ \ \ \ \ \ \ \ \ \ \ \ \ (3)$$ Error that is reducible can be reduced by building better models.

This tells us that that in practice the best possible learning curves we can see are those which converge to the value of some irreducible error, not toward some ideal error value (for MSE, the ideal error score is 0;

Expressing the same thing in the more precise language of mathematics, there's no function $$g$$ to map $$X$$ to the true value of the irreducible error: $$irreducible\ error \neq g(X)$$ So there's no way to know the true value of the irreducible error based on the data we have.

In practice, a good workaround is to try to lower the error score as much as possible, while keeping in mind that the limit is given by some irreducible error.

The main difference is that we'll have to choose another error metric - one that is suitable for evaluating the performance of a classifier.

For error metrics that describe how bad a model is, the irreducible error gives a lower bound: you cannot get lower than that.

As a side note here, in more technical writings the term Bayes error rate is what's usually used to refer to the best possible error score of a classifier.

How to Prepare Data for Machine Learning and A.I.

In this video, Alina discusses how to Prepare data for Machine Learning and AI. Artificial Intelligence is only powerful as the quality of the data collection, so it's ...

Training and testing

This video is part of the Udacity course "Machine Learning for Trading". Watch the full course at

When to Change Dev/Test Sets (C3W1L07)

R tutorial: Cross-validation

Learn more about machine learning with R: In the last video, we manually split our data into a ..

How Machines Learn

How do all the algorithms around us learn to do their jobs? Bot Wallpapers on Patreon: Discuss this video: ..

Regression Training and Testing - Practical Machine Learning Tutorial with Python p.4

Welcome to part four of the Machine Learning with Python tutorial series. In the previous tutorials, we got our initial data, we transformed and manipulated it a bit ...

Training/Testing on our Data - Deep Learning with Neural Networks and TensorFlow part 7

Welcome to part seven of the Deep Learning with Neural Networks and TensorFlow tutorials. We've been working on attempting to apply our recently-learned ...

Validation and Test Set Size

This video is part of the Udacity course "Deep Learning". Watch the full course at

How to do the Titanic Kaggle competition in R - Part 1

As part of submitting to Data Science Dojo's Kaggle competition you need to create a model out of the titanic data set. We will show you how to do this using ...

train and test data

this video was done in hurry, i might made some mistakes.. Train and test... back propagation neural network.. in this demo i put layer 3.. and layer 1 and 2 i put ...