Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -256,14 +256,13 @@ class OutlierDetective:
|
|
256 |
self.outlier_results = results
|
257 |
return results
|
258 |
|
259 |
-
|
260 |
"""Generate comprehensive outlier analysis report"""
|
261 |
if not self.outlier_results:
|
262 |
return "No outlier analysis results available. Please run the analysis first."
|
263 |
|
264 |
report = "#Outlier Detection Report\n\n"
|
265 |
|
266 |
-
# Summary statistics
|
267 |
total_outliers_by_method = {}
|
268 |
all_outlier_indices = set()
|
269 |
|
@@ -273,14 +272,11 @@ class OutlierDetective:
|
|
273 |
|
274 |
for method, result in methods.items():
|
275 |
if isinstance(result, dict) and 'outlier_count' in result:
|
276 |
-
|
277 |
-
total_outliers_by_method[method] = 0
|
278 |
total_outliers_by_method[method] += result['outlier_count']
|
279 |
-
|
280 |
if 'outlier_indices' in result:
|
281 |
all_outlier_indices.update(result['outlier_indices'])
|
282 |
|
283 |
-
# Add multivariate results
|
284 |
if 'Multivariate' in self.outlier_results:
|
285 |
for method, result in self.outlier_results['Multivariate'].items():
|
286 |
if isinstance(result, dict) and 'outlier_count' in result:
|
@@ -297,19 +293,15 @@ class OutlierDetective:
|
|
297 |
for method, count in total_outliers_by_method.items():
|
298 |
report += f"- **{method}:** {count} outliers\n"
|
299 |
|
300 |
-
report += "\n"
|
301 |
-
|
302 |
-
# Detailed results by column
|
303 |
-
report += "## Detailed Results\n\n"
|
304 |
|
305 |
for column, methods in self.outlier_results.items():
|
306 |
if column == 'Multivariate':
|
307 |
continue
|
308 |
-
|
309 |
-
report += f"### Column: `{column}`\n\n"
|
310 |
|
|
|
311 |
for method, result in methods.items():
|
312 |
-
if not isinstance(result, dict) or 'outlier_count' in result and result['outlier_count'] == 0:
|
313 |
report += f"**{method}:** No outliers detected\n"
|
314 |
continue
|
315 |
|
@@ -317,23 +309,22 @@ class OutlierDetective:
|
|
317 |
report += f"- Outliers found: {result['outlier_count']} ({result['outlier_percentage']:.2f}%)\n"
|
318 |
report += f"- Explanation: {result['explanation']}\n"
|
319 |
|
320 |
-
# Show some example outlier values
|
321 |
if 'outlier_values' in result and result['outlier_values']:
|
322 |
-
sample_values = result['outlier_values'][:5]
|
323 |
-
|
|
|
324 |
if len(result['outlier_values']) > 5:
|
325 |
report += f" (and {len(result['outlier_values']) - 5} more)"
|
326 |
report += "\n"
|
327 |
-
|
328 |
report += "\n"
|
329 |
|
330 |
-
# Multivariate results
|
331 |
if 'Multivariate' in self.outlier_results:
|
332 |
report += "### Multivariate Analysis\n\n"
|
333 |
-
|
334 |
for method, result in self.outlier_results['Multivariate'].items():
|
335 |
-
if not isinstance(result, dict):
|
336 |
continue
|
337 |
-
|
338 |
report += f"**{method}:**\n"
|
339 |
-
report += f"- Outliers found: {result['
|
|
|
|
|
|
|
|
256 |
self.outlier_results = results
|
257 |
return results
|
258 |
|
259 |
+
def generate_outlier_report(self) -> str:
|
260 |
"""Generate comprehensive outlier analysis report"""
|
261 |
if not self.outlier_results:
|
262 |
return "No outlier analysis results available. Please run the analysis first."
|
263 |
|
264 |
report = "#Outlier Detection Report\n\n"
|
265 |
|
|
|
266 |
total_outliers_by_method = {}
|
267 |
all_outlier_indices = set()
|
268 |
|
|
|
272 |
|
273 |
for method, result in methods.items():
|
274 |
if isinstance(result, dict) and 'outlier_count' in result:
|
275 |
+
total_outliers_by_method.setdefault(method, 0)
|
|
|
276 |
total_outliers_by_method[method] += result['outlier_count']
|
|
|
277 |
if 'outlier_indices' in result:
|
278 |
all_outlier_indices.update(result['outlier_indices'])
|
279 |
|
|
|
280 |
if 'Multivariate' in self.outlier_results:
|
281 |
for method, result in self.outlier_results['Multivariate'].items():
|
282 |
if isinstance(result, dict) and 'outlier_count' in result:
|
|
|
293 |
for method, count in total_outliers_by_method.items():
|
294 |
report += f"- **{method}:** {count} outliers\n"
|
295 |
|
296 |
+
report += "\n## Detailed Results\n\n"
|
|
|
|
|
|
|
297 |
|
298 |
for column, methods in self.outlier_results.items():
|
299 |
if column == 'Multivariate':
|
300 |
continue
|
|
|
|
|
301 |
|
302 |
+
report += f"### Column: `{column}`\n\n"
|
303 |
for method, result in methods.items():
|
304 |
+
if not isinstance(result, dict) or ('outlier_count' in result and result['outlier_count'] == 0):
|
305 |
report += f"**{method}:** No outliers detected\n"
|
306 |
continue
|
307 |
|
|
|
309 |
report += f"- Outliers found: {result['outlier_count']} ({result['outlier_percentage']:.2f}%)\n"
|
310 |
report += f"- Explanation: {result['explanation']}\n"
|
311 |
|
|
|
312 |
if 'outlier_values' in result and result['outlier_values']:
|
313 |
+
sample_values = result['outlier_values'][:5]
|
314 |
+
formatted_values = ', '.join([f'{v:.3f}' if isinstance(v, (int, float)) else str(v) for v in sample_values])
|
315 |
+
report += f"- Example outliers: {formatted_values}"
|
316 |
if len(result['outlier_values']) > 5:
|
317 |
report += f" (and {len(result['outlier_values']) - 5} more)"
|
318 |
report += "\n"
|
|
|
319 |
report += "\n"
|
320 |
|
|
|
321 |
if 'Multivariate' in self.outlier_results:
|
322 |
report += "### Multivariate Analysis\n\n"
|
|
|
323 |
for method, result in self.outlier_results['Multivariate'].items():
|
324 |
+
if not isinstance(result, dict) or 'outlier_count' not in result:
|
325 |
continue
|
|
|
326 |
report += f"**{method}:**\n"
|
327 |
+
report += f"- Outliers found: {result['outlier_count']} ({result['outlier_percentage']:.2f}%)\n"
|
328 |
+
report += f"- Explanation: {result['explanation']}\n\n"
|
329 |
+
|
330 |
+
return report
|