Σ being a positive definite ensure quadratic bowl is downwards
σ2 also being positive ensure that parabola is downwards
On Covariance Matrix
Definition of covariance between two vectors:
When we have more than two variable we present them in matrix form. So covariance matrix will look like
Above is very similar to how we compute sigma^2 in 1-D = (x – mu)^2
Formula of multivariate gaussian distribution demands Σ to be singular and symmetric positive semidefinite, which in terms means sigma will be symmetric positive semidefinite.
For some data above demands might not meet
Side Note
Covariance is directional measure
Correlation is scaled measure
We normalise by individual variance
Derivations
Following derivations are available at [0]:
We can prove[0] that when covariance matrix is diagonal (i.e there is variables are independent) multivariate gaussian distribution is simply multiplication of single gaussian distribution of each variable.
It was derived that shape of isocontours (figure 1) is elliptical and axis length is proportional to individual variance of that variable
Above is true even when covariance matrix is not diagonal and for dimension n>2 (ellipsoids)
First part above says that bi-variant destitution can be generated from two standard normal distribution z = N(0,1).
For any given k-variant Gaussian we can represent it as linear combination of k standard normal distribution. One simpler way to find these coefficient is Cholesky decomposition. Theorem 1 below stats the same thing.
This has a reference from [1].
Linear Transformation Interpretation
This was proved in two steps [0]:
Step-1 : Factorizing covariance matrix
Step-2 : Change of variables, which we apply to density function
On Practical Example
Height, wight and waist size of men in US (Of course it weight can be negative, so it is approximately normal)
Understanding probability rules and solving tricky probability questions can be challenging. In this blog post, we will explore key probability rules and discuss solutions to some intriguing questions.
Probability Rules:
Joint Distribution: The probability of events X and Y occurring together is denoted as p(X, Y) and is known as the joint distribution.
Conditional Distribution: The probability of event X given event Y is denoted as p(X/Y) and is known as the conditional distribution.
Marginal Distribution: The probability of event X, with event Y marginalized out, is denoted as p(X) and is known as the marginal distribution.
Operations:
Making Conditional Distribution: To obtain the conditional distribution, normalization is required.
Marginalization: Marginalization does not require normalization.
Note: It is not possible to derive the conditional distribution from the joint distribution solely through integration. There is no direct relationship between them.
There are just two rules for probability. Sum rule and product rules. And then there is Bayes theorem. Bayes theorem can be derived from product rule and the fact that P(x,y) = P(y,x)
We might want to look at a table like below and calculate joint and conditional distribution and marginalized out one of the variable. [1]
Probability Tricky Question
This questions are taken from [2]. One key to solve this question is write down the sample space and keep eliminating choices. Don’t conclude in hurry.
Q1 : A man comes up to you on the street and says: I have two children. At least one of them is a boy. What is the probability that the other child is also a boy?
Q2 : I have two kids, what are the odds I have 2 boys?
Q3 : A man comes up to you on the street and says: I have two children. The older one is a boy. What is the probability that the other child is also a boy?
Q4 : A man comes up to you on the street and says: I have two children. One is the boy standing here next to me. What is the probability that the other child is also a boy?
Q5 : Q. A man comes up to you on the street and says: I have two children. One of them is a boy who was born in the summer. What is the probability that the other child is also a boy? (There are four seasons : spring, summer, fall, winter)[0]
Ans1 : (1/3)
P(BG) is 1/2 and p(BB) = 1/4 in the universe
Ans2 : (1/4)
Ans3 : (1/2)
Ans4 : (1/2)
Ans5 : (7/15) [0]
Compare Q1 and Q5. Odd increases. Being born in summer is rare thing. If that rare thing has occurred there are higher chances of having two boys.
A bag contains (x) one rupee coins and (y) 50 paise coins. Four coins are taken from the bag and put away. If a coin is now taken at random from the bag, what is the probability that it is a one rupee coin?
Ans is x/(x+y). It will remain same if we take either 1/2/3/4/5 coins because we don’t know which coin has been withdrawn. It is like trying out all possibilities and when we sum, it would come out as 1 only. [4]
The probability of a car passing a certain intersection in a 20 minute windows is 0.9. What is the probability of a car passing the intersection in a 5 minute window? (Assuming a constant probability throughout)
Ans : 0.4377 [5]
Independent Events
Mutually exclusive events means dependent event
For independent event = P(A/B) = P(A)
For mutually exclusive event if we know B has occurred, A will never occur.
If two random variables, X and Y, are independent, they satisfy the following conditions.
P(x|y) = P(x), for all values of X and Y.
P(X, Y) = P(x ∩ y) = P(x) * P(y), for all values of X and Y.
Here is an example from [6]. Ans is that X and Y are independent, A and B are not.
Margin is the distance between hyperplane and closest training data point
We want to select a hyperplane for which this distance is maximum
Once we identify optimal separating hyper plane there can be many equidistance training points with the shortest distance from hyperplane
Such point are called support vectors
These points support the hyperplane in a sense that if they are moved slightly optimal hyperplane will also move
Training
Equation 9.10 ensures that left hand side of equation 9.11 gives perpendicular distance from the hyperplane
Equation assumes y has two values (+1) and (-1)
Support Vector classifier
Maximum margin classifier does not work when supporting hyperplane does not exist.
Support vector classifier relaxes optimization objective to get that work
Unlike maximum margin classifier this one is less prone to overfit as well
The formal one is very sensitive to change in single observation
Also know as soft margin classifier
ε variable allows training point to be on wrong side of margin
If ε > 0 it is on the wrong side of margin
If ε > 1 it is on the wrong side of hyperplane
Parameter C is the budget that constraints how many points are allowed on wrong side of hyperplane
C is selected with cross validation and controls bias variance trade off
Point that lies directly on the margin or on the wrong side of margin for their class are called support vectors
Because these points affects the choice of hyperplane
And this is the property which makes it robust to outliers
LDA calculates mean of all the observation
However LR is less sensitivity to outliers
Computation note – when we try to solve above optimization problem with lagrange multiplier we found that it depends on dot product of training samples
This will be very important when we discuss support vector machine in next section
Dot product is only with support vector, both while training and while solving [1]
Support vector machine
Above two classifier does not work when desired decision boundary is not linear
One solution is to create polynomial features (as we generally do for LR)
But fundamental problem with this approach is that how many and which terms you should create
Also creating large number of feature raises computational problem
For the case of SVM, that fact that it involved only dot product of observation allows us to perform kernel trick.
Kernel acts as similarity function
Above equation makes it clear that we are not calculating(and storing) higher order polynomial still taking the advantage of it
Second one is polynomial kernel and last one is radial kernel
LDA models probability with multivariate Gaussian function
LR find maximum likelihood solution
LDA find maximum a posterior using Bayes’ formula
When classes are well separated
When the classes are well-separated, the parameter estimates for logistic regression are surprisingly unstable. Coefficients may go to infinity. LDA doesn’t suffer from this problem.
LR gets unstable in the case of perfect separation
If there are covariate values that can predict the binary outcome perfectly then the algorithm of logistic regression, i.e. Fisher scoring, does not even converge.
If you are using R or SAS you will get a warning that probabilities of zero and one were computed and that the algorithm has crashed.
This is the extreme case of perfect separation but even if the data are only separated to a great degree and not perfectly, the maximum likelihood estimator might not exist and even if it does exist, the estimates are not reliable.
The resulting fit is not good at all.
Math behind LR
For example suppose y = 0 for x=0 and y=1 for x = 1. To maximize the likelihood of the observed data, the “S”-shaped logistic regression curve has to model h(Θ) as 0 and 1. This will lead β to reach infinite, which causes the instability.
Few terms:
Complete Separation – when x completely predicts both zero and 1
Quasi-Complete separation – when x completely predicts either 0 or 1
When can LDA fail
It can fail if either the between or within covariance matrix(Sigma) is singular but that is a rather rareinstance.
In fact, If there is complete or quasi-complete separation then all the better because the discriminant is more likely to be successful.
LDA is popular when we have more than two response classes, because it also provides low-dimensional views of the data.
In the post on LDA, QDA we had said that LDA is generalization of Fisher’s discriminant analysis (which involves project data on lower dimension to that achieves maximum separation).
LDA may result in information loss
The low-dimensional representation has a problem that it can result in loss of information. This is less of a problem when the data are linearly separable but if they are not the loss of information might be substantial and the classifier will perform poorly
Another assumption of LDA that it assumes equal covariance matrix for all classes, in which case we might go for QDA. Blog post on LDA, QDA list more consideration about the same.
{In practice it is used more for classification than for regression}
This resemble gaussian mixture models in that you git one gaussian for each class.
Don't forget one important difference though. LDA is supervised, Mixture models are unsupervised.
Linear Discriminant Analysis (LDA)
In logistic regression (LR), we estimate the posterior probability directly. In LDA we estimate likelihood and then use Bayes theorem. Calculating posterior using bayes theorem is easy in case of classification because hypothesis space is limited.
Equation 2 computes probability of class k given x. This is a posterior instead of just point estimates.
Equation 4 is derived from equation 3 only. Probability(k) would be highest for the class for which Delta(k) will be highest.
LDA estimates mean and variance from data and uses equation 4 for classification.
We also need to estimate π_k, which I think would be n_k/N.
Assumptions made:
f(x) is normal
Variance(sigma) is same for all classes
When more than one predictor, we go for multivariate gaussian
Some comparisons
Compare this with mixture models, where there is a responsibility vector for each sample
There labels are not available (unsupervised learning) and hence is solved by EM (Expectation Maximization)
Compare this with naive bayes, there assumption is each feature is independent
Here we have parameter for each (class, feature), there we have parameter for each feature
Also here f captures probability of class (k) given x, there after bayes rules we calculate probability of x given class k
Hence the name naive bayes
Here we have joint distribution (multivariate gaussian, there it is independent distribution for each features)
Both LDA and navie bayes try to calculate posterior while logistic regression maximizes likelihood function
Quadratic Descriminant Analysis (QDA)
Unlike LDA, QDA assumes that each class has its own covariance matrix. It is called quadratic because below function is quadratic of x.
When to use LDA, QDA
This is related to bias variance trade-off
For p predict and k classes
LDA estimates k*p parameters
QDA estimates additional k*p*(p+1)/2 parameters
So LDA has much lower variance and classifier built can suffer from high bias
LDA should be used when number of training sample are less, because we want to avoid high variance problem
QDA has high variance, so it should be used when number of training samples are more
Another scenario would the case when common covariance matrix among K classes is untenable
A note on Fisher’s Linear Discriminant Analysis
It is simply LDA in case of two classes.
We can derive this similarity mathematically.
In literature we found it from the perspective that it project data on a line which achieves maximum separation
We can state without loss of generality that LDA also provides low dimensional view on data
Math
We want to project 2-D data on a line which
maximizes the difference between projected mean
minimizes within class variance
Such a direction can be found by maximizing fisher criterion (J)
In the blog post on Cost Function And Hypothesis for LR we noted that LR (Logistic Regression) inherently models binary classification. Here we will describe two approaches used to extend it for multiclass classification.
One vs Rest approach takes one class as positive and rest all as negative and trains the classifier. So for the data having n-classes it trains n classifiers. Now in the scoring phase all the n-classifier predicts probability of particular class and class with highest probability is selected.
One vs One considers each binary pair of classes and trains classifier on subset of data containing those classes. So it trains total n*(n-1)/2 classes. During the classification phases each classifier predicts one class. (This is contrast to one vs rest where each classifier predicts probability). And the class which has been predicted most is the answer.
Example
For example consider four class problem having classes A, B, C, and D.
One vs Rest
Models classifiers_A, classifier_B, classifier_C and classifier_D
During prediction here is the probability we get:
classifier_A = 40% = prob(class A)
classifier_B = 30%
classifier_C = 60%
classifier_D = 50%
We assign it class B
Note that Summation might not be come out to 1
Prob(class A) + Prob(class B) + Prob(class C)
One vs One
We train total six classifier with subset of data containing classes involved
classifier_AB
classifier_AC
classifier_AD
classifier_BC
classifier_BD
classifier_CD
And during classification
classifier_AB assigns class A
classifier_AC assigns class A
classifier_AD assigns class A
classifier_BC assigns class B
classifier_BD assigns class D
classifier_CD assigns class C
We assign it to class A
How do we estimate Prob(class A) ?
Somewhat complicated
More notes
One vs rest trains less no of classifier and hence is faster overall and hence is usually prefered
Single classifier in one vs one uses subset of data, so single classifier is faster for one vs one
One vs one is less prone to imbalance in dataset (dominance of particular classes)
Inconsistency
What if two class gets equal vote in the case of one vs one case
What if probability are almost close to equal in case of one vs rest
Use precision / recall based on use case, needs threshold tuning
Two types of AUC
ROC-AUC for balanced dataset
PR-AUC for imbalanced dataset
Used because its threshold independent
model selection
threshold selection
drift detection ( calculate AUC from production log and track )
F score to balance both precision and recall
Again at some threshold
In multi class we have
Macro F1 score – PR for each class -> F1 for each -> average
When you care about minority classes
E commerce customer support classification – general / refund / legal
Medical diagnosis – rare disease 1, rare disease 2, general disease
Micro F1 score – Get TP, FP for each class and sum to fill the metrics
We are going at micros level -> TP, FP for each class
overall dataset accuracy is main priority
classifier to predict user’s genre for book e-commerce – fiction, fitness, aviation
Goal is overall CTR
Weighted F1 manly assigns weight to each individual F1
Macro assigns same weight by taking average
Normalized entropy
When business needs calibrated probabilities ( uses cross entropy )
normalized by true CTR (0,1) range easy to compare
Threshold independent
Some Scenarios
In finance default is failure to meet the legal obligation of loan. Given some data we want to classify whether the person will be defaulter or not.
Suppose our training data-set is imbalanced. Out of 10k samples only 300 are defaulters. (3%)
Classifier in the following table is good at classifying non defaulters but not good at classifying defaulters (which is more important for credit card company)
Assume what if out of 300 defaulters 250 are classified as non defaulters and given the credit card
Doctors want to conduct a test whether a patient has cancer or not.
Popular terms in medical field are sensitivity and specificity
Instead of trying to classify person as defaulter, here we classify if patient has cancer.
Sensitivity = 81/333 = 24 %
Specificity = 9644/9667 = 99 %
Every medical test thrives to achieve 100% in both sensitivity and specificity.
In information retriever we want to know how many % of relevant pages we were able to retrieve.
TP = 81
FP = 23
TN = 9644
FN = 252
Precision = 81/104= 77%
Recall = 81/333= sensitivity = 24%
Example
Formulas:
Precision = TP/(TP+FP)
Recall = TP/(TP+FN)
Sensitivity = TP/(TP+FN)
Specificity = TN/(TN+FP)
Recall and sensitivity are same
Solution is to change the threshold
Earlier we were assigning person to default if probability is more than 50%
Now we want to assign more person as defaulter
So we will assign them to defaulter when probability is more than 20%
This will incorrectly classify non-defaulters to defaulters but that is less concerned compared to assigning defaulter to non-defaulter
This will also increase the overall error rate, which is still okay
ROC-AUC
We can always increase sensitivity by classifying all samples as positive
We can increase specificity by classifying all samples as negative
ROC plot (sensitivity) vs (1-specificity)
That is TP vs FP
And also precision vs recall
ROC = Receiver operating characteristic
It is good to have ROC curve on top left
Better classifier
Accurate test
And ROC curve close to 45 degree represents less accurate test
AUC = Area Under Curve
Area under ROC curve
Ideal value for AUC is 1
AUC of 0.5 (45 degree line) represents a random classifier
AUC = P(score of a random positive > score of a random negative )
0.5 => random, 1 => perfect seperation
Its scale invariance
Any monotonic transform ( multiply by 1.4, log ) preserves parities comparison
How to plot ROC?
Change the probability threshold from 0 to 1 and measure sensitivity and specificity. If specificity keeps on decreasing ((100-specificity) keeps on increasing) as sensitivity increase it is a bad classifier.
For random classifier ROC is 45 degree line
You draw random number between (0, 1)
Classify it based on threshold
So threshold is there
But while building classifier we want to do better than drawing random probability between (0, 1). We also want to consider features into account while drawing between (0, 1)
Can AUC be less than 0.5? I don’t think so.
Complementing the output will bring it to other side of line anyway.
What if I classified all of them as positive?
That means you are taking all 1. You can not plot ROC with that.
Threshold selection
Unless there is special business requirement (as in credit card defaulters) we want to select a threshold which maximizes TP while minimizing FP
There are two methods to do that:
Point which is closest to (0, 1) in ROC curve
Youden Index
Point which maximizes vertical distance from line of equality (45 degree line)
We can derive that this is the point which maximizes (sensitivity + specificity)
AUC vs overall accuracy as comparison metric
AUC helps us understand how much our classifier is away from random guess, which accuracy can not tell
Accuracy is measured at particular threshold while AUC requires moving threshold from 0 to 1
PR-AUC
PR-AUC (Precision-Recall Area Under the Curve) summarizes a classifier’s performance by plotting Precision against Recall across all thresholds. You should use it when your data has a severe class imbalance (e.g., < 5% positive class) and your primary goal is to minimize False Positives and False Negatives within that rare target group
While training on the model, you can take a look at PR-ROC. Once you have found your best model, you can pick up any point based on the business needs.
A random classifier always gives ROC AUC to be 0.5.
Our ROC would be the percentage of positive samples.
This helps with the cases where there is highly class imbalance and we have more negative samples.
F score
We know that recall and sensitivity are same, but precision and specificity are not same
While medical field is more concerned about specificity, information retrieval is more concerned about precision
So they came up with F score which is harmonic mean of precision and recall
AUChelps us maximizing sensitivity and specificity simultaneously while F scorehelps us maximizing precision and recall simultaneously
Beta in f score helps providing weight to precision and recall.
Harmonic mean can not be made arbitrarily large while changing some values to bigger one and leaving at least one unchanged. It is maximizes when all elements are increased.
x = 0, y = 1 will give 0.5 in arithmetic mean but is zero for harmonic mean
harmonic mean
Micro and Macro F1 Score
The Core Difference
When dealing with multi-class classification (predicting three or more categories, like Cat, Dog, or Bird), you calculate an F1-score for each individual class. To get a single final score for the whole model, you must aggregate them:
Macro F1 treats all classes equally. It calculates the F1-score for each class independently and takes the unweighted average. It is excellent for flagging if a model performs poorly on a rare, minor class.
We can also cut on domain dimension like
head/tail query
Video popularity decile
Matrix of trigger popularity decile x video popularity decile
Micro F1 treats all samples equally. It pools the True Positives (TP), False Positives (FP), and False Negatives (FN) from all classes together, then computes a global F1-score. It is heavily influenced by the performance of the majority class.
Step-by-Step Example
Let’s say we have an image classification model evaluating 100 test images across three categories. The dataset is highly imbalanced:
Cat: 80 images
Dog: 15 images
Bird: 5 images
After running our model, we track the True Positives (TP), False Positives (FP), and False Negatives (FN) for each class:
Class
Total Images
True Positives (TP)
False Positives (FP)
False Negatives (FN)
Class F1-Score
Cat
80
75
10
5
0.91
Dog
15
10
5
5
0.67
Bird
5
1
2
4
0.25
(Note: Our model does great on Cats, decent on Dogs, but terrible on Birds because Birds are rare.)
1. Calculating Macro F1
Macro F1 is simply the straightforward average of the individual class F1-scores.
Why it matters: The score drops to 0.61 because it treats the Bird class with the exact same weight as the Catclass, exposing the model’s failure on rare data.
2. Calculating Micro F1
Micro F1 aggregates the counts of all raw outcomes across the entire dataset first.
Total TP = 75 + 10 + 1 = 86
Total FP = 10 + 5 + 2 = 17
Total FN = 5 + 5 + 4 = 14
Using these global metrics, we calculate overall Precision and Recall:
Why it matters: The score is a high 0.85 because the model correctly classified most of the dataset (the 80 Cats), effectively masking the fact that it completely failed at identifying Birds.
Summary Guideline
Use Macro F1 when you care about minority classes and want to ensure the model performs well across every single category equally.
Use Micro F1 when overall dataset accuracy is your main priority, and you are comfortable with minor classes having a negligible impact on the final score.
Normalized Entropy
To understand Normalized Entropy (NE), let’s use a simple example of a model predicting whether a user will click an ad.
In this metric, lower values are better. A score of 1.0 means your model is no better than a random guess based on the background average, while 0.0 means perfect predictions.
Step 1: The Dataset (20 Rows)
Suppose we have 20 ad impressions. 5 resulted in a click (1), and 15 did not (0).
0.4624 is less than 1, which proves the model is actively adding value.
By subtracting this from 1 ($1 – 0.4624 = 0.5376$), we can conclude that our model reduces uncertainty by roughly 53.8% compared to a naive baseline guess.
importnumpyasnp
# Let's simulate a dataset of 20 rows (between 10 and 50)
# Binary classification context (e.g., Click vs No Click)
# Let's assume a background positive rate (p) of 0.25 (5 clicks out of 20)
We want a hypothesis that is bounded between zero and one, regression hypothesis line extends beyond this limits. Hypothesis here also represents probability of observing an outcome.
Hypothesis by ISLR and Andrew N.G :
Odds and log-odds/logit
Log of odd is also called logit. So above is logit(p(x)) = b0 + b1X.
In terms of GLM we call it a logic link function. Logit has a property of broadcasting [0,1] range to [-inf, inf]. Log does not have that property.
In regression beta1 given average change in y for unit change in x. But here it says unit increase in x changes log-odds by beta1. It multiplies odds by exp(beta1) and hence depends on current value of odds and therefor is not linear.
Cost Function
For ISLR perspective it is likelihood that we want to maximize.
Andre N.G looks it from the perspective of modifying cost function of linear regression.
As we can see that Andrew N.G cost function is same as maximizing log likelihood of ISLR.
Least square in case of linear regression is special case of maximum likelihood. We know that derivation where we assume likelihood to be gaussian.
Logistic Regression For well separated classes
MLE estimation becomes unstable when classes are well separated. While this is acceptable for classification tasks, it is not ideal for risk estimation. Regularization techniques can help avoid this instability. Support Vector Machines (SVM) also perform well for well-separated classes. As shown in figure below[1], the intercept of the sigmoid function reaches -inf, and the slope reaches inf. This allows the slope to come from an infinitely weighted feature.
Why Can’t we use square loss ?
Labels (+1, and -1)
Prediction : +1 when w*x > 0 else -1
Consider scenario [2]
label +1
w*x = 100
Prediction is correct
Still we add it to loss (100-1)^2
Solutions are hinge loss and logistic loss
Why is not logistic loss not 0 for correct prediction ?
There are more training samples. We want to find parameter such that it balances all of them
If we make it 0 positive examples would no longer contribute to loss (like SVM)
That’s why hinge loss create support vectors. More about that on SVM’s blog post
Also this is the property which will make coefficient higher for well separated classes
To control that we use regularisation
Regularisation is while training, not while prediction, we are just changing loss function
Predict is still +1 is w*x > 0 else -1
Why can’t we use step loss ?
When we are incurring loss, we also want to know which direction to go to reduce loss.
Gradient/slope is what provide this information. [2]
We calculate the t-score using hypothesis data, which also provides us with the degrees of freedom. This value is then supplied to a function that gives us the probability of the hypothesis being true.
The t-test can be seen as a ratio, similar to a signal-to-noise ratio. The numerator allows us to center it around zero, while the denominator represents the standard error of the mean (SEM) calculated as s/sqrt(n), where s is the standard deviation of the samples.
The t-score indicates how many SEM the current mean is away from the mean given in the hypothesis. If it is far away, it suggests a low probability of the null-hypothesis-mean being true, leading us to reject the null hypothesis.
In engineering, we typically assume that the mean and standard deviation are given and true, and we compute the probability of observing the sample. However, in hypothesis testing with a small number of samples, we are testing whether the given mean is true or not.
To address this, we need a distribution that adjusts itself based on the number of observations, widening when there are fewer samples. The t-distribution serves this purpose, as it is dependent on the sample size.
There are different types of t-tests:
One-sample t-test: Compares the mean of a sample with a known population mean.
Discussion so far is for one sample test
Two-sample t-test: Compares the means of two independent groups.
To compare means of two independent groups
Scores of student who get 8 hour sleep vs four hour sleep
Question we want to answer is are there any significant difference in there scores?
In one sample test (In numerator of t-score) we are comparing sample mean with population mean
In two sample test it compares means of two independently drawn sample
And in denominator as well SEM formula is modified
Example
A/B testing on e-commerce site where you compare CTR before and after
This is two sample because you don’t have standard value of CTR before the feature
Even you will see some difference in AA test
Paired t-test: Compares the means of two conditions using the same samples.
This is essentially a one-sample t-test on the differences between values at two conditions.
Same samples are used in two different conditions
10 people before medication and same 10 people after medication
We want to check if medication has any effect
Different time points are used for market calculation
This essentially is a one sample T-test on the differences of value at two different conditions
Example
Interleaving test in e-commence search system
For each search page you will assign some score to control and variant
One-sided t-test: Tests a hypothesis in one direction (e.g., weight of dairy milk is less than 100g).
Two-sided t-test: Tests a hypothesis in both directions (e.g., weight of dairy milk is not equal to 100g).
P-values represent the probability of finding the observed or more extreme results when the null hypothesis is true. It is described in terms of rejecting the null hypothesis when it is actually true, but it is not a direct probability of this state.
For further examples and details, you can refer to the following link: Example Link