Skip to main content

Posts

Showing posts with the label Python

Machine Learning Loss Functions in Practice

  Error/Loss functions are used to estimate the loss of a model so that the weights can be updated to reduce the error rate on the next iteration.  As you have clicked in this article, I am assuming you know the fundamental stuffs of machine learning pipelines and you want to know about loss functions specifically. So, let's jump directly to loss functions. I will also show you how you can use these loss functions in Scikit-learn/Pytorch. Broadly, we can categorize loss functions in two categories.  Loss functions for Regression problems. Loss functions for Classification problems. Regression problems The two most common loss functions for regression problems are: MSE( Mean Squared Error)  MAE (Mean Absolute Error)  MSE / Quadratic Loss / L2 Loss   If the target values falls into Gaussian/ Normal distribution, then it is the preferred loss function for regression problems. MSE is the sum of squared distances between target variables (ground truth) and predi...

Lambda, Map, and Filter in Python

Lambda: Lambda functions are known as the anonymous functions in Python. This kind of functions are declared without any name. Can accept any number of argument.  Restricted to only a single expression.  Used only one-time. Lambda function is used when you need a function for a short period of time.  Basic syntax:  lambda arguments : expression Example: Map: Map is a built-in function that takes a function object and iterable list (list/dictionary) as its parameter. Basic syntax: map (function_object, iterable_1, iterable_2, ... ) Few examples of Map in python: Filter: It works similar way like map. The difference is it makes a new list from the element in the list that satisfy some condition . In case of of parameters, it takes a function and one iterable. Basic syntax: filter (function, iterable) Normally used with lambda functions. Example is given below:

Fix Error: mysqlclient installation problem with Python

This problem usually happens when you try to install mysqlclient using Python 3.7 If you're using python 3.7, there is no way for fixing it. The only way to fix it is to downgrade your python version. Python 3.6 or lower. After re-configuring your python version, run this two commands: $ pip install wheel $ pip install --only-binary :all: mysqlclient

Insertion Sort Analysis - Python Implementation

Insertion sort always maintains a sorted sublist at the beginning of a list. New items are then again "inserted" back into the previous sorted sublist such that the sublist remain sorted and it becomes just one item larger. Time Complexity:         Worst Case and Average Case: O(n²)         Best Case: O(n) It works as the same way we arrange cards. Look at the example of swapping items in insertion sort below:  Consider [3, 2, 1] The loop starts with 3. Since it is the first item in the list there is nothing else to do. [ 3 , 2 , 1 ] The next item is 2. It compares 2 to 3 and since 2 is less than 3 it swaps them, first putting 3 in the second position and then placing 2 in the first position. [ 2 , 3 , 1 ] The last item is 1. Since 1 is less than 3 it moves 3 over. [ 2 , 3 , 3 ] Since 1 is less than 2 it swaps moves 2 over. [ 2 , 2 , 3 ] Then it inserts 1 at the beginning. [ 1 , 2 , 3 ]     ...