File size: 570 Bytes
a3171a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import pandas as pd
from sklearn.preprocessing import StandardScaler
import streamlit as st
from sklearn.cluster import KMeans



def process(data):

    if 'object' in list(data[0].dtypes):
        st.info('This Algorithm can only process numerical data')
        return None

    scaler = StandardScaler()
    df = data[0].copy()

    for c in data[0].columns:
        df[c] = scaler.fit_transform(data[0][[c]])
    k = st.slider('Number of Clusters :',2,9)
    kmeans = KMeans(k)
    res = kmeans.fit_predict(df)
    df = data[0]
    df['cluster'] = res
    return df