k-means clustering

    0

    0

    clustering

    The code will then fit a KMeans model to the values in the "vals" column. The "y_means" column will be the estimated KMeans model.

    from sklearn.cluster import KMeans
    
    km = KMeans(n_clusters = 5,
      init = 'k-means++',  
      max_iter = 300,
      n_init = 10,         
      random_state = 0)
    
    # Define the values to which the KMeans model will be applied, replace with desired columns
    # generally will want to normalize dataframe
    vals = df_norm.iloc[:, [3, 4]].values
    
    # Fit the model to the values
    y_means = km.fit(vals)
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.