Skip to content

Instantly share code, notes, and snippets.

View Kimxons's full-sized avatar
🏠
Working from home

Meshack Kitonga Kimxons

🏠
Working from home
View GitHub Profile
@Kimxons
Kimxons / README.md
Created February 2, 2023 06:58 — forked from rpgove/README.md
Using the elbow method to determine the optimal number of clusters for k-means clustering

K-means is a simple unsupervised machine learning algorithm that groups a dataset into a user-specified number (k) of clusters. The algorithm is somewhat naive--it clusters the data into k clusters, even if k is not the right number of clusters to use. Therefore, when using k-means clustering, users need some way to determine whether they are using the right number of clusters.

One method to validate the number of clusters is the elbow method. The idea of the elbow method is to run k-means clustering on the dataset for a range of values of k (say, k from 1 to 10 in the examples above), and for each value of k calculate the sum of squared errors (SSE). Like this:

var sse = {};
for (var k = 1; k <= maxK; ++k) {
    sse[k] = 0;
    clusters = kmeans(dataset, k);
    clusters.forEach(function(cluster) {

mean = clusterMean(cluster);

#include<stdio.h>
#include<string.h>
void palindrome(char str[])
{
int leftmost_index = 0;
int rightmost_index = strlen(str) - 1;
while(rightmost_index > leftmost_index)
{
@Kimxons
Kimxons / hash_backed_maps.py
Last active March 20, 2021 09:24
Hash-backed Maps
#!/usr/bin/python3
#define dictionary
dic = {
'alice':100,
'bob':200,
'shak':300,
}
#get value by key
x = dic["bob"]
@Kimxons
Kimxons / python_strings.py
Created March 20, 2021 09:22
python strings are immutable -> they cant be changed after theyre created
my_string = 'hi'
print(my_string)
print(my_string[0])
print(len(my_string))
print( my_string + "", "there" )#concatenation
@Kimxons
Kimxons / stack.py
Last active March 20, 2021 09:20
Working with stack in python 3
#implementation one
stack = [2,3,4]
stack.append(7)
print("Stack after appending: \n", stack)
stack.pop()
print("Stack after popping: \n", stack)
#implementation two
class Stack:
def __init__(self):
@Kimxons
Kimxons / web-servers.md
Created December 15, 2020 14:59 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000