Close Menu
    Trending
    • Finding the right tool for the job: Visual Search for 1 Million+ Products | by Elliot Ford | Kingfisher-Technology | Jul, 2025
    • How Smart Entrepreneurs Turn Mid-Year Tax Reviews Into Long-Term Financial Wins
    • Become a Better Data Scientist with These Prompt Engineering Tips and Tricks
    • Meanwhile in Europe: How We Learned to Stop Worrying and Love the AI Angst | by Andreas Maier | Jul, 2025
    • Transform Complexity into Opportunity with Digital Engineering
    • OpenAI Is Fighting Back Against Meta Poaching AI Talent
    • Lessons Learned After 6.5 Years Of Machine Learning
    • Handling Big Git Repos in AI Development | by Rajarshi Karmakar | Jul, 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

    Finding the right tool for the job: Visual Search for 1 Million+ Products | by Elliot Ford | Kingfisher-Technology | Jul, 2025

    July 1, 2025
    Machine Learning

    Meanwhile in Europe: How We Learned to Stop Worrying and Love the AI Angst | by Andreas Maier | Jul, 2025

    July 1, 2025
    Machine Learning

    Handling Big Git Repos in AI Development | by Rajarshi Karmakar | Jul, 2025

    July 1, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    Finding the right tool for the job: Visual Search for 1 Million+ Products | by Elliot Ford | Kingfisher-Technology | Jul, 2025

    July 1, 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

    Meta’s new AI model can translate speech from more than 100 languages

    January 15, 2025

    What If Your AI Wasn’t Just Answering You? | by Terralanmira | Jun, 2025

    June 5, 2025

    DeepSeek V3: A New Contender in AI-Powered Data Science | by Yu Dong | Feb, 2025

    February 2, 2025
    Our Picks

    Finding the right tool for the job: Visual Search for 1 Million+ Products | by Elliot Ford | Kingfisher-Technology | Jul, 2025

    July 1, 2025

    How Smart Entrepreneurs Turn Mid-Year Tax Reviews Into Long-Term Financial Wins

    July 1, 2025

    Become a Better Data Scientist with These Prompt Engineering Tips and Tricks

    July 1, 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.