Tuesday, April 28, 2026

Kaggle Data: Plot(With Respect) of Breast Cancer Wisconsin Data Set

Scatter Plot: Mean Radius vs Mean Texture of Breast Cancer Wisconsin Data Set


This scatter plot visualizes the relationship between two important features from the Breast Cancer Wisconsin (Diagnostic) dataset: Mean Radius and Mean Texture of cell nuclei.
  • X-axis (Mean Radius): Represents the average size of the cell nuclei.
  • Y-axis (Mean Texture): Represents how much the cell nuclei vary in gray levels (a measure of texture or irregularity). Rougher / more varied appearance under the microscope (higher Mean Texture)
Each point on the plot represents one breast mass sample. The color indicates the diagnosis:
  • Red points = Malignant (cancerous)
  • Blue points = Benign (non-cancerous)
Key Observation: The plot clearly shows two distinct clusters. Malignant tumors (red) tend to appear in the upper-right region, indicating they generally have larger radius and higher texture values. In contrast, benign tumors (blue) mostly cluster in the lower-left area with smaller radius and smoother texture.This natural separation suggests that these two features (Mean Radius and Mean Texture) contain valuable information for distinguishing between cancerous and non-cancerous breast tumors. 


Python Code for the Plot
import osimport pandas as pdimport seaborn as snsimport matplotlib.pyplot as pltfrom kaggle.api.kaggle_api_extended import KaggleApiimport zipfile
# ==================== YOUR KAGGLE CREDENTIALS ====================os.environ['KAGGLE_USERNAME'] = "xxxxxxxx"os.environ['KAGGLE_KEY'] = "KGAT_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Authenticateapi = KaggleApi()api.authenticate()
# Download and extract datasetapi.dataset_download_files("uciml/breast-cancer-wisconsin-data", path='.', unzip=False)
with zipfile.ZipFile('breast-cancer-wisconsin-data.zip', 'r') as zip_ref:    zip_ref.extractall('breast_cancer_data')
# Load datadf = pd.read_csv('breast_cancer_data/data.csv')
# ============================# Clean Scatter Plot with Correct Legend# ============================
plt.figure(figsize=(10, 8))
ax = sns.scatterplot(    data=df,    x='radius_mean',    y='texture_mean',    hue='diagnosis',    palette={'M': 'red', 'B': 'blue'},    alpha=0.8,    s=75)
plt.title("Mean Radius vs Mean Texture\nBreast Cancer Wisconsin (Diagnostic) Dataset",           fontsize=14, fontweight='bold', pad=20)
plt.xlabel("Mean Radius", fontsize=12)plt.ylabel("Mean Texture", fontsize=12)
# === Fix Legend Properly ===handles, labels = ax.get_legend_handles_labels()
# Map correct readable labelslabel_map = {'M': 'Malignant (M)', 'B': 'Benign (B)'}new_labels = [label_map[label] for label in labels]
ax.legend(handles, new_labels, title="Diagnosis", loc='upper left', fontsize=10)
plt.grid(True, alpha=0.3)plt.tight_layout()plt.show()

Saturday, April 25, 2026

Dynamic Prompt Engineering for LLM(Llama3.2) In my Local Machine

Dynamic prompting tailors the input prompt to adaptively include only the most relevant information from prior interactions. This approach ensures that essential context is retained while keeping the token count within limits.

Dynamic Prompt Engineering
  • Definition: The process of creating or modifying the prompt itself at runtime (dynamically).
  • It focuses on how you structure and word the instructions, templates, roles, examples, reasoning steps, output format, etc.
  • The prompt (especially the system message or user message) changes based on the situation — e.g., different roles, tones, few-shot examples, or instructions depending on the task.

Example in the Python Code
system_message = f"""You are a {role}.

CONTEXT:
{context}

USER PREFERENCES:
{prefs}

TONE:
{tone}
"""
This is dynamic prompt engineering — you're building a customized prompt by filling in variables (role, context, prefs, tone).


References

Shekhar Agrawal; Srinivasa Sunil Chippada; Rathish Mohan. Ultimate Agentic AI with AutoGen for Enterprise Automation: Design, Build, And Deploy Enterprise-Grade AI Agents Using LLMs and AutoGen To Power Intelligent, ... Enterprise Automation (English Edition) (p. 177). Orange Education Pvt Ltd, AVA™. Kindle Edition. 



Python code for this 

# === Fix for Jupyter Notebook ===

import nest_asyncio

nest_asyncio.apply()          # ← This line solves the "event loop is already running" error


import asyncio

from autogen_ext.models.ollama import OllamaChatCompletionClient

from autogen_agentchat.agents import AssistantAgent

from autogen_agentchat.ui import Console

def create_dynamic_llama_agent(

    name: str,

    role: str,

    context: str,

    prefs: str = "",

    tone: str = "helpful"

):

    system_message = f"""You are a {role}.

CONTEXT:

{context}

USER PREFERENCES:

{prefs}

TONE:

{tone}

Think step by step. Be clear, accurate, and follow the user's preferences.

"""

    model_client = OllamaChatCompletionClient(

        model="llama3.2:latest",      # Use "llama3.2:3b" if you downloaded the small version

        temperature=0.7,

        num_ctx=8192,

    )

    agent = AssistantAgent(

        name=name,

        model_client=model_client,

        system_message=system_message,

    )

    print(f"✅ Created dynamic agent '{name}' with role: {role}")

    print(f"   Context length: {len(context)} characters\n")

    return agent


# ====================== Main Function ======================

async def main():

    analyst = create_dynamic_llama_agent(

        name="DataAnalyst",

        role="data analyst",

        context="The latest quarterly sales data shows a 22% drop in Europe, while Asia grew by 15%. Main product 'WidgetX' underperformed.",

        prefs="Always include chart suggestions and 2-3 actionable recommendations",

        tone="professional and data-driven"

    )

    task = "Analyze the sales situation and suggest recovery strategies."

    print("🚀 Running task with dynamic prompt...\n")

    # Streaming output with nice formatting

    stream = analyst.run_stream(task=task)

    await Console(stream)


# ====================== Run in Jupyter ======================

# Just run this cell

await main()