Commit bc4462e8 authored by Alexander Lercher's avatar Alexander Lercher

[RoleStage] Small changes in clustering

parent 7f326a3d
...@@ -79,6 +79,9 @@ class Repository(MongoRepositoryBase): ...@@ -79,6 +79,9 @@ class Repository(MongoRepositoryBase):
entries = super().get_entries(self._clusters_collection, selection={'layer_name': layer_name}, projection={'_id': 0}) entries = super().get_entries(self._clusters_collection, selection={'layer_name': layer_name}, projection={'_id': 0})
return [Cluster(cluster_dict=e, from_db=True) for e in entries] return [Cluster(cluster_dict=e, from_db=True) for e in entries]
def delete_all_clusters(self):
super().drop_collection(self._clusters_collection)
#endregion #endregion
#region TimeSlice #region TimeSlice
......
...@@ -35,7 +35,7 @@ class Clusterer: ...@@ -35,7 +35,7 @@ class Clusterer:
'''Extracts the feature values from the dataset into a np array with same order as original dataset.''' '''Extracts the feature values from the dataset into a np array with same order as original dataset.'''
extracted_features = [] extracted_features = []
for data in dataset: for data in dataset:
entry = [float(data[feature]) for feature in features] entry = [float(data[feature] if data[feature] is not "" else 0) for feature in features]
extracted_features.append(entry) extracted_features.append(entry)
return np.asarray(extracted_features) return np.asarray(extracted_features)
......
...@@ -25,8 +25,11 @@ def run_generic_clustering(): ...@@ -25,8 +25,11 @@ def run_generic_clustering():
print("skipping") print("skipping")
continue continue
try:
clusters = run_clustering_for_layer(layer) clusters = run_clustering_for_layer(layer)
store_generic_clusters(clusters) store_generic_clusters(clusters)
except Exception as e:
print(str(e))
def run_clustering_for_layer(layer: Layer) -> List[Cluster]: def run_clustering_for_layer(layer: Layer) -> List[Cluster]:
...@@ -46,4 +49,5 @@ def store_generic_clusters(clusters: List[Cluster]): ...@@ -46,4 +49,5 @@ def store_generic_clusters(clusters: List[Cluster]):
if __name__ == "__main__": if __name__ == "__main__":
repo.delete_all_clusters()
run_generic_clustering() run_generic_clustering()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment