Skip to main content

Posts

Standard Normal Distribution with examples using Python

Recent posts

Understanding Normal Distribution and its Properties using Python

Understanding Normal Distribution and its Properties using Python A Normal or Gaussian distribution is used to represent continuous random variables. BMI of people, height of people amongst other phenomena tend to follow a Normal distribution. It is generally used to describe a lot of natural phenomena around us. A normal distribution generally follows a bell curve. Let's see this in action. A normal distribution is defined by 2 parameters viz. Mean and Standard Deviation . This is how you can define this distribution using the Stats functionality from Scipy . import numpy as np from matplotlib import pyplot as plt from scipy.stats import norm import scipy x= np.linspace(0,700,1000000)##Create evenly spaced numbers from 0 to 400 r1 = norm.rvs(loc=350,scale=50,size=1000000) ###Create samples with mean=350 and stdev=50 Notice the rvs attribute of norm . We will talk about it in a while. Let's see how the plot for this distribution look

Continuous Uniform Probability Distribution with Python

Continuous Uniform Probability Distribution In an earlier post , we had discussed about Random Variables and what is a continuous random variable. An extension of those ideas comes in the form of a distribution called a Continuous Uniform Probability Distribution . In a continuous probability distribution, we are not interested in exact events. As an example of this, we would not be so bothered to know the chances of a duration of flight to be exactly 180 minutes or 177 minutes. We would be more keen in knowing the chances of a flight duration being between 150 minutes to 185 minutes. Time intervals are more important to extract probability information in this case. The simplest form of continuous probability distribution function is a unform probability distribution function. It is also called a rectangular distribution function due to its inherent rectangular shape. Let's assume that the flight duration from Bangalore to Delhi roughly takes

Difference between Discrete and Continuous Random variables

Difference between Discrete and Continuous Random variables What is a Random Variable? Let's say you want to observe the number of goals scored in any football match in the English Premier League season. You record the number of goals scored in each match in a set S--> (3,1,4,0,6,8,...2). We just conducted a series of random experiments of observing goals in each match. Every random experiment had a numerical outcome which we call as a random variable . In our case, it was the number of goals in each match (3,1,4,...2). The reason we call this as random is because we do not know until the end of the match about the number of goals which would be scored. What is a Discrete Random Variable? In our example of observing number of goals scored , we saw the set S--> (3,1,4,0,6,8,...2). A match can end in a draw (0 goals), or the number of goals could be 1 or 2 or n goals. The n goals will be finite and sensible. In some sense, we can cou

Easy Guide to using f-strings in Python with examples

Easy Guide to using f-strings in Python with examples f-strings were introduced in Python 3.6. String formatting has been made simpler with f-strings. f-strings are of the form f" " or f' ' . Let's look at some examples to understand this better. How to print a variable using f-strings? name = "James Bond" drink = "martini" serving_type = "shaken and not stirred" f"My name is {name} and I like my {drink} {serving_type}" --->My name is James Bond and I like my martini shaken and not stirred f-strings use a { } to evaluate any expression and format it as a string. The above example evaluates each of the variables within curly braces and formats it as string. How to use mathematical expressions with f-strings f"2x2 = {2*2}" --->2x2 = 4 f"Square of 8 is {8**2} ---> Square of 8 is 64 Practically anything can be put inside the { } as long as the expresson eval

How to format float and numerical values using f-strings

f-strings have made life easier for Python developers. They are of the form f" {} " where the curly brackets are optional. The advantage of curly brackets is that expressions can be evaluated within f-strings at runtime and printed to the screen. We need not cast the variable to string format anymore. They have been around since Python 3.6 How to restrict decimal to n positions for a float variable? pi= 22/7 f"Value of pi upto 2 decimal positions is {pi:0.2f}" --->Value of pi upto 2 decimal positions is 3.14 f"Value of pi upto 3 decimal positions is {pi:0.3f}" --->Value of pi upto 3 decimal positions is 3.143 f"Value of pi upto 4 decimal positions is {pi:0.4f}" --->Value of pi upto 4 decimal positions is 3.1429 f"Value of pi with no decimal position is {pi:0.0f}" --->Value of pi with no decimal position is 3 How to format a fraction as a Percentage using f-strings? perc = 0.555553

How to adopt Embeddings for Categorical features in Tabular Data using PyTorch's nn.Embedding( )-- Part 2

In the previous post , we set up the context to utilize embeddings for categorical features. In this post, we will figure out how to create these embeddings and combine them with other continuous features to build a neural network model. Dataset Download We will utilize the UCI machine learning repo which has a dataset on credit card default for customers in Taiwan. This dataset is also available in Kaggle . Metadata about this dataset is available on the respective websites. To follow this post, it is recommended to download the dataset from Kaggle. Most of the features are self explanatory. Embedding Creation A few definitions first. Levels in a categorical feature represent unique values available for that categorical feature. For e.g. MARRIAGE has levels 0,1,2,3. Each level of a categorical feature is represented by a vector of numbers. So, if you stack up all the levels together and all the vectors together, you can imagine levels to be a colum