Skip to main content

Posts

Showing posts from June, 2025

Understanding Z-Test and P-Value with ML Use Cases

Learn about z-test and p-value in statistics with detailed examples and Python code. Understand how they apply to Machine Learning and Deep Learning for model evaluation. What is a P-Value? The p-value is a probability that measures the strength of the evidence against the null hypothesis. Specifically, it is the probability of observing a test statistic (like the z-score) at least as extreme as the one computed from your sample, assuming that the null hypothesis is true. A smaller p-value indicates stronger evidence against the null hypothesis. Common thresholds to reject the null hypothesis are: p < 0.05: statistically significant p < 0.01: highly significant Python Example of Z-Test Let’s assume we want to test whether the mean of a sample differs from a known population mean: import numpy as np from scipy import stats # Sample data sample = [2.9, 3.0, 2.5, 3.2, 3.8, 3.5] mu = 3.0 # Population mean sigma = 0.5 # Population std dev...

Understanding Distance Metrics in Machine Learning with PyTorch Examples

Distance metrics play a crucial role in machine learning, especially in tasks like clustering, classification, and recommendation systems. In this blog, we will explore popular distance metrics including Cosine, Euclidean, Mahalanobis, Hellinger, Jaccard, Manhattan, Correlation, Dice, and Hamming distances. We will also provide PyTorch implementations for each metric. 1. Cosine Distance Measures the cosine of the angle between two non-zero vectors. Often used in text similarity and document clustering. import torch x = torch.tensor([1.0, 2.0, 3.0]) y = torch.tensor([4.0, 5.0, 6.0]) cosine_distance = 1 - torch.nn.functional.cosine_similarity(x.unsqueeze(0), y.unsqueeze(0)) 2. Euclidean Distance Represents the straight-line distance between two points in Euclidean space. euclidean_distance = torch.dist(x, y, p=2) 3. Mahalanobis Distance Accounts for the correlation between variables and scales distances accordingly. Useful in anomaly detection. cov = torch.cov(torch.stack([x,...

Relational Deep Learning: Learning from Relational Databases using GNNs

Relational Deep Learning (RDL)  proposes a unified graph-based way to model multi-table databases for end-to-end learning using GNNs. This retains relational semantics, avoids joins, and supports temporal reasoning. It’s a paradigm shift that bridges the gap between ML and databases. 1. Motivation: From Tables to Graphs Traditional Setup Relational databases store structured data across multiple normalized tables , each capturing different types of entities (e.g., users, orders, products). These tables are linked by foreign-key (FK) and primary-key (PK) constraints. To train machine learning models, these databases are typically flattened into a single table using joins , and domain experts manually select and engineer features. Problems: Joins are expensive and brittle (schema changes break pipelines). Manual feature engineering is time-consuming and lacks relational awareness. Loss of information about cross-entity relationships . 2. Core Idea: Learn Direc...

Building an MCP Agent with UV, Python & mcp-use

Model Context Protocol (MCP) is an open protocol designed to enable AI agents to interact with external tools and data in a standardized way. MCP is composed of three components: server , client , and host . MCP host The MCP host acts as the interface between the user and the agent   (such as Claude Desktop or IDE) and plays the role of connecting to external tools or data through MCP clients and servers. Previously, Anthropic’s Claude Desktop was introduced as a host, but it required a separate desktop app, license, and API key management, leading to dependency on the Claude ecosystem.   mcp-use is an open-source Python/Node package that connects LangChain LLMs (e.g., GPT-4, Claude, Groq) to MCP servers in just six lines of code, eliminating dependencies and supporting multi-server and multi-model setups. MCP Client The MCP client manages the MCP protocol within the host and is responsible for connecting to MCP servers that provide the necessary functions for the ...