{"id":5821,"date":"2025-08-21T03:13:35","date_gmt":"2025-08-21T03:13:35","guid":{"rendered":"https:\/\/techtrendfeed.com\/?p=5821"},"modified":"2025-08-21T03:13:35","modified_gmt":"2025-08-21T03:13:35","slug":"tutorialok-means-in-plain-python-flip-a-messy-spend-listing-into-3-clear-buckets-by-alen-george-aug-2025","status":"publish","type":"post","link":"https:\/\/techtrendfeed.com\/?p=5821","title":{"rendered":"[Tutorial]Ok-Means in Plain Python: Flip a Messy Spend Listing into 3 Clear Buckets | by Alen George | Aug, 2025"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div>\n<div>\n<h2 id=\"3ec2\" class=\"pw-subtitle-paragraph hu ha hb bf b hv hw hx hy hz ia ib ic id ie if ig ih ii ij cq du\">A delicate walk-through with ~30 strains of NumPy, a scikit-learn model, and a tiny dataset you generate in code.<\/h2>\n<div>\n<div class=\"speechify-ignore ac cp\">\n<div class=\"speechify-ignore bh m\">\n<div class=\"ac ik il im in io ip iq ir is it iu\">\n<div class=\"ac r iu\">\n<div class=\"ac iv\">\n<div>\n<div class=\"bm\" aria-hidden=\"false\" role=\"tooltip\">\n<div tabindex=\"-1\" class=\"be\"><a rel=\"nofollow\" target=\"_blank\" rel=\"noopener follow\" href=\"https:\/\/medium.com\/@alengeorge2005?source=post_page---byline--9a9b9c7bf26a---------------------------------------\" data-discover=\"true\"><\/p>\n<div class=\"m iw ix bx iy iz\">\n<div class=\"m fl\"><img decoding=\"async\" alt=\"Alen George\" class=\"m fd bx by bz cx\" src=\"https:\/\/miro.medium.com\/v2\/resize:fill:64:64\/1*xCrIpKYQQRCeJ-aO0M9mDw.jpeg\" width=\"32\" height=\"32\" loading=\"lazy\" data-testid=\"authorPhoto\"\/><\/div>\n<\/div>\n<p><\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n<p><span class=\"bf b bg ab bk\"\/><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<figure class=\"ms mt mu mv mw mx mp mq paragraph-image\">\n<div role=\"button\" tabindex=\"0\" class=\"my mz fl na bh nb\"><span class=\"fu nc nd an ne nf ng nh ni speechify-ignore\">Press enter or click on to view picture in full measurement<\/span><\/p>\n<div class=\"mp mq mr\"><picture><source srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/format:webp\/1*KP8qlkUql_4LQQL7FAolaQ.png 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/format:webp\/1*KP8qlkUql_4LQQL7FAolaQ.png 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/format:webp\/1*KP8qlkUql_4LQQL7FAolaQ.png 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/format:webp\/1*KP8qlkUql_4LQQL7FAolaQ.png 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/format:webp\/1*KP8qlkUql_4LQQL7FAolaQ.png 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/format:webp\/1*KP8qlkUql_4LQQL7FAolaQ.png 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/format:webp\/1*KP8qlkUql_4LQQL7FAolaQ.png 1400w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\" type=\"image\/webp\"\/><source data-testid=\"og\" srcset=\"https:\/\/miro.medium.com\/v2\/resize:fit:640\/1*KP8qlkUql_4LQQL7FAolaQ.png 640w, https:\/\/miro.medium.com\/v2\/resize:fit:720\/1*KP8qlkUql_4LQQL7FAolaQ.png 720w, https:\/\/miro.medium.com\/v2\/resize:fit:750\/1*KP8qlkUql_4LQQL7FAolaQ.png 750w, https:\/\/miro.medium.com\/v2\/resize:fit:786\/1*KP8qlkUql_4LQQL7FAolaQ.png 786w, https:\/\/miro.medium.com\/v2\/resize:fit:828\/1*KP8qlkUql_4LQQL7FAolaQ.png 828w, https:\/\/miro.medium.com\/v2\/resize:fit:1100\/1*KP8qlkUql_4LQQL7FAolaQ.png 1100w, https:\/\/miro.medium.com\/v2\/resize:fit:1400\/1*KP8qlkUql_4LQQL7FAolaQ.png 1400w\" sizes=\"(min-resolution: 4dppx) and (max-width: 700px) 50vw, (-webkit-min-device-pixel-ratio: 4) and (max-width: 700px) 50vw, (min-resolution: 3dppx) and (max-width: 700px) 67vw, (-webkit-min-device-pixel-ratio: 3) and (max-width: 700px) 65vw, (min-resolution: 2.5dppx) and (max-width: 700px) 80vw, (-webkit-min-device-pixel-ratio: 2.5) and (max-width: 700px) 80vw, (min-resolution: 2dppx) and (max-width: 700px) 100vw, (-webkit-min-device-pixel-ratio: 2) and (max-width: 700px) 100vw, 700px\"\/><img alt=\"\" class=\"bh lw nj c\" width=\"700\" height=\"382\" loading=\"eager\" role=\"presentation\"\/><\/picture><\/div>\n<\/div><figcaption class=\"nk ff nl mp mq nm nn bf b bg ab du\">Picture generated by <a rel=\"nofollow\" target=\"_blank\" class=\"ag no\" href=\"https:\/\/aistudio.google.com\/\" rel=\"noopener ugc nofollow\" target=\"_blank\">Gemini<\/a><\/figcaption><\/figure>\n<p id=\"8b91\" class=\"pw-post-body-paragraph np nq hb nr b hv ns nt nu hy nv nw nx ny nz oa ob oc od oe of og oh oi oj ok gu bk\"><strong class=\"nr hc\">Your financial institution feed is a blur.<\/strong> Let\u2019s flip it into three buckets you&#8217;ll be able to scan at a look: small, medium, and enormous spends. We&#8217;ll hold issues easy, write a tiny Ok-Means from scratch, then use scikit-learn. No downloads. The information is created contained in the code so anybody can run it.<\/p>\n<ul class=\"\">\n<li id=\"1abb\" class=\"np nq hb nr b hv ph nt nu hy pi nw nx ny pj oa ob oc pk oe of og pl oi oj ok pm pn po bk\">A minimal Ok-Means in about 30 strains<\/li>\n<li id=\"0319\" class=\"np nq hb nr b hv pp nt nu hy pq nw nx ny pr oa ob oc ps oe of og pt oi oj ok pm pn po bk\">The scikit-learn model you&#8217;ll use day after day<\/li>\n<li id=\"75d1\" class=\"np nq hb nr b hv pp nt nu hy pq nw nx ny pr oa ob oc ps oe of og pt oi oj ok pm pn po bk\">A fast \u201cmeasurement bucket\u201d labeler for artificial transactions<\/li>\n<\/ul>\n<pre class=\"ms mt mu mv mw pu pv pw bp px bb bk\"><span id=\"c3fb\" class=\"py om hb pv b bg pz qa m qb qc\">pip set up numpy pandas scikit-learn<\/span><\/pre>\n<p id=\"dd0a\" class=\"pw-post-body-paragraph np nq hb nr b hv ph nt nu hy pi nw nx ny pj oa ob oc pk oe of og pl oi oj ok gu bk\">We&#8217;ll create 60 faux transactions with practical ranges and small service provider quirks. It&#8217;s deterministic, so your outcomes match mine.<\/p>\n<pre class=\"ms mt mu mv mw pu pv pw bp px bb bk\"><span id=\"2b59\" class=\"py om hb pv b bg pz qa m qb qc\">import numpy as np, pandas as pd<br\/>def make_transactions(n=60, seed=0):<br\/>rng = np.random.default_rng(seed)<br\/>begin = np.datetime64(\"2025-06-01\")<br\/>dates = begin + rng.integers(0, 30\u2026<\/span><\/pre>\n<\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>A delicate walk-through with ~30 strains of NumPy, a scikit-learn model, and a tiny dataset you generate in code. Press enter or click on to view picture in full measurement Picture generated by Gemini Your financial institution feed is a blur. Let\u2019s flip it into three buckets you&#8217;ll be able to scan at a look: [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":5823,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55],"tags":[4836,4455,4835,119,2619,219,4801,3379,1258,4834,2416,4833],"class_list":["post-5821","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-machine-learning","tag-alen","tag-aug","tag-buckets","tag-clear","tag-george","tag-list","tag-messy","tag-plain","tag-python","tag-spend","tag-turn","tag-tutorialkmeans"],"_links":{"self":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/5821","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5821"}],"version-history":[{"count":1,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/5821\/revisions"}],"predecessor-version":[{"id":5822,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/5821\/revisions\/5822"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/media\/5823"}],"wp:attachment":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5821"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5821"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<!-- This website is optimized by Airlift. Learn more: https://airlift.net. Template:. Learn more: https://airlift.net. Template: 69d9690a190636c2e0989534. Config Timestamp: 2026-04-10 21:18:02 UTC, Cached Timestamp: 2026-08-13 04:01:50 UTC -->