示例#1
0
 def init(clustering: str = ClusteringMethods.NO_CLUSTER.value,
          configuration: dict = {}):
     if clustering == ClusteringMethods.NO_CLUSTER.value:
         return NoCluster.objects.get_or_create(
             pk=1, clustering_method=clustering)[0]
     elif clustering == ClusteringMethods.KMEANS.value:
         from src.clustering.methods_default_config import clustering_kmeans  # TODO fixme
         default_configuration = clustering_kmeans()
         return KMeans.objects.get_or_create(
             clustering_method=clustering,
             n_clusters=configuration.get(
                 'n_clusters', default_configuration['n_clusters']),
             init=configuration.get('init', default_configuration['init']),
             n_init=configuration.get('n_init',
                                      default_configuration['n_init']),
             max_iter=configuration.get('max_iter',
                                        default_configuration['max_iter']),
             tol=configuration.get('tol', default_configuration['tol']),
             precompute_distances=configuration.get(
                 'precompute_distances',
                 default_configuration['precompute_distances']),
             random_state=configuration.get(
                 'random_state', default_configuration['random_state']),
             copy_x=configuration.get('copy_x',
                                      default_configuration['copy_x']),
             algorithm=configuration.get(
                 'algorithm', default_configuration['algorithm']))[0]
     else:
         raise ValueError(
             'configuration {} not recognized'.format(clustering))
示例#2
0
def add_default_config(job: Job, prediction_method=""):  # TODO is this needed?
    """Map to job method default config"""
    if prediction_method == "":
        prediction_method = job.predictive_model.prediction_method
    method_conf_name = "{}.{}".format(job.predictive_model.predictive_model,
                                      prediction_method)
    method_conf = CONF_MAP[method_conf_name]()
    job[method_conf_name] = method_conf
    job['kmeans'] = clustering_kmeans()
    return job