def fit_from_centroids(): data_test = [178.75, 5.97390157] data_height = [170., 186., 182., 177.] data_size = [40, 42, 45, 47, 50] data_injuries = [3, 4, 1, 0] centers = [[175., 4.08], [44.8, 3.54], [2., 1.58]] fcm = FCM(n_clusters=3, max_iter=1) fcm.cluster_centers_ = np.array(centers) fcm.fit(fcm.cluster_centers_, [0, 1, 2]) membership_height = fcm.predict(np.array([data_test])) membership_height = fcm.predict( np.array([[np.average(data_height), np.std(data_height)]])) membership_size = fcm.predict( np.array([[np.average(data_size), np.std(data_size)]])) membership_injuries = fcm.predict( np.array([[np.average(data_injuries), np.std(data_injuries)]]))
def load_mlmodel_into_fcm(model): """ :param model: MLModel :param data: matrix input as np array :return: FCM model """ num_of_cols = len(model.cluster_set.all()) centers = [] for clus_model in model.cluster_set.all(): logger.debug("load_mlmodel_into_fcm> getting clus %s" % clus_model.name) p = clus_model.center.split(',') centers.append(p) centers_np = np.array(centers, dtype='f') # logger.debug("Centers: ") # logger.debug(centers_np) fcm = FCM(n_clusters=num_of_cols, max_iter=1, logger=logger) fcm.cluster_centers_ = centers_np data = centers_np logger.debug("load_mlmodel_into_fcm> will fit the data with %d clusters" % num_of_cols) fcm.fit(data, range(num_of_cols)) logger.info("generated the FCM model from the MLModel") return fcm