Close Menu
    Trending
    • Can Machines Really Recreate “You”?
    • Meet the researcher hosting a scientific conference by and for AI
    • Current Landscape of Artificial Intelligence Threats | by Kosiyae Yussuf | CodeToDeploy : The Tech Digest | Aug, 2025
    • Data Protection vs. Data Privacy: What’s the Real Difference?
    • Elon Musk and X reach settlement with axed Twitter workers
    • Labubu Could Reach $1B in Sales, According to Pop Mart CEO
    • Unfiltered Roleplay AI Chatbots with Pictures – My Top Picks
    • Optimizing ML Costs with Azure Machine Learning | by Joshua Fox | Aug, 2025
    AIBS News
    • Home
    • Artificial Intelligence
    • Machine Learning
    • AI Technology
    • Data Science
    • More
      • Technology
      • Business
    AIBS News
    Home»Machine Learning»Running LLMs Locally: A Beginner’s Guide to Automating Marketing Data Analysis with AI (Part 3) | by Devarsh Tare | Mar, 2025
    Machine Learning

    Running LLMs Locally: A Beginner’s Guide to Automating Marketing Data Analysis with AI (Part 3) | by Devarsh Tare | Mar, 2025

    Team_AIBS NewsBy Team_AIBS NewsMarch 2, 2025No Comments2 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    import pandas as pd
    import subprocess

    def analyze_with_ollama(immediate, mannequin=”mistral”):
    “””Ship immediate to Ollama and get response”””
    cmd = [
    “ollama”, “run”, model,
    f”{prompt}”
    ]
    outcome = subprocess.run(cmd, capture_output=True, textual content=True)
    return outcome.stdout
    def load_and_summarize_data(file_path):
    “””Load dataset and generate a abstract for LLM context”””
    df = pd.read_csv(file_path) # or pd.read_excel() for Excel recordsdata
    data_context = f”””
    Columns: {‘, ‘.be a part of(df.columns)}
    Pattern row: {dict(df.iloc[0])}
    Numeric columns: {df.select_dtypes(embody=’quantity’).columns.tolist()}
    “””
    return df, data_context
    def generate_pivot_code(data_context):
    “””Ask LLM to generate pivot desk code”””
    pivot_prompt = f”””Analyze this dataset and create pandas pivot desk code. Knowledge context: {data_context}
    Return ONLY legitimate Python code with pd.pivot_table() that will be most insightful.
    Enclose code in “`python“` blocks.”””

    llm_response = analyze_with_ollama(pivot_prompt)

    # Extract code from response
    strive:
    code_block = llm_response.break up(““`python”)[1].break up(““`”)[0]
    besides IndexError:
    code_block = llm_response # Fallback to full response if code block not discovered

    return code_block
    def execute_pivot_code(code_block, df):
    “””Execute the generated pivot desk code safely”””
    strive:
    local_vars = {‘df’: df}
    exec(code_block, globals(), local_vars)
    pivot_df = local_vars.get(‘pivot_table’)
    return pivot_df
    besides Exception as e:
    return f”Code execution failed: {str(e)}”
    def analyze_pivot_table(pivot_df):
    “””Ask LLM to investigate the pivot desk and supply insights”””
    analysis_prompt = f”””Analyze this pivot desk:
    {pivot_df.head().to_markdown()}
    Present 3 key insights in bullet factors.”””

    return analyze_with_ollama(analysis_prompt)
    def auto_pivot_analysis(file_path):
    “””Automate your entire pivot desk evaluation course of”””
    print(“Loading dataset…”)
    df, data_context = load_and_summarize_data(file_path)

    print(“Producing pivot desk code utilizing LLM…”)
    pivot_code = generate_pivot_code(data_context)
    print(f”Generated code:n{pivot_code}”)

    print(“Executing pivot desk code…”)
    pivot_df = execute_pivot_code(pivot_code, df)
    if isinstance(pivot_df, str): # Verify if execution failed
    print(pivot_df)
    return

    print(“Analyzing pivot desk with LLM…”)
    insights = analyze_pivot_table(pivot_df)
    print(“nPivot Evaluation Outcomes:”)
    print(insights)
    if __name__ == “__main__”:
    outcome = auto_pivot_analysis(“sales_data.csv”) # Exchange together with your file path



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleSmart Cities: Solving Urban Problems with IoT
    Next Article 7 Steps to Building a Smart, High-Performing Team
    Team_AIBS News
    • Website

    Related Posts

    Machine Learning

    Current Landscape of Artificial Intelligence Threats | by Kosiyae Yussuf | CodeToDeploy : The Tech Digest | Aug, 2025

    August 22, 2025
    Machine Learning

    Optimizing ML Costs with Azure Machine Learning | by Joshua Fox | Aug, 2025

    August 22, 2025
    Machine Learning

    Top Tools and Skills for AI/ML Engineers in 2025 | by Raviishankargarapti | Aug, 2025

    August 22, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    Can Machines Really Recreate “You”?

    August 22, 2025

    I Tried Buying a Car Through Amazon: Here Are the Pros, Cons

    December 10, 2024

    Amazon and eBay to pay ‘fair share’ for e-waste recycling

    December 10, 2024

    Artificial Intelligence Concerns & Predictions For 2025

    December 10, 2024

    Barbara Corcoran: Entrepreneurs Must ‘Embrace Change’

    December 10, 2024
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    Most Popular

    Introducing n-Step Temporal-Difference Methods | by Oliver S | Dec, 2024

    December 29, 2024

    Weight in Neural Network. My blog… | by Kien Duong | Jan, 2025

    January 18, 2025

    Vibe coding lets anyone write software—but comes with risks

    June 8, 2025
    Our Picks

    Can Machines Really Recreate “You”?

    August 22, 2025

    Meet the researcher hosting a scientific conference by and for AI

    August 22, 2025

    Current Landscape of Artificial Intelligence Threats | by Kosiyae Yussuf | CodeToDeploy : The Tech Digest | Aug, 2025

    August 22, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2024 Aibsnews.comAll Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.