aigroup-econ-mcp 0.7.0__py3-none-any.whl → 0.8.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of aigroup-econ-mcp might be problematic. Click here for more details.

@@ -570,33 +570,133 @@ VARIANCE_DECOMPOSITION_ANALYSIS = ToolDescription(
570
570
 
571
571
  RANDOM_FOREST_REGRESSION_ANALYSIS = ToolDescription(
572
572
  name="random_forest_regression_analysis",
573
- description="随机森林回归 - 支持文件输入",
573
+ description="""随机森林回归分析
574
+
575
+ 📊 功能说明:
576
+ 随机森林通过构建多个决策树并集成结果,能够处理复杂的非线性关系和特征交互。
577
+
578
+ 📈 算法特点:
579
+ - 集成学习:多个决策树投票或平均结果
580
+ - 稳健性:对异常值和噪声数据稳健
581
+ - 特征重要性:自动计算特征重要性分数
582
+ - 袋外评估:使用袋外样本进行模型评估
583
+ - 并行训练:支持并行化训练加速
584
+
585
+ 💡 适用场景:
586
+ - 复杂非线性关系建模
587
+ - 特征交互分析
588
+ - 稳健预测需求
589
+ - 特征重要性评估
590
+ - 大数据集处理
591
+
592
+ ⚠️ 注意事项:
593
+ - 黑盒模型,可解释性较差
594
+ - 内存消耗较大(树的数量多时)
595
+ - 训练时间随树数量增加
596
+ - 可能过度拟合噪声数据
597
+
598
+ 🔧 参数建议:
599
+ - n_estimators: 树的数量,默认100
600
+ - 小数据集: 50-100
601
+ - 大数据集: 100-500
602
+ - max_depth: 最大深度,默认None(无限制)
603
+ - 控制过拟合: 5-15
604
+ - 复杂关系: None(无限制)
605
+
606
+ 📋 数据要求:
607
+ - 至少10个样本
608
+ - 数值型和类别型数据
609
+ - 支持缺失值处理""",
574
610
  field_descriptions={
575
- "file_path": "文件路径",
576
- "file_content": "文件内容",
577
- "file_format": "文件格式",
578
- "y_data": "因变量数据",
579
- "x_data": "自变量数据",
580
- "feature_names": "特征名称",
581
- "n_estimators": "树的数量",
582
- "max_depth": "最大深度"
583
- }
611
+ "file_path": "CSV/JSON文件路径。CSV格式: 最后一列为因变量,其余列为自变量",
612
+ "file_content": "文件内容字符串。JSON格式: {'y': [因变量], 'x1': [自变量1], ...}",
613
+ "file_format": "文件格式: csv/json/auto",
614
+ "y_data": "因变量数据列表,数值格式,如 [1.2, 3.4, 5.6, ...]",
615
+ "x_data": "自变量数据矩阵,二维列表格式,如 [[1, 2], [3, 4], [5, 6], ...]",
616
+ "feature_names": "自变量名称列表,如 ['GDP', 'Population', 'Investment']",
617
+ "n_estimators": "决策树数量,控制模型复杂度和稳定性,默认100",
618
+ "max_depth": "决策树最大深度,控制过拟合,默认None(无限制)"
619
+ },
620
+ examples=[
621
+ "预测房价与房屋特征的非线性关系",
622
+ "分析消费者行为与营销变量的复杂交互",
623
+ "评估经济指标对股票收益的影响"
624
+ ],
625
+ use_cases=[
626
+ "复杂非线性关系建模",
627
+ "特征重要性分析",
628
+ "稳健预测建模",
629
+ "大数据集处理",
630
+ "集成学习应用"
631
+ ]
584
632
  )
585
633
 
