Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -353,7 +353,6 @@ def extract_problem_domains(df,
|
|
| 353 |
# top_words = [feature_names[index] for index in top_word_indices]
|
| 354 |
# cluster_representations[i] = top_words
|
| 355 |
|
| 356 |
-
|
| 357 |
try:
|
| 358 |
center = kmeans.cluster_centers_[i]
|
| 359 |
console_messages.append(f"Processing cluster {i}")
|
|
@@ -361,28 +360,28 @@ def extract_problem_domains(df,
|
|
| 361 |
|
| 362 |
if not isinstance(center, np.ndarray):
|
| 363 |
center = np.array(center)
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
|
|
|
| 369 |
top_word_indices = sorted_indices[-top_words:][::-1]
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
top_words = [feature_names[index] for index in top_word_indices]
|
| 377 |
console_messages.append(f"Top words: {top_words}")
|
| 378 |
cluster_representations[i] = top_words
|
| 379 |
|
| 380 |
-
|
| 381 |
-
|
| 382 |
except Exception as e:
|
| 383 |
console_messages.append(f"Error processing cluster {i}: {str(e)}")
|
| 384 |
console_messages.append(f"Center: {center}")
|
| 385 |
|
|
|
|
| 386 |
|
| 387 |
console_messages.append(f"Number of clusters: {optimal_n_clusters}")
|
| 388 |
console_messages.append(f"Sample cluster words: {cluster_representations[0][:5]}...")
|
|
|
|
| 353 |
# top_words = [feature_names[index] for index in top_word_indices]
|
| 354 |
# cluster_representations[i] = top_words
|
| 355 |
|
|
|
|
| 356 |
try:
|
| 357 |
center = kmeans.cluster_centers_[i]
|
| 358 |
console_messages.append(f"Processing cluster {i}")
|
|
|
|
| 360 |
|
| 361 |
if not isinstance(center, np.ndarray):
|
| 362 |
center = np.array(center)
|
| 363 |
+
|
| 364 |
+
# Remove NaN values
|
| 365 |
+
center = center[~np.isnan(center)]
|
| 366 |
+
|
| 367 |
+
sorted_indices = np.array(center.argsort())
|
| 368 |
+
|
| 369 |
top_word_indices = sorted_indices[-top_words:][::-1]
|
| 370 |
+
|
| 371 |
+
# Check for valid indices
|
| 372 |
+
if np.any(top_word_indices < 0) or np.any(top_word_indices >= len(feature_names)):
|
| 373 |
+
console_messages.append(f"Invalid top word indices for cluster {i}")
|
| 374 |
+
continue
|
| 375 |
+
|
| 376 |
top_words = [feature_names[index] for index in top_word_indices]
|
| 377 |
console_messages.append(f"Top words: {top_words}")
|
| 378 |
cluster_representations[i] = top_words
|
| 379 |
|
|
|
|
|
|
|
| 380 |
except Exception as e:
|
| 381 |
console_messages.append(f"Error processing cluster {i}: {str(e)}")
|
| 382 |
console_messages.append(f"Center: {center}")
|
| 383 |
|
| 384 |
+
|
| 385 |
|
| 386 |
console_messages.append(f"Number of clusters: {optimal_n_clusters}")
|
| 387 |
console_messages.append(f"Sample cluster words: {cluster_representations[0][:5]}...")
|