我已经使用sklearn使用Kmeans完成了聚类。尽管它有一种打印质心的方法,但我发现scikit-learn没有找到簇长的方法(或者到目前为止我还没有看到它)真是太奇怪了。是否有一种巧妙的方法来获取每个群集的群集长度或与群集关联的许多点?我现在有这个相当笨拙的代码,在我发现长度为一的簇的情况下,并且需要通过测量点之间的欧几里得距离来向该簇添加其他点,并且必须更新标签
import numpy as np
from clustering.clusternew import Kmeans_clu
from evolution.generate import reproduction
from mapping.somnew import mapping, no_of_neurons, neuron_weights_init
from population_creation.population import pop_create
from New_SOL import newsol
data = genfromtxt('iris.csv', delimiter=',', skip_header=0, usecols=range(0, 4)) ##Read the input data
actual_label = genfromtxt('iris.csv', delimiter=',', dtype=str,skip_header=0, usecols=(4))
chromosome = int(input("Enter the number of chromosomes: ")) #Input the population size
max_gen = int(input("Enter the maximum number of generation: ")) #Input the maximum number of generation
for i in range(0, chromosome):
cluster = 3#random.randint(2, max_cluster) …Run Code Online (Sandbox Code Playgroud) python machine-learning k-means unsupervised-learning scikit-learn
public class NoDuplicate {
static final int NO_OF_CHARS = 256;
/* Print duplicates present in the passed string */
static void printDistinct(String str)
{
// Create an array of size 256 and count of
// every character in it
int[] count = new int[NO_OF_CHARS];
/* Count array with frequency of characters */
int i;
for (i = 0; i < str.length(); i++)
if(str.charAt(i)!=' ')
count[(int)str.charAt(i)]++;
int n = i;
// Print characters having count more than 0
for (i = …Run Code Online (Sandbox Code Playgroud)