586
634
  GRADIENT_BOOSTING_REGRESSION_ANALYSIS = ToolDescription(
587
635
  name="gradient_boosting_regression_analysis",
588
- description="梯度提升树回归 - 支持文件输入",
636
+ description="""梯度提升树回归分析
637
+
638
+ 📊 功能说明:
639
+ 梯度提升树通过顺序构建决策树,每棵树修正前一棵树的错误,能够处理复杂的非线性关系。
640
+
641
+ 📈 算法特点:
642
+ - 顺序学习:每棵树学习前一棵树的残差
643
+ - 高精度:通常具有很高的预测精度
644
+ - 特征重要性:自动计算特征重要性
645
+ - 灵活性强:可处理各种类型的数据
646
+ - 正则化:内置正则化防止过拟合
647
+
648
+ 💡 适用场景:
649
+ - 高精度预测需求
650
+ - 复杂非线性关系
651
+ - 小样本高维数据
652
+ - 竞赛和性能要求高的场景
653
+ - 特征重要性分析
654
+
655
+ ⚠️ 注意事项:
656
+ - 对参数敏感,需要仔细调优
657
+ - 训练时间较长
658
+ - 可能过度拟合噪声数据
659
+ - 内存消耗较大
660
+
661
+ 🔧 参数建议:
662
+ - n_estimators: 树的数量,默认100
663
+ - 小数据集: 50-200
664
+ - 大数据集: 200-1000
665
+ - learning_rate: 学习率,默认0.1
666
+ - 保守学习: 0.01-0.1
667
+ - 快速收敛: 0.1-0.3
668
+ - max_depth: 最大深度,默认3
669
+ - 简单关系: 2-4
670
+ - 复杂关系: 5-8
671
+
672
+ 📋 数据要求:
673
+ - 至少10个样本
674
+ - 数值型和类别型数据
675
+ - 建议进行数据标准化""",
589
676
  field_descriptions={
590
- "file_path": "文件路径",
591
- "file_content": "文件内容",
592
- "file_format": "文件格式",
593
- "y_data": "因变量数据",
594
- "x_data": "自变量数据",
595
- "feature_names": "特征名称",
596
- "n_estimators": "树的数量",
597
- "learning_rate": "学习率",
598
- "max_depth": "最大深度"
599
- }
677
+ "file_path": "CSV/JSON文件路径。CSV格式: 最后一列为因变量,其余列为自变量",
678
+ "file_content": "文件内容字符串。JSON格式: {'y': [因变量], 'x1': [自变量1], ...}",
679
+ "file_format": "文件格式: csv/json/auto",
680
+ "y_data": "因变量数据列表,数值格式,如 [1.2, 3.4, 5.6, ...]",
681
+ "x_data": "自变量数据矩阵,二维列表格式,如 [[1, 2], [3, 4], [5, 6], ...]",
682
+ "feature_names": "自变量名称列表,如 ['GDP', 'Population', 'Investment']",
683
+ "n_estimators": "提升阶段执行的树数量,控制模型复杂度,默认100",
684
+ "learning_rate": "学习率,控制每棵树的贡献程度,默认0.1",
685
+ "max_depth": "单个回归估计器的最大深度,控制过拟合,默认3"
686
+ },
687
+ examples=[
688
+ "高精度预测股票价格走势",
689
+ "分析复杂的经济指标关系",
690
+ "预测消费者购买行为的精确概率",
691
+ "竞赛级别的预测建模"
692
+ ],
693
+ use_cases=[
694
+ "高精度预测建模",
695
+ "复杂非线性关系分析",
696
+ "特征重要性评估",
697
+ "小样本高维数据处理",
698
+ "竞赛级别模型构建"
699
+ ]
600
700
  )
601
701
 
