aigroup-econ-mcp 1.3.3__py3-none-any.whl → 1.4.3__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.
- .gitignore +253 -0
- PKG-INFO +710 -0
- README.md +672 -0
- __init__.py +14 -0
- aigroup_econ_mcp-1.4.3.dist-info/METADATA +710 -0
- aigroup_econ_mcp-1.4.3.dist-info/RECORD +92 -0
- aigroup_econ_mcp-1.4.3.dist-info/entry_points.txt +2 -0
- aigroup_econ_mcp-1.4.3.dist-info/licenses/LICENSE +21 -0
- cli.py +28 -0
- econometrics/README.md +18 -0
- econometrics/__init__.py +191 -0
- econometrics/advanced_methods/modern_computing_machine_learning/__init__.py +0 -0
- econometrics/basic_parametric_estimation/__init__.py +31 -0
- econometrics/basic_parametric_estimation/gmm/__init__.py +13 -0
- econometrics/basic_parametric_estimation/gmm/gmm_model.py +256 -0
- econometrics/basic_parametric_estimation/mle/__init__.py +13 -0
- econometrics/basic_parametric_estimation/mle/mle_model.py +241 -0
- econometrics/basic_parametric_estimation/ols/__init__.py +13 -0
- econometrics/basic_parametric_estimation/ols/ols_model.py +141 -0
- econometrics/causal_inference/causal_identification_strategy/__init__.py +0 -0
- econometrics/missing_data/missing_data_measurement_error/__init__.py +0 -0
- econometrics/model_specification_diagnostics_robust_inference/README.md +173 -0
- econometrics/model_specification_diagnostics_robust_inference/__init__.py +78 -0
- econometrics/model_specification_diagnostics_robust_inference/diagnostic_tests/__init__.py +20 -0
- econometrics/model_specification_diagnostics_robust_inference/diagnostic_tests/diagnostic_tests_model.py +149 -0
- econometrics/model_specification_diagnostics_robust_inference/generalized_least_squares/__init__.py +15 -0
- econometrics/model_specification_diagnostics_robust_inference/generalized_least_squares/gls_model.py +130 -0
- econometrics/model_specification_diagnostics_robust_inference/model_selection/__init__.py +18 -0
- econometrics/model_specification_diagnostics_robust_inference/model_selection/model_selection_model.py +286 -0
- econometrics/model_specification_diagnostics_robust_inference/regularization/__init__.py +15 -0
- econometrics/model_specification_diagnostics_robust_inference/regularization/regularization_model.py +177 -0
- econometrics/model_specification_diagnostics_robust_inference/robust_errors/__init__.py +15 -0
- econometrics/model_specification_diagnostics_robust_inference/robust_errors/robust_errors_model.py +122 -0
- econometrics/model_specification_diagnostics_robust_inference/simultaneous_equations/__init__.py +15 -0
- econometrics/model_specification_diagnostics_robust_inference/simultaneous_equations/simultaneous_equations_model.py +246 -0
- econometrics/model_specification_diagnostics_robust_inference/weighted_least_squares/__init__.py +15 -0
- econometrics/model_specification_diagnostics_robust_inference/weighted_least_squares/wls_model.py +127 -0
- econometrics/nonparametric/nonparametric_semiparametric_methods/__init__.py +0 -0
- econometrics/spatial_econometrics/spatial_econometrics_new/__init__.py +0 -0
- econometrics/specific_data_modeling/micro_discrete_limited_data/__init__.py +0 -0
- econometrics/specific_data_modeling/survival_duration_data/__init__.py +0 -0
- econometrics/specific_data_modeling/time_series_panel_data/__init__.py +143 -0
- econometrics/specific_data_modeling/time_series_panel_data/arima_model.py +104 -0
- econometrics/specific_data_modeling/time_series_panel_data/cointegration_vecm.py +334 -0
- econometrics/specific_data_modeling/time_series_panel_data/dynamic_panel_models.py +653 -0
- econometrics/specific_data_modeling/time_series_panel_data/exponential_smoothing.py +176 -0
- econometrics/specific_data_modeling/time_series_panel_data/garch_model.py +198 -0
- econometrics/specific_data_modeling/time_series_panel_data/panel_diagnostics.py +125 -0
- econometrics/specific_data_modeling/time_series_panel_data/panel_var.py +60 -0
- econometrics/specific_data_modeling/time_series_panel_data/structural_break_tests.py +87 -0
- econometrics/specific_data_modeling/time_series_panel_data/time_varying_parameter_models.py +106 -0
- econometrics/specific_data_modeling/time_series_panel_data/unit_root_tests.py +204 -0
- econometrics/specific_data_modeling/time_series_panel_data/var_svar_model.py +372 -0
- econometrics/statistical_inference/statistical_inference_techniques/__init__.py +0 -0
- econometrics/statistics/distribution_decomposition_methods/__init__.py +0 -0
- econometrics/tests/basic_parametric_estimation_tests/__init__.py +3 -0
- econometrics/tests/basic_parametric_estimation_tests/test_gmm.py +128 -0
- econometrics/tests/basic_parametric_estimation_tests/test_mle.py +127 -0
- econometrics/tests/basic_parametric_estimation_tests/test_ols.py +100 -0
- econometrics/tests/model_specification_diagnostics_tests/__init__.py +3 -0
- econometrics/tests/model_specification_diagnostics_tests/test_diagnostic_tests.py +86 -0
- econometrics/tests/model_specification_diagnostics_tests/test_robust_errors.py +89 -0
- econometrics/tests/specific_data_modeling_tests/__init__.py +3 -0
- econometrics/tests/specific_data_modeling_tests/test_arima.py +98 -0
- econometrics/tests/specific_data_modeling_tests/test_dynamic_panel.py +198 -0
- econometrics/tests/specific_data_modeling_tests/test_exponential_smoothing.py +105 -0
- econometrics/tests/specific_data_modeling_tests/test_garch.py +118 -0
- econometrics/tests/specific_data_modeling_tests/test_unit_root.py +156 -0
- econometrics/tests/specific_data_modeling_tests/test_var.py +124 -0
- prompts/__init__.py +0 -0
- prompts/analysis_guides.py +43 -0
- pyproject.toml +78 -0
- resources/MCP_MASTER_GUIDE.md +422 -0
- resources/MCP_TOOLS_DATA_FORMAT_GUIDE.md +185 -0
- resources/__init__.py +0 -0
- server.py +83 -0
- tools/README.md +88 -0
- tools/__init__.py +45 -0
- tools/data_loader.py +213 -0
- tools/decorators.py +38 -0
- tools/econometrics_adapter.py +286 -0
- tools/mcp_tool_groups/__init__.py +1 -0
- tools/mcp_tool_groups/basic_parametric_tools.py +173 -0
- tools/mcp_tool_groups/model_specification_tools.py +402 -0
- tools/mcp_tool_groups/time_series_tools.py +494 -0
- tools/mcp_tools_registry.py +114 -0
- tools/model_specification_adapter.py +369 -0
- tools/output_formatter.py +563 -0
- tools/time_series_panel_data_adapter.py +858 -0
- tools/time_series_panel_data_tools.py +65 -0
- aigroup_econ_mcp/__init__.py +0 -19
- aigroup_econ_mcp/cli.py +0 -82
- aigroup_econ_mcp/config.py +0 -561
- aigroup_econ_mcp/server.py +0 -452
- aigroup_econ_mcp/tools/__init__.py +0 -19
- aigroup_econ_mcp/tools/base.py +0 -470
- aigroup_econ_mcp/tools/cache.py +0 -533
- aigroup_econ_mcp/tools/data_loader.py +0 -195
- aigroup_econ_mcp/tools/file_parser.py +0 -1027
- aigroup_econ_mcp/tools/machine_learning.py +0 -60
- aigroup_econ_mcp/tools/ml_ensemble.py +0 -210
- aigroup_econ_mcp/tools/ml_evaluation.py +0 -272
- aigroup_econ_mcp/tools/ml_models.py +0 -54
- aigroup_econ_mcp/tools/ml_regularization.py +0 -186
- aigroup_econ_mcp/tools/monitoring.py +0 -555
- aigroup_econ_mcp/tools/optimized_example.py +0 -229
- aigroup_econ_mcp/tools/panel_data.py +0 -619
- aigroup_econ_mcp/tools/regression.py +0 -214
- aigroup_econ_mcp/tools/statistics.py +0 -154
- aigroup_econ_mcp/tools/time_series.py +0 -698
- aigroup_econ_mcp/tools/timeout.py +0 -283
- aigroup_econ_mcp/tools/tool_descriptions.py +0 -410
- aigroup_econ_mcp/tools/tool_handlers.py +0 -1016
- aigroup_econ_mcp/tools/tool_registry.py +0 -478
- aigroup_econ_mcp/tools/validation.py +0 -482
- aigroup_econ_mcp-1.3.3.dist-info/METADATA +0 -525
- aigroup_econ_mcp-1.3.3.dist-info/RECORD +0 -30
- aigroup_econ_mcp-1.3.3.dist-info/entry_points.txt +0 -2
- /aigroup_econ_mcp-1.3.3.dist-info/licenses/LICENSE → /LICENSE +0 -0
- {aigroup_econ_mcp-1.3.3.dist-info → aigroup_econ_mcp-1.4.3.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
"""
|
|
2
|
+
模型规范、诊断和稳健推断适配器
|
|
3
|
+
将econometrics/model_specification_diagnostics_robust_inference中的模型适配为MCP工具
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from typing import List, Optional, Union, Dict, Any
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
import json
|
|
10
|
+
|
|
11
|
+
# 确保可以导入econometrics模块
|
|
12
|
+
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
13
|
+
|
|
14
|
+
# 导入模型规范、诊断和稳健推断模型
|
|
15
|
+
from econometrics.model_specification_diagnostics_robust_inference.diagnostic_tests.diagnostic_tests_model import (
|
|
16
|
+
diagnostic_tests as core_diagnostic_tests,
|
|
17
|
+
DiagnosticTestsResult as CoreDiagnosticTestsResult
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
from econometrics.model_specification_diagnostics_robust_inference.generalized_least_squares.gls_model import (
|
|
21
|
+
gls_regression as core_gls_regression,
|
|
22
|
+
GLSResult as CoreGLSResult
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
from econometrics.model_specification_diagnostics_robust_inference.weighted_least_squares.wls_model import (
|
|
26
|
+
wls_regression as core_wls_regression,
|
|
27
|
+
WLSResult as CoreWLSResult
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
from econometrics.model_specification_diagnostics_robust_inference.robust_errors.robust_errors_model import (
|
|
31
|
+
robust_errors_regression as core_robust_errors_regression,
|
|
32
|
+
RobustErrorsResult as CoreRobustErrorsResult
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
from econometrics.model_specification_diagnostics_robust_inference.model_selection.model_selection_model import (
|
|
36
|
+
model_selection_criteria as core_model_selection_criteria,
|
|
37
|
+
granger_causality_test as core_granger_causality_test,
|
|
38
|
+
ModelSelectionResult as CoreModelSelectionResult,
|
|
39
|
+
GrangerCausalityResult as CoreGrangerCausalityResult
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
from econometrics.model_specification_diagnostics_robust_inference.regularization.regularization_model import (
|
|
43
|
+
regularized_regression as core_regularized_regression,
|
|
44
|
+
RegularizationResult as CoreRegularizationResult
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
from econometrics.model_specification_diagnostics_robust_inference.simultaneous_equations.simultaneous_equations_model import (
|
|
48
|
+
two_stage_least_squares as core_two_stage_least_squares,
|
|
49
|
+
SimultaneousEquationsResult as CoreSimultaneousEquationsResult
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
# 导入数据加载和格式化组件
|
|
53
|
+
from .data_loader import DataLoader
|
|
54
|
+
from .output_formatter import OutputFormatter
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class ModelSpecificationAdapter:
|
|
58
|
+
"""
|
|
59
|
+
模型规范、诊断和稳健推断适配器
|
|
60
|
+
将core算法适配为MCP工具,支持文件输入和多种输出格式
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
@staticmethod
|
|
64
|
+
def diagnostic_tests(
|
|
65
|
+
y_data: Optional[List[float]] = None,
|
|
66
|
+
x_data: Optional[List[List[float]]] = None,
|
|
67
|
+
file_path: Optional[str] = None,
|
|
68
|
+
feature_names: Optional[List[str]] = None,
|
|
69
|
+
constant: bool = True,
|
|
70
|
+
output_format: str = "json",
|
|
71
|
+
save_path: Optional[str] = None
|
|
72
|
+
) -> str:
|
|
73
|
+
"""
|
|
74
|
+
模型诊断检验适配器
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
y_data: 因变量数据
|
|
78
|
+
x_data: 自变量数据
|
|
79
|
+
file_path: 数据文件路径
|
|
80
|
+
feature_names: 特征名称
|
|
81
|
+
constant: 是否包含常数项
|
|
82
|
+
output_format: 输出格式 ("json", "markdown", "html")
|
|
83
|
+
save_path: 保存路径
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
str: 格式化的分析结果
|
|
87
|
+
"""
|
|
88
|
+
# 1. 数据准备
|
|
89
|
+
if file_path:
|
|
90
|
+
data = DataLoader.load_from_file(file_path)
|
|
91
|
+
y_data = data["y_data"]
|
|
92
|
+
x_data = data["x_data"]
|
|
93
|
+
feature_names = data.get("feature_names") or feature_names
|
|
94
|
+
elif y_data is None or x_data is None:
|
|
95
|
+
raise ValueError("必须提供文件路径(file_path)或直接数据(y_data和x_data)")
|
|
96
|
+
|
|
97
|
+
# 2. 调用核心算法
|
|
98
|
+
result: CoreDiagnosticTestsResult = core_diagnostic_tests(
|
|
99
|
+
y_data=y_data,
|
|
100
|
+
x_data=x_data,
|
|
101
|
+
feature_names=feature_names,
|
|
102
|
+
constant=constant
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
# 3. 格式化输出
|
|
106
|
+
json_result = json.dumps(result.dict(), ensure_ascii=False, indent=2)
|
|
107
|
+
if save_path:
|
|
108
|
+
OutputFormatter.save_to_file(json_result, save_path)
|
|
109
|
+
return f"模型诊断检验完成!结果已保存到: {save_path}\n\n{json_result}"
|
|
110
|
+
return json_result
|
|
111
|
+
|
|
112
|
+
@staticmethod
|
|
113
|
+
def gls_regression(
|
|
114
|
+
y_data: Optional[List[float]] = None,
|
|
115
|
+
x_data: Optional[List[List[float]]] = None,
|
|
116
|
+
file_path: Optional[str] = None,
|
|
117
|
+
sigma: Optional[List[List[float]]] = None,
|
|
118
|
+
feature_names: Optional[List[str]] = None,
|
|
119
|
+
constant: bool = True,
|
|
120
|
+
confidence_level: float = 0.95,
|
|
121
|
+
output_format: str = "json",
|
|
122
|
+
save_path: Optional[str] = None
|
|
123
|
+
) -> str:
|
|
124
|
+
"""
|
|
125
|
+
GLS回归适配器
|
|
126
|
+
"""
|
|
127
|
+
# 1. 数据准备
|
|
128
|
+
if file_path:
|
|
129
|
+
data = DataLoader.load_from_file(file_path)
|
|
130
|
+
y_data = data["y_data"]
|
|
131
|
+
x_data = data["x_data"]
|
|
132
|
+
feature_names = data.get("feature_names") or feature_names
|
|
133
|
+
elif y_data is None or x_data is None:
|
|
134
|
+
raise ValueError("必须提供文件路径(file_path)或直接数据(y_data和x_data)")
|
|
135
|
+
|
|
136
|
+
# 2. 调用核心算法
|
|
137
|
+
result: CoreGLSResult = core_gls_regression(
|
|
138
|
+
y_data=y_data,
|
|
139
|
+
x_data=x_data,
|
|
140
|
+
sigma=sigma,
|
|
141
|
+
feature_names=feature_names,
|
|
142
|
+
constant=constant,
|
|
143
|
+
confidence_level=confidence_level
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
# 3. 格式化输出
|
|
147
|
+
json_result = json.dumps(result.dict(), ensure_ascii=False, indent=2)
|
|
148
|
+
if save_path:
|
|
149
|
+
OutputFormatter.save_to_file(json_result, save_path)
|
|
150
|
+
return f"GLS回归完成!结果已保存到: {save_path}\n\n{json_result}"
|
|
151
|
+
return json_result
|
|
152
|
+
|
|
153
|
+
@staticmethod
|
|
154
|
+
def wls_regression(
|
|
155
|
+
y_data: Optional[List[float]] = None,
|
|
156
|
+
x_data: Optional[List[List[float]]] = None,
|
|
157
|
+
file_path: Optional[str] = None,
|
|
158
|
+
weights: Optional[List[float]] = None,
|
|
159
|
+
feature_names: Optional[List[str]] = None,
|
|
160
|
+
constant: bool = True,
|
|
161
|
+
confidence_level: float = 0.95,
|
|
162
|
+
output_format: str = "json",
|
|
163
|
+
save_path: Optional[str] = None
|
|
164
|
+
) -> str:
|
|
165
|
+
"""
|
|
166
|
+
WLS回归适配器
|
|
167
|
+
"""
|
|
168
|
+
# 1. 数据准备
|
|
169
|
+
if file_path:
|
|
170
|
+
data = DataLoader.load_from_file(file_path)
|
|
171
|
+
y_data = data["y_data"]
|
|
172
|
+
x_data = data["x_data"]
|
|
173
|
+
weights = data.get("weights") or weights
|
|
174
|
+
feature_names = data.get("feature_names") or feature_names
|
|
175
|
+
elif y_data is None or x_data is None or weights is None:
|
|
176
|
+
raise ValueError("必须提供文件路径(file_path)或直接数据(y_data、x_data和weights)")
|
|
177
|
+
|
|
178
|
+
# 2. 调用核心算法
|
|
179
|
+
result: CoreWLSResult = core_wls_regression(
|
|
180
|
+
y_data=y_data,
|
|
181
|
+
x_data=x_data,
|
|
182
|
+
weights=weights,
|
|
183
|
+
feature_names=feature_names,
|
|
184
|
+
constant=constant,
|
|
185
|
+
confidence_level=confidence_level
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
# 3. 格式化输出
|
|
189
|
+
json_result = json.dumps(result.dict(), ensure_ascii=False, indent=2)
|
|
190
|
+
if save_path:
|
|
191
|
+
OutputFormatter.save_to_file(json_result, save_path)
|
|
192
|
+
return f"WLS回归完成!结果已保存到: {save_path}\n\n{json_result}"
|
|
193
|
+
return json_result
|
|
194
|
+
|
|
195
|
+
@staticmethod
|
|
196
|
+
def robust_errors_regression(
|
|
197
|
+
y_data: Optional[List[float]] = None,
|
|
198
|
+
x_data: Optional[List[List[float]]] = None,
|
|
199
|
+
file_path: Optional[str] = None,
|
|
200
|
+
feature_names: Optional[List[str]] = None,
|
|
201
|
+
constant: bool = True,
|
|
202
|
+
confidence_level: float = 0.95,
|
|
203
|
+
cov_type: str = "HC1",
|
|
204
|
+
output_format: str = "json",
|
|
205
|
+
save_path: Optional[str] = None
|
|
206
|
+
) -> str:
|
|
207
|
+
"""
|
|
208
|
+
稳健标准误回归适配器
|
|
209
|
+
"""
|
|
210
|
+
# 1. 数据准备
|
|
211
|
+
if file_path:
|
|
212
|
+
data = DataLoader.load_from_file(file_path)
|
|
213
|
+
y_data = data["y_data"]
|
|
214
|
+
x_data = data["x_data"]
|
|
215
|
+
feature_names = data.get("feature_names") or feature_names
|
|
216
|
+
elif y_data is None or x_data is None:
|
|
217
|
+
raise ValueError("必须提供文件路径(file_path)或直接数据(y_data和x_data)")
|
|
218
|
+
|
|
219
|
+
# 2. 调用核心算法
|
|
220
|
+
result: CoreRobustErrorsResult = core_robust_errors_regression(
|
|
221
|
+
y_data=y_data,
|
|
222
|
+
x_data=x_data,
|
|
223
|
+
feature_names=feature_names,
|
|
224
|
+
constant=constant,
|
|
225
|
+
confidence_level=confidence_level,
|
|
226
|
+
cov_type=cov_type
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
# 3. 格式化输出
|
|
230
|
+
json_result = json.dumps(result.dict(), ensure_ascii=False, indent=2)
|
|
231
|
+
if save_path:
|
|
232
|
+
OutputFormatter.save_to_file(json_result, save_path)
|
|
233
|
+
return f"稳健标准误回归完成!结果已保存到: {save_path}\n\n{json_result}"
|
|
234
|
+
return json_result
|
|
235
|
+
|
|
236
|
+
@staticmethod
|
|
237
|
+
def model_selection_criteria(
|
|
238
|
+
y_data: Optional[List[float]] = None,
|
|
239
|
+
x_data: Optional[List[List[float]]] = None,
|
|
240
|
+
file_path: Optional[str] = None,
|
|
241
|
+
feature_names: Optional[List[str]] = None,
|
|
242
|
+
constant: bool = True,
|
|
243
|
+
cv_folds: Optional[int] = None,
|
|
244
|
+
output_format: str = "json",
|
|
245
|
+
save_path: Optional[str] = None
|
|
246
|
+
) -> str:
|
|
247
|
+
"""
|
|
248
|
+
模型选择准则适配器
|
|
249
|
+
"""
|
|
250
|
+
# 1. 数据准备
|
|
251
|
+
if file_path:
|
|
252
|
+
data = DataLoader.load_from_file(file_path)
|
|
253
|
+
y_data = data["y_data"]
|
|
254
|
+
x_data = data["x_data"]
|
|
255
|
+
feature_names = data.get("feature_names") or feature_names
|
|
256
|
+
elif y_data is None or x_data is None:
|
|
257
|
+
raise ValueError("必须提供文件路径(file_path)或直接数据(y_data和x_data)")
|
|
258
|
+
|
|
259
|
+
# 2. 调用核心算法
|
|
260
|
+
result: CoreModelSelectionResult = core_model_selection_criteria(
|
|
261
|
+
y_data=y_data,
|
|
262
|
+
x_data=x_data,
|
|
263
|
+
feature_names=feature_names,
|
|
264
|
+
constant=constant,
|
|
265
|
+
cv_folds=cv_folds
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
# 3. 格式化输出
|
|
269
|
+
json_result = json.dumps(result.dict(), ensure_ascii=False, indent=2)
|
|
270
|
+
if save_path:
|
|
271
|
+
OutputFormatter.save_to_file(json_result, save_path)
|
|
272
|
+
return f"模型选择分析完成!结果已保存到: {save_path}\n\n{json_result}"
|
|
273
|
+
return json_result
|
|
274
|
+
|
|
275
|
+
@staticmethod
|
|
276
|
+
def regularized_regression(
|
|
277
|
+
y_data: Optional[List[float]] = None,
|
|
278
|
+
x_data: Optional[List[List[float]]] = None,
|
|
279
|
+
file_path: Optional[str] = None,
|
|
280
|
+
method: str = "ridge",
|
|
281
|
+
alpha: float = 1.0,
|
|
282
|
+
l1_ratio: float = 0.5,
|
|
283
|
+
feature_names: Optional[List[str]] = None,
|
|
284
|
+
fit_intercept: bool = True,
|
|
285
|
+
output_format: str = "json",
|
|
286
|
+
save_path: Optional[str] = None
|
|
287
|
+
) -> str:
|
|
288
|
+
"""
|
|
289
|
+
正则化回归适配器
|
|
290
|
+
"""
|
|
291
|
+
# 1. 数据准备
|
|
292
|
+
if file_path:
|
|
293
|
+
data = DataLoader.load_from_file(file_path)
|
|
294
|
+
y_data = data["y_data"]
|
|
295
|
+
x_data = data["x_data"]
|
|
296
|
+
feature_names = data.get("feature_names") or feature_names
|
|
297
|
+
elif y_data is None or x_data is None:
|
|
298
|
+
raise ValueError("必须提供文件路径(file_path)或直接数据(y_data和x_data)")
|
|
299
|
+
|
|
300
|
+
# 2. 调用核心算法
|
|
301
|
+
result: CoreRegularizationResult = core_regularized_regression(
|
|
302
|
+
y_data=y_data,
|
|
303
|
+
x_data=x_data,
|
|
304
|
+
method=method,
|
|
305
|
+
alpha=alpha,
|
|
306
|
+
l1_ratio=l1_ratio,
|
|
307
|
+
feature_names=feature_names,
|
|
308
|
+
fit_intercept=fit_intercept
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
# 3. 格式化输出
|
|
312
|
+
json_result = json.dumps(result.dict(), ensure_ascii=False, indent=2)
|
|
313
|
+
if save_path:
|
|
314
|
+
OutputFormatter.save_to_file(json_result, save_path)
|
|
315
|
+
return f"正则化回归({method})完成!结果已保存到: {save_path}\n\n{json_result}"
|
|
316
|
+
return json_result
|
|
317
|
+
|
|
318
|
+
@staticmethod
|
|
319
|
+
def simultaneous_equations(
|
|
320
|
+
y_data: Optional[List[List[float]]] = None,
|
|
321
|
+
x_data: Optional[List[List[float]]] = None,
|
|
322
|
+
file_path: Optional[str] = None,
|
|
323
|
+
instruments: Optional[List[List[float]]] = None,
|
|
324
|
+
equation_names: Optional[List[str]] = None,
|
|
325
|
+
instrument_names: Optional[List[str]] = None,
|
|
326
|
+
constant: bool = True,
|
|
327
|
+
output_format: str = "json",
|
|
328
|
+
save_path: Optional[str] = None
|
|
329
|
+
) -> str:
|
|
330
|
+
"""
|
|
331
|
+
联立方程模型适配器
|
|
332
|
+
"""
|
|
333
|
+
# 1. 数据准备
|
|
334
|
+
if file_path:
|
|
335
|
+
data = DataLoader.load_from_file(file_path)
|
|
336
|
+
y_data = data.get("y_data") or y_data
|
|
337
|
+
x_data = data.get("x_data") or x_data
|
|
338
|
+
instruments = data.get("instruments") or instruments
|
|
339
|
+
equation_names = data.get("equation_names") or equation_names
|
|
340
|
+
instrument_names = data.get("instrument_names") or instrument_names
|
|
341
|
+
elif y_data is None or x_data is None or instruments is None:
|
|
342
|
+
raise ValueError("必须提供文件路径(file_path)或直接数据(y_data、x_data和instruments)")
|
|
343
|
+
|
|
344
|
+
# 2. 调用核心算法
|
|
345
|
+
result: CoreSimultaneousEquationsResult = core_two_stage_least_squares(
|
|
346
|
+
y_data=y_data,
|
|
347
|
+
x_data=x_data,
|
|
348
|
+
instruments=instruments,
|
|
349
|
+
equation_names=equation_names,
|
|
350
|
+
instrument_names=instrument_names,
|
|
351
|
+
constant=constant
|
|
352
|
+
)
|
|
353
|
+
|
|
354
|
+
# 3. 格式化输出
|
|
355
|
+
json_result = json.dumps(result.dict(), ensure_ascii=False, indent=2)
|
|
356
|
+
if save_path:
|
|
357
|
+
OutputFormatter.save_to_file(json_result, save_path)
|
|
358
|
+
return f"联立方程模型(2SLS)分析完成!结果已保存到: {save_path}\n\n{json_result}"
|
|
359
|
+
return json_result
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
# 便捷别名
|
|
363
|
+
diagnostic_tests_adapter = ModelSpecificationAdapter.diagnostic_tests
|
|
364
|
+
gls_adapter = ModelSpecificationAdapter.gls_regression
|
|
365
|
+
wls_adapter = ModelSpecificationAdapter.wls_regression
|
|
366
|
+
robust_errors_adapter = ModelSpecificationAdapter.robust_errors_regression
|
|
367
|
+
model_selection_adapter = ModelSpecificationAdapter.model_selection_criteria
|
|
368
|
+
regularization_adapter = ModelSpecificationAdapter.regularized_regression
|
|
369
|
+
simultaneous_equations_adapter = ModelSpecificationAdapter.simultaneous_equations
|