1624261538

In this video, we are going to learn a very important concept to write efficient programs, which is Profiling. I will explain the basics concepts and the options available in Python along with the practical code examples.

And, In short, we will discuss the following things in this python tutorial:

- cpython
- python optimizations

Subscribe: https://www.youtube.com/c/Pythonist/featured

#python

1619518440

Welcome to my Blog , In this article, you are going to learn the top 10 python tips and tricks.

…

#python #python hacks tricks #python learning tips #python programming tricks #python tips #python tips and tricks #python tips and tricks advanced #python tips and tricks for beginners #python tips tricks and techniques #python tutorial #tips and tricks in python #tips to learn python #top 30 python tips and tricks for beginners

1603753200

So far in our journey through the Machine Learning universe, we covered several big topics. We investigated some **regression** algorithms, **classification** algorithms and algorithms that can be used for both types of problems (**SVM****, ****Decision Trees** and Random Forest). Apart from that, we dipped our toes in unsupervised learning, saw how we can use this type of learning for **clustering** and learned about several clustering techniques.

We also talked about how to quantify machine learning model **performance** and how to improve it with **regularization**. In all these articles, we used Python for “from the scratch” implementations and libraries like **TensorFlow**, **Pytorch** and SciKit Learn. The word optimization popped out more than once in these articles, so in this and next article, we focus on optimization techniques which are an important part of the machine learning process.

In general, every machine learning algorithm is composed of three integral parts:

- A
**loss**function. - Optimization criteria based on the loss function, like a
**cost**function. **Optimization**technique – this process leverages training data to find a solution for optimization criteria (cost function).

As you were able to see in previous articles, some algorithms were created intuitively and didn’t have optimization criteria in mind. In fact, mathematical **explanations** of why and how these algorithms work were done later. Some of these algorithms are **Decision Trees** and **kNN**. Other algorithms, which were developed later had this thing in mind beforehand. **SVM**is one example.

During the training, we change the parameters of our machine learning model to try and **minimize** the loss function. However, the question of how do you change those parameters arises. Also, by how much should we change them during training and when. To answer all these questions we use **optimizers**. They put all different parts of the machine learning algorithm together. So far we mentioned **Gradient Decent** as an optimization technique, but we haven’t explored it in more detail. In this article, we focus on that and we cover the **grandfather** of all optimization techniques and its variation. Note that these techniques are **not** machine learning algorithms. They are solvers of **minimization** problems in which the function to minimize has a gradient in most points of its domain.

Data that we use in this article is the famous *Boston Housing Dataset* . This dataset is composed 14 features and contains information collected by the U.S Census Service concerning housing in the area of Boston Mass. It is a small **dataset** with only 506 samples.

For the purpose of this article, make sure that you have installed the following _Python _libraries:

- **NumPy **– Follow
**this guide**if you need help with installation. - **SciKit Learn **– Follow
**this guide**if you need help with installation. **Pandas**– Follow**this guide**if you need help with installation.

Once installed make sure that you have imported all the necessary modules that are used in this tutorial.

```
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import SGDRegressor
```

Apart from that, it would be good to be at least familiar with the basics of **linear algebra**, **calculus** and **probability**.

Note that we also use simple **Linear Regression** in all examples. Due to the fact that we explore **optimization**techniques, we picked the easiest machine learning algorithm. You can see more details about Linear regression **here**. As a quick reminder the formula for linear regression goes like this:

where *w* and *b* are parameters of the machine learning algorithm. The entire point of the training process is to set the correct values to the *w* and *b*, so we get the desired output from the machine learning model. This means that we are trying to make the value of our **error vector** as small as possible, i.e. to find a **global minimum of the cost function**.

One way of solving this problem is to use calculus. We could compute derivatives and then use them to find places where is an extrema of the cost function. However, the cost function is not a function of one or a few variables; it is a function of all parameters of a machine learning algorithm, so these calculations will quickly grow into a monster. That is why we use these optimizers.

#ai #machine learning #python #artificaial inteligance #artificial intelligence #batch gradient descent #data science #datascience #deep learning #from scratch #gradient descent #machine learning #machine learning optimizers #ml optimization #optimizers #scikit learn #software #software craft #software craftsmanship #software development #stochastic gradient descent

1625843760

When installing Machine Learning Services in SQL Server by default few Python Packages are installed. In this article, we will have a look on how to get those installed python package information.

When we choose Python as Machine Learning Service during installation, the following packages are installed in SQL Server,

**revoscalepy**– This Microsoft Python package is used for remote compute contexts, streaming, parallel execution of rx functions for data import and transformation, modeling, visualization, and analysis.**microsoftml**– This is another Microsoft Python package which adds machine learning algorithms in Python.**Anaconda 4.2**– Anaconda is an opensource Python package

#machine learning #sql server #executing python in sql server #machine learning using python #machine learning with sql server #ml in sql server using python #python in sql server ml #python packages #python packages for machine learning services #sql server machine learning services

1619510796

Welcome to my Blog, In this article, we will learn python lambda function, Map function, and filter function.

**Lambda function in python**: Lambda is a one line anonymous function and lambda takes any number of arguments but can only have one expression and python lambda syntax is

**Syntax: x = lambda arguments : expression**

Now i will show you some python lambda function examples:

#python #anonymous function python #filter function in python #lambda #lambda python 3 #map python #python filter #python filter lambda #python lambda #python lambda examples #python map

1623814980

Nobody writes the best code in the first instance of building logic. Especially in the startup environment, implementing the functionality is what we call coding. We don’t get much time to follow any standards of coding. All we do is write functions or classes and giving whatever names we feel apt for those.

Maintaining coding standards can be time-consuming at times, but the least we can do is making sure our code is efficient — not taking much time or memory for execution. As we have good compute power most of the time, we neglect this part unless we get OOM errors or have to wait minutes for getting the output.

Do you really need optimization?

Every code needs optimization and any functionality should be implemented in the optimal way possible *-Ideally.* Time and memory both are linked to money. So if your code takes more time or more memory, it is taking extra money out of your pocket. But we don’t bother about that much as most of our code serves a limited purpose and the money factor doesn’t come into picture.

I am a data scientist and I write code almost every day. For most of the part, I don’t worry about optimization while writing the code. I will analyze my code once I finished the implementation using the profiler and decide whether it needs optimization or not.

If a particular block of my code takes most of the time, then I will try to optimize that block. But if the time taken is spread across the whole code, I don’t bother improving it further.

How do we know which parts of the code needs optimization?

That’s where profiling comes into play. There are many profilers available for both time and memory. We will save memory profiling for some other day. Let’s concentrate on time profiling for now. cProfile is one of the ways of time profiling. Let’s work through an example.

#programming #profiling #cprofile #python #optimization #profiling and optimizing your python code