602
702
  LASSO_REGRESSION_ANALYSIS = ToolDescription(
@@ -320,7 +320,7 @@ async def handle_panel_hausman_test(ctx, y_data, x_data, entity_ids, time_period
320
320
 
321
321
  async def handle_panel_unit_root_test(ctx, **kwargs):
322
322
  """
323
- 处理面板单位根检验
323
+ 处理面板单位根检验 - 统一输出格式
324
324
 
325
325
  panel_unit_root_test函数期望:data, entity_ids, time_periods
326
326
  但panel装饰器会传入:y_data, x_data, entity_ids, time_periods
@@ -344,68 +344,310 @@ async def handle_panel_unit_root_test(ctx, **kwargs):
344
344
 
345
345
  # 只传递panel_unit_root_test需要的参数
346
346
  result = panel_unit_root_test(data, entity_ids, time_periods, test_type)
347
+
348
+ # 构建详细的结果文本
349
+ result_text = f"""📊 面板单位根检验结果
350
+
351
+ 🔍 检验信息:
352
+ - 检验方法 = {test_type.upper()}
353
+ - 个体数量 = {len(set(entity_ids))}
354
+ - 时间期数 = {len(set(time_periods))}
355
+ - 检验统计量 = {result.statistic:.4f}
356
+ - p值 = {result.p_value:.4f}
357
+ - 平稳性 = {'平稳' if result.stationary else '非平稳'} (5%水平)
358
+
359
+ 📈 检验详情:"""
360
+
361
+ # 添加检验详情信息
362
+ if hasattr(result, 'critical_values'):
363
+ result_text += f"\n- 临界值: {result.critical_values}"
364
+ if hasattr(result, 'lags_used'):
365
+ result_text += f"\n- 使用滞后阶数: {result.lags_used}"
366
+ if hasattr(result, 'test_statistic'):
367
+ result_text += f"\n- 检验统计量: {result.test_statistic:.4f}"
368
+
369
+ result_text += f"\n\n💡 检验说明:面板单位根检验用于判断面板数据是否平稳,是面板数据分析的重要前提检验。"
370
+ result_text += f"\n\n⚠️ 注意事项:如果数据非平稳,需要进行差分处理或使用面板协整检验。"
371
+
347
372
  return CallToolResult(
348
- content=[TextContent(type="text", text=f"面板单位根检验: {'平稳' if result.stationary else '非平稳'}")],
373
+ content=[TextContent(type="text", text=result_text)],
349
374
  structuredContent=result.model_dump()
350
375
  )
351
376
 
352
377
 
353
378
  # 时间序列处理器
354
379
  async def handle_var_model(ctx, data, max_lags=5, ic="aic", **kwargs):
380
+ """处理VAR模型分析 - 统一输出格式"""
355
381
  result = var_model(data, max_lags=max_lags, ic=ic)
382
+
383
+ # 构建详细的结果文本
384
+ result_text = f"""📊 VAR模型分析结果
385
+
386
+ 🔍 模型基本信息:
387
+ - 最优滞后阶数 = {result.order}
388
+ - 变量数量 = {len(result.variables) if hasattr(result, 'variables') else '未知'}
389
+ - 信息准则 = {ic.upper()}
390
+ - AIC = {result.aic:.2f}
391
+ - BIC = {getattr(result, 'bic', 'N/A')}
392
+ - HQIC = {getattr(result, 'hqic', 'N/A')}
393
+
394
+ 📈 模型诊断信息:"""
395
+
396
+ # 添加模型诊断信息
397
+ if hasattr(result, 'residuals_normality'):
398
+ result_text += f"\n- 残差正态性检验: {result.residuals_normality}"
399
+ if hasattr(result, 'serial_correlation'):
400
+ result_text += f"\n- 序列相关性检验: {result.serial_correlation}"
401
+ if hasattr(result, 'stability'):
402
+ result_text += f"\n- 模型稳定性: {result.stability}"
403
+
404
+ # 添加变量信息
405
+ if hasattr(result, 'variables'):
406
+ result_text += f"\n\n🔬 分析变量:"
407
+ for var in result.variables:
408
+ result_text += f"\n- {var}"
409
+
410
+ result_text += f"\n\n💡 模型说明:VAR模型用于分析多个时间序列变量间的动态关系,能够捕捉变量间的相互影响和滞后效应。"
411
+ result_text += f"\n\n⚠️ 注意事项:VAR模型假设所有变量都是内生的,适用于分析变量间的动态交互关系。"
412
+
356
413
  return CallToolResult(
357
- content=[TextContent(type="text", text=f"VAR模型: 滞后阶数={result.order}, AIC={result.aic:.2f}")],
414
+ content=[TextContent(type="text", text=result_text)],
358
415
  structuredContent=result.model_dump()
359
416
  )
360
417
 
361
418
 
362
419
  async def handle_vecm_model(ctx, data, coint_rank=1, deterministic="co", max_lags=5, **kwargs):
420
+ """处理VECM模型分析 - 统一输出格式"""
363
421
  result = vecm_model(data, coint_rank=coint_rank, deterministic=deterministic, max_lags=max_lags)
422
+
423
+ # 构建详细的结果文本
424
+ result_text = f"""📊 VECM模型分析结果
425
+
426
+ 🔍 模型基本信息:
427
+ - 协整秩 = {result.coint_rank}
428
+ - 确定性项类型 = {deterministic}
429
+ - 最大滞后阶数 = {max_lags}
430
+ - AIC = {result.aic:.2f}
431
+ - BIC = {getattr(result, 'bic', 'N/A')}
432
+ - HQIC = {getattr(result, 'hqic', 'N/A')}
433
+
434
+ 📈 协整关系分析:"""
435
+
436
+ # 添加协整关系信息
437
+ if hasattr(result, 'coint_relations'):
438
+ result_text += f"\n- 协整关系数量: {len(result.coint_relations)}"
439
+ for i, relation in enumerate(result.coint_relations[:3], 1): # 显示前3个关系
440
+ result_text += f"\n- 关系{i}: {relation}"
441
+ if len(result.coint_relations) > 3:
442
+ result_text += f"\n- ... 还有{len(result.coint_relations) - 3}个协整关系"
443
+
444
+ # 添加误差修正项信息
445
+ if hasattr(result, 'error_correction'):
446
+ result_text += f"\n\n🔧 误差修正机制:"
447
+ result_text += f"\n- 误差修正项显著性: {result.error_correction}"
448
+
449
+ result_text += f"\n\n💡 模型说明:VECM模型用于分析非平稳时间序列的长期均衡关系,包含误差修正机制来反映短期调整过程。"
450
+ result_text += f"\n\n⚠️ 注意事项:VECM模型要求变量间存在协整关系,适用于分析经济变量的长期均衡和短期动态调整。"
451
+
364
452
  return CallToolResult(
365
- content=[TextContent(type="text", text=f"VECM模型: 协整秩={result.coint_rank}, AIC={result.aic:.2f}")],
453
+ content=[TextContent(type="text", text=result_text)],
366
454
  structuredContent=result.model_dump()
367
455
  )
368
456
 
369
457
 
370
458
  async def handle_garch_model(ctx, data, order=(1, 1), dist="normal", **kwargs):
459
+ """处理GARCH模型分析 - 统一输出格式"""
371
460
  result = garch_model(data, order=order, dist=dist)
461
+
462
+ # 构建详细的结果文本
463
+ result_text = f"""📊 GARCH模型分析结果
464
+
465
+ 🔍 模型基本信息:
466
+ - GARCH阶数 = ({order[0]}, {order[1]})
467
+ - 误差分布 = {dist}
468
+ - 持久性 = {result.persistence:.4f}
469
+ - AIC = {result.aic:.2f}
470
+ - BIC = {getattr(result, 'bic', 'N/A')}
471
+
472
+ 📈 波动率特征:"""
473
+
474
+ # 添加波动率特征信息
475
+ if hasattr(result, 'volatility_persistence'):
476
+ result_text += f"\n- 波动率持续性: {result.volatility_persistence:.4f}"
477
+ if hasattr(result, 'unconditional_variance'):
478
+ result_text += f"\n- 无条件方差: {result.unconditional_variance:.4f}"
479
+ if hasattr(result, 'leverage_effect'):
480
+ result_text += f"\n- 杠杆效应: {result.leverage_effect}"
481
+
482
+ # 添加模型诊断信息
483
+ if hasattr(result, 'residuals_test'):
484
+ result_text += f"\n\n🔧 模型诊断:"
485
+ result_text += f"\n- 残差检验: {result.residuals_test}"
486
+
487
+ result_text += f"\n\n💡 模型说明:GARCH模型用于分析金融时间序列的波动率聚类现象,能够捕捉条件异方差性。"
488
+ result_text += f"\n\n⚠️ 注意事项:GARCH模型适用于金融数据波动率建模,阶数选择影响模型对波动率持续性的捕捉能力。"
489
+
372
490
  return CallToolResult(
373
- content=[TextContent(type="text", text=f"GARCH模型: 持久性={result.persistence:.4f}")],
491
+ content=[TextContent(type="text", text=result_text)],
374
492
  structuredContent=result.model_dump()
375
493
  )
376
494
 
377
495
 
378
- async def handle_state_space_model(ctx, data, state_dim=1, observation_dim=1,
496
+ async def handle_state_space_model(ctx, data, state_dim=1, observation_dim=1,
379
497
  trend=True, seasonal=False, period=12, **kwargs):
498
+ """处理状态空间模型分析 - 统一输出格式"""
380
499
  result = state_space_model(data, state_dim, observation_dim, trend, seasonal, period)
500
+
501
+ # 构建详细的结果文本
502
+ result_text = f"""📊 状态空间模型分析结果
503
+
504
+ 🔍 模型结构信息:
505
+ - 状态维度 = {result.state_dim}
506
+ - 观测维度 = {result.observation_dim}
507
+ - 趋势项 = {'包含' if result.trend else '不包含'}
508
+ - 季节项 = {'包含' if result.seasonal else '不包含'}
509
+ - 季节周期 = {result.period if result.seasonal else 'N/A'}
510
+ - AIC = {result.aic:.2f}
511
+ - BIC = {getattr(result, 'bic', 'N/A')}
512
+
513
+ 📈 模型拟合信息:"""
514
+
515
+ # 添加模型拟合信息
516
+ if hasattr(result, 'log_likelihood'):
517
+ result_text += f"\n- 对数似然值: {result.log_likelihood:.2f}"
518
+ if hasattr(result, 'converged'):
519
+ result_text += f"\n- 收敛状态: {'已收敛' if result.converged else '未收敛'}"
520
+ if hasattr(result, 'smoothing_error'):
521
+ result_text += f"\n- 平滑误差: {result.smoothing_error:.4f}"
522
+
523
+ result_text += f"\n\n💡 模型说明:状态空间模型用于分析时间序列的潜在状态和观测关系,能够处理复杂的动态系统。"
524
+ result_text += f"\n\n⚠️ 注意事项:状态空间模型适用于分析具有潜在状态的时间序列,参数估计可能对初始值敏感。"
525
+
381
526
  return CallToolResult(
382
- content=[TextContent(type="text", text=f"状态空间模型: AIC={result.aic:.2f}")],
527
+ content=[TextContent(type="text", text=result_text)],
383
528
  structuredContent=result.model_dump()
384
529
  )
385
530
 
386
531
 
387
532
  async def handle_variance_decomposition(ctx, data, periods=10, max_lags=5, **kwargs):
533
+ """处理方差分解分析 - 统一输出格式"""
388
534
  result = variance_decomposition(data, periods=periods, max_lags=max_lags)
535
+
536
+ # 构建详细的结果文本
537
+ result_text = f"""📊 方差分解分析结果
538
+
539
+ 🔍 分析设置:
540
+ - 分解期数 = {periods}
541
+ - 最大滞后阶数 = {max_lags}
542
+ - 变量数量 = {len(result) if isinstance(result, dict) else '未知'}
543
+
544
+ 📈 方差分解结果:"""
545
+
546
+ # 添加方差分解结果
547
+ if isinstance(result, dict):
548
+ for var_name, decomposition in result.items():
549
+ if isinstance(decomposition, dict):
550
+ result_text += f"\n\n🔬 变量 '{var_name}' 的方差来源:"
551
+ for source, percentage in decomposition.items():
552
+ result_text += f"\n- {source}: {percentage:.1f}%"
553
+ else:
554
+ result_text += f"\n- {var_name}: {decomposition}"
555
+ else:
556
+ result_text += f"\n- 结果: {result}"
557
+
558
+ result_text += f"\n\n💡 分析说明:方差分解用于分析多变量系统中各变量对预测误差方差的贡献程度。"
559
+ result_text += f"\n\n⚠️ 注意事项:方差分解结果依赖于模型的滞后阶数选择,不同期数的分解结果可能不同。"
560
+
389
561
  return CallToolResult(
390
- content=[TextContent(type="text", text=f"方差分解: {periods}期")],
562
+ content=[TextContent(type="text", text=result_text)],
391
563
  structuredContent=result
392
564
  )
393
565
 
394
566
 
395
567
  # 机器学习处理器
396
568
  async def handle_random_forest(ctx, y_data, x_data, feature_names=None, n_estimators=100, max_depth=None, **kwargs):
569
+ """处理随机森林回归 - 统一输出格式"""
397
570
  result = random_forest_regression(y_data, x_data, feature_names, n_estimators, max_depth)
571
+
572
+ # 检查R²是否为负值
573
+ r2_warning = ""
574
+ if result.r2_score < 0:
575
+ r2_warning = f"\n⚠️ 警告:R²为负值({result.r2_score:.4f}),表明模型性能比简单均值预测更差。建议:1) 检查数据质量 2) 增加样本数量 3) 调整模型参数"
576
+
577
+ # 构建详细的结果文本
578
+ result_text = f"""📊 随机森林回归分析结果
579
+
580
+ 🔍 模型拟合信息:
581
+ - R² = {result.r2_score:.4f}
582
+ - 均方误差(MSE) = {result.mse:.4f}
583
+ - 平均绝对误差(MAE) = {result.mae:.4f}
584
+ - 样本数量 = {result.n_obs}
585
+ - 树的数量 = {result.n_estimators}
586
+ - 最大深度 = {result.max_depth if result.max_depth else '无限制'}
587
+ - 袋外得分 = {f"{result.oob_score:.4f}" if result.oob_score else '未计算'}
588
+ {r2_warning}
589
+
590
+ 📈 特征重要性(前10个):"""
591
+
592
+ # 添加特征重要性信息,按重要性排序
593
+ if result.feature_importance:
594
+ sorted_features = sorted(result.feature_importance.items(), key=lambda x: x[1], reverse=True)
595
+ for i, (feature, importance) in enumerate(sorted_features[:10]):
596
+ result_text += f"\n- {feature}: {importance:.4f}"
597
+ if len(sorted_features) > 10:
598
+ result_text += f"\n- ... 还有{len(sorted_features) - 10}个特征"
599
+ else:
600
+ result_text += "\n- 特征重要性未计算"
601
+
602
+ result_text += f"\n\n💡 模型说明:随机森林通过构建多个决策树并集成结果,能够处理非线性关系和特征交互,对异常值稳健且不易过拟合。"
603
+ result_text += f"\n\n⚠️ 注意事项:随机森林是黑盒模型,可解释性较差,但预测性能通常较好。"
604
+
398
605
  return CallToolResult(
399
- content=[TextContent(type="text", text=f"随机森林: R²={result.r2_score:.4f}")],
606
+ content=[TextContent(type="text", text=result_text)],
400
607
  structuredContent=result.model_dump()
401
608
  )
402
609
 
403
610
 
404
- async def handle_gradient_boosting(ctx, y_data, x_data, feature_names=None,
611
+ async def handle_gradient_boosting(ctx, y_data, x_data, feature_names=None,
405
612
  n_estimators=100, learning_rate=0.1, max_depth=3, **kwargs):
613
+ """处理梯度提升树回归 - 统一输出格式"""
406
614
  result = gradient_boosting_regression(y_data, x_data, feature_names, n_estimators, learning_rate, max_depth)
615
+
616
+ # 检查R²是否为负值
617
+ r2_warning = ""
618
+ if result.r2_score < 0:
619
+ r2_warning = f"\n⚠️ 警告:R²为负值({result.r2_score:.4f}),表明模型性能比简单均值预测更差。建议:1) 检查数据质量 2) 增加样本数量 3) 调整模型参数"
620
+
621
+ # 构建详细的结果文本
622
+ result_text = f"""📊 梯度提升树回归分析结果
623
+
624
+ 🔍 模型拟合信息:
625
+ - R² = {result.r2_score:.4f}
626
+ - 均方误差(MSE) = {result.mse:.4f}
627
+ - 平均绝对误差(MAE) = {result.mae:.4f}
628
+ - 样本数量 = {result.n_obs}
629
+ - 树的数量 = {result.n_estimators}
630
+ - 学习率 = {result.learning_rate}
631
+ - 最大深度 = {result.max_depth}
632
+ {r2_warning}
633
+
634
+ 📈 特征重要性(前10个):"""
635
+
636
+ # 添加特征重要性信息,按重要性排序
637
+ if result.feature_importance:
638
+ sorted_features = sorted(result.feature_importance.items(), key=lambda x: x[1], reverse=True)
639
+ for i, (feature, importance) in enumerate(sorted_features[:10]):
640
+ result_text += f"\n- {feature}: {importance:.4f}"
641
+ if len(sorted_features) > 10:
642
+ result_text += f"\n- ... 还有{len(sorted_features) - 10}个特征"
643
+ else:
644
+ result_text += "\n- 特征重要性未计算"
645
+
646
+ result_text += f"\n\n💡 模型说明:梯度提升树通过顺序构建决策树,每棵树修正前一棵树的错误,能够处理复杂的非线性关系,通常具有很高的预测精度。"
647
+ result_text += f"\n\n⚠️ 注意事项:梯度提升树对参数敏感,需要仔细调优,训练时间较长但预测性能优秀。"
648
+
407
649
  return CallToolResult(
408
- content=[TextContent(type="text", text=f"梯度提升树: R²={result.r2_score:.4f}")],
650
+ content=[TextContent(type="text", text=result_text)],
409
651
  structuredContent=result.model_dump()
410
652
  )
411
653
 
@@ -491,16 +733,81 @@ async def handle_ridge_regression(ctx, y_data, x_data, feature_names=None, alpha
491
733
 
492
734
 
493
735
  async def handle_cross_validation(ctx, y_data, x_data, model_type="random_forest", cv_folds=5, scoring="r2", **kwargs):
736
+ """处理交叉验证 - 统一输出格式"""
494
737
  result = cross_validation(y_data, x_data, model_type, cv_folds, scoring)
738
+
739
+ # 构建详细的结果文本
740
+ result_text = f"""📊 交叉验证分析结果
741
+
742
+ 🔍 验证信息:
743
+ - 模型类型 = {result.model_type}
744
+ - 交叉验证折数 = {result.n_splits}
745
+ - 评分指标 = {scoring}
746
+ - 平均得分 = {result.mean_score:.4f}
747
+ - 得分标准差 = {result.std_score:.4f}
748
+ - 变异系数 = {(result.std_score / abs(result.mean_score)) * 100 if result.mean_score != 0 else 0:.2f}%
749
+
750
+ 📈 各折得分详情:"""
751
+
752
+ # 添加各折得分
753
+ for i, score in enumerate(result.cv_scores, 1):
754
+ result_text += f"\n- 第{i}折: {score:.4f}"
755
+
756
+ # 评估模型稳定性
757
+ stability_assessment = ""
758
+ cv_threshold = 0.1 # 10%的变异系数阈值
759
+ cv_value = (result.std_score / abs(result.mean_score)) if result.mean_score != 0 else 0
760
+
761
+ if cv_value < cv_threshold:
762
+ stability_assessment = f"\n\n✅ 模型稳定性:优秀(变异系数{cv_value*100:.2f}% < {cv_threshold*100:.0f}%)"
763
+ elif cv_value < cv_threshold * 2:
764
+ stability_assessment = f"\n\n⚠️ 模型稳定性:一般(变异系数{cv_value*100:.2f}% 在{cv_threshold*100:.0f}%-{cv_threshold*2*100:.0f}%之间)"
765
+ else:
766
+ stability_assessment = f"\n\n❌ 模型稳定性:较差(变异系数{cv_value*100:.2f}% > {cv_threshold*2*100:.0f}%)"
767
+
768
+ result_text += stability_assessment
769
+ result_text += f"\n\n💡 模型说明:交叉验证通过将数据分成多个子集进行训练和测试,评估模型的泛化能力和稳定性。"
770
+ result_text += f"\n\n⚠️ 注意事项:变异系数越小表明模型越稳定,建议选择变异系数小于10%的模型。"
771
+
495
772
  return CallToolResult(
496
- content=[TextContent(type="text", text=f"交叉验证: 平均得分={result.mean_score:.4f}")],
773
+ content=[TextContent(type="text", text=result_text)],
497
774
  structuredContent=result.model_dump()
498
775
  )
499
776
 
500
777
 
501
778
  async def handle_feature_importance(ctx, y_data, x_data, feature_names=None, method="random_forest", top_k=5, **kwargs):
779
+ """处理特征重要性分析 - 统一输出格式"""
502
780
  result = feature_importance_analysis(y_data, x_data, feature_names, method, top_k)
781
+
782
+ # 构建详细的结果文本
783
+ result_text = f"""📊 特征重要性分析结果
784
+
785
+ 🔍 分析信息:
786
+ - 分析方法 = {method}
787
+ - 显示Top特征数量 = {top_k}
788
+ - 总特征数量 = {len(result.feature_importance)}
789
+
790
+ 📈 特征重要性排名:"""
791
+
792
+ # 添加特征重要性信息
793
+ for i, (feature, importance) in enumerate(result.sorted_features[:top_k], 1):
794
+ percentage = (importance / sum(result.feature_importance.values())) * 100 if sum(result.feature_importance.values()) > 0 else 0
795
+ result_text += f"\n{i}. {feature}: {importance:.4f} ({percentage:.1f}%)"
796
+
797
+ # 添加重要性分布信息
798
+ if len(result.sorted_features) > 0:
799
+ top_k_importance = sum(imp for _, imp in result.sorted_features[:top_k])
800
+ total_importance = sum(result.feature_importance.values())
801
+ top_k_percentage = (top_k_importance / total_importance) * 100 if total_importance > 0 else 0
802
+
803
+ result_text += f"\n\n📊 重要性分布:"
804
+ result_text += f"\n- Top {top_k}特征累计重要性: {top_k_percentage:.1f}%"
805
+ result_text += f"\n- 剩余特征重要性: {100 - top_k_percentage:.1f}%"
806
+
807
+ result_text += f"\n\n💡 分析说明:特征重要性分析帮助识别对预测目标最重要的变量,可用于特征选择和模型解释。"
808
+ result_text += f"\n\n⚠️ 注意事项:不同方法计算的特征重要性可能不同,建议结合业务知识进行解释。"
809
+
503
810
  return CallToolResult(
504
- content=[TextContent(type="text", text=f"特征重要性: Top特征={result.top_features}")],
811
+ content=[TextContent(type="text", text=result_text)],
505
812
  structuredContent=result.model_dump()
506
813
  )
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aigroup-econ-mcp
3
- Version: 0.7.0
4
- Summary: 专业计量经济学MCP工具 - 让大模型直接进行数据分析(优化版:增强工具描述,提升大模型调用体验)
3
+ Version: 0.8.0
4
+ Summary: 专业计量经济学MCP工具 - 让大模型直接进行数据分析(优化版:统一输出格式,增强模型说明)
5
5
  Project-URL: Homepage, https://github.com/aigroup/aigroup-econ-mcp
6
6
  Project-URL: Repository, https://github.com/aigroup/aigroup-econ-mcp.git
7
7
  Project-URL: Issues, https://github.com/aigroup/aigroup-econ-mcp/issues
@@ -19,12 +19,12 @@ aigroup_econ_mcp/tools/regression.py,sha256=uMGRGUQo4mU1sb8fwpP2FpkCqt_e9AtqEtUp
19
19
  aigroup_econ_mcp/tools/statistics.py,sha256=2cHgNSUXwPYPLxntVOEOL8yF-x92mrgjK-R8kkxDihg,4239
20
20
  aigroup_econ_mcp/tools/time_series.py,sha256=LNCO0bYXLPilQ2kSVXA3woNp8ERVq7n3jaoQhWgTCJQ,21763
21
21
  aigroup_econ_mcp/tools/timeout.py,sha256=vNnGsR0sXW1xvIbKCF-qPUU3QNDAn_MaQgSxbGxkfW4,8404
22
- aigroup_econ_mcp/tools/tool_descriptions.py,sha256=yJ6c9Ue3r9HAh3o2t2aGQUu6xfZwJE8B6wC6cqDypDI,28717
23
- aigroup_econ_mcp/tools/tool_handlers.py,sha256=HZz_AvDtoMzqRmpu6ibZaEUEVUlqsLNifTdlVHEtInk,20613
22
+ aigroup_econ_mcp/tools/tool_descriptions.py,sha256=Oj_14_79AB8Ku64mV0cdoV5f2-UFx-0NY3Xxjj6L-1A,32506
23
+ aigroup_econ_mcp/tools/tool_handlers.py,sha256=RUXCB8dYkS2sbn7pKl3WPI70HQHwCDoy0hEmQMJ8rbs,34399
24
24
  aigroup_econ_mcp/tools/tool_registry.py,sha256=4SFpMnReZyGfEHCCDnojwHIUEpuQICS9M2u_9xuoUck,4413
25
25
  aigroup_econ_mcp/tools/validation.py,sha256=F7LHwog5xtFIMjD9D48kd8jAF5MsZb7wjdrgaOg8EKo,16657
26
- aigroup_econ_mcp-0.7.0.dist-info/METADATA,sha256=_GY3y5qGca64s-WWHsdw59nT7aG0wUEZgpLdrnFKvzo,10866
27
- aigroup_econ_mcp-0.7.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
28
- aigroup_econ_mcp-0.7.0.dist-info/entry_points.txt,sha256=j5ZJYOc4lAZV-X3XkAuGhzHtIRcJtZ6Gz8ZKPY_QTrM,62
29
- aigroup_econ_mcp-0.7.0.dist-info/licenses/LICENSE,sha256=DoyCJUWlDzKbqc5KRbFpsGYLwLh-XJRHKQDoITjb1yc,1083
30
- aigroup_econ_mcp-0.7.0.dist-info/RECORD,,
26
+ aigroup_econ_mcp-0.8.0.dist-info/METADATA,sha256=7ByVxeiktZPL809uJSH7zKG59f6-1zAzb7uSpxT-Usc,10857
27
+ aigroup_econ_mcp-0.8.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
28
+ aigroup_econ_mcp-0.8.0.dist-info/entry_points.txt,sha256=j5ZJYOc4lAZV-X3XkAuGhzHtIRcJtZ6Gz8ZKPY_QTrM,62
29
+ aigroup_econ_mcp-0.8.0.dist-info/licenses/LICENSE,sha256=DoyCJUWlDzKbqc5KRbFpsGYLwLh-XJRHKQDoITjb1yc,1083
30
+ aigroup_econ_mcp-0.8.0.dist-info/RECORD,,