Close Menu
    Trending
    • What’s the Highest Paid Hourly Position at Walmart?
    • Connecting the Dots for Better Movie Recommendations
    • Diabetes Prediction with Machine Learning by Model Mavericks | by Olivia Godwin | Jun, 2025
    • Mattel, OpenAI Sign Deal to Bring ChatGPT to ‘Iconic’ Toys
    • Agentic AI 103: Building Multi-Agent Teams
    • Vertical Integration in the AI Tech Stack | by Aashna Kumar | Jun, 2025
    • How to Build a Tech-Forward Company That Lasts
    • User Authorisation in Streamlit With OIDC and Google
    Finance StarGate
    • Home
    • Artificial Intelligence
    • AI Technology
    • Data Science
    • Machine Learning
    • Finance
    • Passive Income
    Finance StarGate
    Home»Machine Learning»K-means Clustering : Study case pizza restaurant in Khon Kaen, Thailand | by Pisit Jinanikorn | Mar, 2025
    Machine Learning

    K-means Clustering : Study case pizza restaurant in Khon Kaen, Thailand | by Pisit Jinanikorn | Mar, 2025

    FinanceStarGateBy FinanceStarGateMarch 11, 2025No Comments3 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    we ready the info from a CSV file. This dataset is semi-structured and accommodates order info from a pizza restaurant, together with Order Quantity, ORDER Kind, ID, ORDERTYPE, and PROMOTIONLIST.

    Fig 1. knowledge from CSV file.
    Fig 2. knowledge kind from CSV file.

    As you’ll be able to see, all the info sorts are object, which can’t be used instantly for evaluation. Subsequently, we’ll convert the info sorts utilizing Label Encoding.

    from sklearn.preprocessing import LabelEncoder
    # creating occasion of labelencoder
    labelencoder = LabelEncoder()
    df['ORDER'] = labelencoder.fit_transform(df['ORDER'])
    df['ORDERTYPE'] = labelencoder.fit_transform(df['ORDERTYPE'])
    df['PROMOTIONLIST'] = labelencoder.fit_transform(df['PROMOTIONLIST'])

    To handle this, we use Label Encoding to transform categorical knowledge into integer values. For instance :

    ORDER kind is encoded as

    1. House = 2
    2. LineMan (LM) = 3
    3. Seize = 1
    4. Dine-in = 0
    5. Pizza Supply = 4

    ORDERTYPE is encoded as

    1. Promotion = 1
    2. A LA CARTE = 0
    Fig 3. Transformed knowledge by Label Encoding.

    From Fig 3. The time format must be transformed, to be appropriate with the perform that classifies it into the respective time interval class. Through the use of this code.

    df['TIME'] = pd.to_datetime(df['TIME'], format='%I:%M %p', errors='coerce')
    df['Hour'] = df['TIME'].dt.hour

    Subsequent, we created a perform to transform the time into completely different lessons for every time interval, so we will determine when the orders have been positioned for additional evaluation

    def get_time_period(hour):
    if 5 return 'Morning'
    elif 11 return 'Lunch'
    elif 14 return 'Afternoon'
    elif 17 return 'Dinner'
    else:
    return 'Night time'

    df['TimePeriod'] = df['Hour'].apply(get_time_period)

    df.columns
    df.dtypes
    df.head(10)

    The consequence :

    Fig 4. The consequence from perform.

    Moreover, we convert the time format to align with our classification perform. We classify completely different time intervals as follows :

    1. Dinner = 1
    2. Lunch = 2
    3. Morning = 3
    4. Afternoon = 0
    5. Night time = 4
    df['TimePeriod'] = labelencoder.fit_transform(df['TimePeriod'])

    df.columns
    df.dtypes
    df.head(10)

    The consequence :

    Fig 5. The consequence from Label Encoding.

    Subsequent, we drop the columns that aren’t wanted, comparable to ID, TIME, and HOUR. Through the use of this code.

    df.drop(['ID','TIME','Hour'], axis=1, inplace=True)
    df.columns
    df.dtypes
    df.head(10)

    The consequence :

    Fig 6. The consequence from dropping the columns that aren’t wanted .

    Okay-Means requires us to specify the variety of clusters ( Okay ). Choosing the proper Okay is essential, as an inappropriate worth might result in poor clustering outcomes.

    To find out the optimum Okay, we use the Elbow Technique, which plots the Sum of Squared Errors (SSE) in opposition to completely different values of Okay. The elbow level—the place the curve bends—is normally the only option, as rising Okay past this level ends in diminishing returns.

    To refine our choice, we take into account a variety of doable values for Okay, usually ±2 across the elbow level. After figuring out this vary, we additional analyze the SSE values to make sure we choose the most effective Okay for our dataset.



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleCIQ Delivers Technical Preview of Security-Hardened Enterprise Linux
    Next Article Why AI leaders can’t afford fragmented AI tools
    FinanceStarGate

    Related Posts

    Machine Learning

    Diabetes Prediction with Machine Learning by Model Mavericks | by Olivia Godwin | Jun, 2025

    June 12, 2025
    Machine Learning

    Vertical Integration in the AI Tech Stack | by Aashna Kumar | Jun, 2025

    June 12, 2025
    Machine Learning

    A Practical Guide to Time Series Model Explainability Using Darts | by Agreharshit | Jun, 2025

    June 12, 2025
    Add A Comment

    Comments are closed.

    Top Posts

    Dave’s Hot Chicken Acquired for $1B By Roark Capital

    June 4, 2025

    5 Key Leadership Principles That Drive Real Results

    May 4, 2025

    The importance of contingency planning as you age

    February 10, 2025

    Innovation vs. Regulation: The Arms Race of the Digital Age

    March 11, 2025

    Analyzing and Predicting Book Reviews Using NLP Techniques | by Fatma Nur ÇETİNTÜRK | Mar, 2025

    March 30, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Data Science
    • Finance
    • Machine Learning
    • Passive Income
    Most Popular

    Model Compression: Make Your Machine Learning Models Lighter and Faster

    May 9, 2025

    Why Communication Flaws Are Costing You More Than You Think

    April 30, 2025

    Small Business Administration: Surging Application Approvals

    April 24, 2025
    Our Picks

    How Golden Visas and Second Passports Are Transforming Wealth Strategies

    March 17, 2025

    Why the world is looking to ditch US AI models

    March 25, 2025

    Unlock the Power of AI in Intelligent Operations

    February 18, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Data Science
    • Finance
    • Machine Learning
    • Passive Income
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2025 Financestargate.com All Rights Reserved.

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