Skip to main content

Posts

Showing posts with the label Python

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...

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 ...

How to Save and Retrieve a Vector Database using LangChain, FAISS, and Gemini Embeddings

How to Save and Retrieve a Vector Database using LangChain, FAISS, and Gemini Embeddings Efficient storage and retrieval of vector databases is foundational for building intelligent retrieval-augmented generation (RAG) systems using large language models (LLMs). In this guide, we’ll walk through a professional-grade Python implementation that utilizes LangChain with FAISS and Google Gemini Embeddings to store document embeddings and retrieve similar information. This setup is highly suitable for advanced machine learning (ML) and deep learning (DL) engineers who work with semantic search and retrieval pipelines. Why Vector Databases Matter in LLM Applications Traditional keyword-based search systems fall short when it comes to understanding semantic meaning. Vector databases store high-dimensional embeddings of text data, allowing for approximate nearest-neighbor (ANN) searches based on semantic similarity. These capabilities are critical in applications like: Question Ans...

Advanced Guide to Python Decorators | Expert Python Techniques

In Python, decorators are a powerful feature used to modify or enhance functions and classes. They are a key part of advanced metaprogramming and are frequently used in logging, authentication, caching, metrics, and tracing in production systems. This document provides an in-depth explanation of the syntax and all common use cases of Python decorators with professional examples aimed at deep learning engineers. 1. Basic Syntax of a Decorator def my_decorator(func): def wrapper(*args, **kwargs): print("Before function call") result = func(*args, **kwargs) print("After function call") return result return wrapper @my_decorator def say_hello(name): print(f"Hello, {name}!") say_hello("Alice") @my_decorator is equivalent to writing say_hello = my_decorator(say_hello) . 2. Stacking Multiple Decorators def deco1(func): def wrapper(*args, **kwargs): print("deco1") ...

Comprehensive Guide to Python's with Statement

1. What is the with Statement? Python's with statement simplifies resource management and exception handling. It ensures that resources like files, network connections, and databases are properly acquired and released. 2. Basic Usage with open('example.txt', 'r') as file: data = file.read() print(data) In this example, the file example.txt is opened in read mode, its contents are read, and the file is automatically closed after the block is executed. 3. What is a Context Manager? The with statement works with context managers, which implement the __enter__() and __exit__() methods to manage resource setup and teardown. 4. Custom Context Manager class CustomContextManager: def __enter__(self): print("Setting up resource") return self def __exit__(self, exc_type, exc_value, traceback): print("Releasing resource") with CustomContextManager() as manager: ...