aigroup-econ-mcp 0.1.1__py3-none-any.whl → 0.1.5__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.
- aigroup_econ_mcp/__init__.py +18 -18
- aigroup_econ_mcp/cli.py +86 -81
- aigroup_econ_mcp/server.py +486 -73
- aigroup_econ_mcp/tools/__init__.py +6 -6
- aigroup_econ_mcp/tools/regression.py +213 -213
- aigroup_econ_mcp/tools/statistics.py +133 -133
- aigroup_econ_mcp/tools/time_series.py +259 -259
- aigroup_econ_mcp-0.1.5.dist-info/METADATA +448 -0
- aigroup_econ_mcp-0.1.5.dist-info/RECORD +12 -0
- {aigroup_econ_mcp-0.1.1.dist-info → aigroup_econ_mcp-0.1.5.dist-info}/licenses/LICENSE +20 -20
- aigroup_econ_mcp-0.1.1.dist-info/METADATA +0 -226
- aigroup_econ_mcp-0.1.1.dist-info/RECORD +0 -12
- {aigroup_econ_mcp-0.1.1.dist-info → aigroup_econ_mcp-0.1.5.dist-info}/WHEEL +0 -0
- {aigroup_econ_mcp-0.1.1.dist-info → aigroup_econ_mcp-0.1.5.dist-info}/entry_points.txt +0 -0
|
@@ -1,134 +1,134 @@
|
|
|
1
|
-
"""
|
|
2
|
-
统计分析工具
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
import numpy as np
|
|
6
|
-
import pandas as pd
|
|
7
|
-
from scipy import stats
|
|
8
|
-
from typing import Dict, List, Any
|
|
9
|
-
from pydantic import BaseModel
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class DescriptiveStats(BaseModel):
|
|
13
|
-
"""描述性统计结果"""
|
|
14
|
-
mean: float
|
|
15
|
-
median: float
|
|
16
|
-
std: float
|
|
17
|
-
min: float
|
|
18
|
-
max: float
|
|
19
|
-
skewness: float
|
|
20
|
-
kurtosis: float
|
|
21
|
-
count: int
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class CorrelationResult(BaseModel):
|
|
25
|
-
"""相关性分析结果"""
|
|
26
|
-
correlation_matrix: Dict[str, Dict[str, float]]
|
|
27
|
-
method: str
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def calculate_descriptive_stats(data: List[float]) -> DescriptiveStats:
|
|
31
|
-
"""计算描述性统计量"""
|
|
32
|
-
series = pd.Series(data)
|
|
33
|
-
|
|
34
|
-
return DescriptiveStats(
|
|
35
|
-
mean=series.mean(),
|
|
36
|
-
median=series.median(),
|
|
37
|
-
std=series.std(),
|
|
38
|
-
min=series.min(),
|
|
39
|
-
max=series.max(),
|
|
40
|
-
skewness=series.skew(),
|
|
41
|
-
kurtosis=series.kurtosis(),
|
|
42
|
-
count=len(series)
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def calculate_correlation_matrix(
|
|
47
|
-
data: Dict[str, List[float]],
|
|
48
|
-
method: str = "pearson"
|
|
49
|
-
) -> CorrelationResult:
|
|
50
|
-
"""计算相关系数矩阵"""
|
|
51
|
-
df = pd.DataFrame(data)
|
|
52
|
-
corr_matrix = df.corr(method=method)
|
|
53
|
-
|
|
54
|
-
return CorrelationResult(
|
|
55
|
-
correlation_matrix=corr_matrix.to_dict(),
|
|
56
|
-
method=method
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
def perform_hypothesis_test(
|
|
61
|
-
data1: List[float],
|
|
62
|
-
data2: List[float] = None,
|
|
63
|
-
test_type: str = "t_test",
|
|
64
|
-
alpha: float = 0.05
|
|
65
|
-
) -> Dict[str, Any]:
|
|
66
|
-
"""执行假设检验"""
|
|
67
|
-
if test_type == "t_test":
|
|
68
|
-
if data2 is None:
|
|
69
|
-
# 单样本t检验
|
|
70
|
-
t_stat, p_value = stats.ttest_1samp(data1, 0)
|
|
71
|
-
test_name = "单样本t检验"
|
|
72
|
-
else:
|
|
73
|
-
# 双样本t检验
|
|
74
|
-
t_stat, p_value = stats.ttest_ind(data1, data2)
|
|
75
|
-
test_name = "双样本t检验"
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
"test_type": test_name,
|
|
79
|
-
"statistic": t_stat,
|
|
80
|
-
"p_value": p_value,
|
|
81
|
-
"significant": p_value < alpha,
|
|
82
|
-
"alpha": alpha
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
elif test_type == "f_test":
|
|
86
|
-
# F检验(方差齐性检验)
|
|
87
|
-
if data2 is None:
|
|
88
|
-
raise ValueError("F检验需要两组数据")
|
|
89
|
-
|
|
90
|
-
f_stat, p_value = stats.f_oneway(data1, data2)
|
|
91
|
-
return {
|
|
92
|
-
"test_type": "F检验",
|
|
93
|
-
"statistic": f_stat,
|
|
94
|
-
"p_value": p_value,
|
|
95
|
-
"significant": p_value < alpha,
|
|
96
|
-
"alpha": alpha
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
elif test_type == "chi_square":
|
|
100
|
-
# 卡方检验
|
|
101
|
-
# 这里简化实现,实际需要频数数据
|
|
102
|
-
chi2_stat, p_value = stats.chisquare(data1)
|
|
103
|
-
return {
|
|
104
|
-
"test_type": "卡方检验",
|
|
105
|
-
"statistic": chi2_stat,
|
|
106
|
-
"p_value": p_value,
|
|
107
|
-
"significant": p_value < alpha,
|
|
108
|
-
"alpha": alpha
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
else:
|
|
112
|
-
raise ValueError(f"不支持的检验类型: {test_type}")
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
def normality_test(data: List[float]) -> Dict[str, Any]:
|
|
116
|
-
"""正态性检验"""
|
|
117
|
-
# Shapiro-Wilk检验
|
|
118
|
-
shapiro_stat, shapiro_p = stats.shapiro(data)
|
|
119
|
-
|
|
120
|
-
# Kolmogorov-Smirnov检验
|
|
121
|
-
ks_stat, ks_p = stats.kstest(data, 'norm', args=(np.mean(data), np.std(data)))
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
"shapiro_wilk": {
|
|
125
|
-
"statistic": shapiro_stat,
|
|
126
|
-
"p_value": shapiro_p,
|
|
127
|
-
"normal": shapiro_p > 0.05
|
|
128
|
-
},
|
|
129
|
-
"kolmogorov_smirnov": {
|
|
130
|
-
"statistic": ks_stat,
|
|
131
|
-
"p_value": ks_p,
|
|
132
|
-
"normal": ks_p > 0.05
|
|
133
|
-
}
|
|
1
|
+
"""
|
|
2
|
+
统计分析工具
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
import pandas as pd
|
|
7
|
+
from scipy import stats
|
|
8
|
+
from typing import Dict, List, Any
|
|
9
|
+
from pydantic import BaseModel
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class DescriptiveStats(BaseModel):
|
|
13
|
+
"""描述性统计结果"""
|
|
14
|
+
mean: float
|
|
15
|
+
median: float
|
|
16
|
+
std: float
|
|
17
|
+
min: float
|
|
18
|
+
max: float
|
|
19
|
+
skewness: float
|
|
20
|
+
kurtosis: float
|
|
21
|
+
count: int
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class CorrelationResult(BaseModel):
|
|
25
|
+
"""相关性分析结果"""
|
|
26
|
+
correlation_matrix: Dict[str, Dict[str, float]]
|
|
27
|
+
method: str
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def calculate_descriptive_stats(data: List[float]) -> DescriptiveStats:
|
|
31
|
+
"""计算描述性统计量"""
|
|
32
|
+
series = pd.Series(data)
|
|
33
|
+
|
|
34
|
+
return DescriptiveStats(
|
|
35
|
+
mean=series.mean(),
|
|
36
|
+
median=series.median(),
|
|
37
|
+
std=series.std(),
|
|
38
|
+
min=series.min(),
|
|
39
|
+
max=series.max(),
|
|
40
|
+
skewness=series.skew(),
|
|
41
|
+
kurtosis=series.kurtosis(),
|
|
42
|
+
count=len(series)
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def calculate_correlation_matrix(
|
|
47
|
+
data: Dict[str, List[float]],
|
|
48
|
+
method: str = "pearson"
|
|
49
|
+
) -> CorrelationResult:
|
|
50
|
+
"""计算相关系数矩阵"""
|
|
51
|
+
df = pd.DataFrame(data)
|
|
52
|
+
corr_matrix = df.corr(method=method)
|
|
53
|
+
|
|
54
|
+
return CorrelationResult(
|
|
55
|
+
correlation_matrix=corr_matrix.to_dict(),
|
|
56
|
+
method=method
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def perform_hypothesis_test(
|
|
61
|
+
data1: List[float],
|
|
62
|
+
data2: List[float] = None,
|
|
63
|
+
test_type: str = "t_test",
|
|
64
|
+
alpha: float = 0.05
|
|
65
|
+
) -> Dict[str, Any]:
|
|
66
|
+
"""执行假设检验"""
|
|
67
|
+
if test_type == "t_test":
|
|
68
|
+
if data2 is None:
|
|
69
|
+
# 单样本t检验
|
|
70
|
+
t_stat, p_value = stats.ttest_1samp(data1, 0)
|
|
71
|
+
test_name = "单样本t检验"
|
|
72
|
+
else:
|
|
73
|
+
# 双样本t检验
|
|
74
|
+
t_stat, p_value = stats.ttest_ind(data1, data2)
|
|
75
|
+
test_name = "双样本t检验"
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
"test_type": test_name,
|
|
79
|
+
"statistic": t_stat,
|
|
80
|
+
"p_value": p_value,
|
|
81
|
+
"significant": p_value < alpha,
|
|
82
|
+
"alpha": alpha
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
elif test_type == "f_test":
|
|
86
|
+
# F检验(方差齐性检验)
|
|
87
|
+
if data2 is None:
|
|
88
|
+
raise ValueError("F检验需要两组数据")
|
|
89
|
+
|
|
90
|
+
f_stat, p_value = stats.f_oneway(data1, data2)
|
|
91
|
+
return {
|
|
92
|
+
"test_type": "F检验",
|
|
93
|
+
"statistic": f_stat,
|
|
94
|
+
"p_value": p_value,
|
|
95
|
+
"significant": p_value < alpha,
|
|
96
|
+
"alpha": alpha
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
elif test_type == "chi_square":
|
|
100
|
+
# 卡方检验
|
|
101
|
+
# 这里简化实现,实际需要频数数据
|
|
102
|
+
chi2_stat, p_value = stats.chisquare(data1)
|
|
103
|
+
return {
|
|
104
|
+
"test_type": "卡方检验",
|
|
105
|
+
"statistic": chi2_stat,
|
|
106
|
+
"p_value": p_value,
|
|
107
|
+
"significant": p_value < alpha,
|
|
108
|
+
"alpha": alpha
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
else:
|
|
112
|
+
raise ValueError(f"不支持的检验类型: {test_type}")
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def normality_test(data: List[float]) -> Dict[str, Any]:
|
|
116
|
+
"""正态性检验"""
|
|
117
|
+
# Shapiro-Wilk检验
|
|
118
|
+
shapiro_stat, shapiro_p = stats.shapiro(data)
|
|
119
|
+
|
|
120
|
+
# Kolmogorov-Smirnov检验
|
|
121
|
+
ks_stat, ks_p = stats.kstest(data, 'norm', args=(np.mean(data), np.std(data)))
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
"shapiro_wilk": {
|
|
125
|
+
"statistic": shapiro_stat,
|
|
126
|
+
"p_value": shapiro_p,
|
|
127
|
+
"normal": shapiro_p > 0.05
|
|
128
|
+
},
|
|
129
|
+
"kolmogorov_smirnov": {
|
|
130
|
+
"statistic": ks_stat,
|
|
131
|
+
"p_value": ks_p,
|
|
132
|
+
"normal": ks_p > 0.05
|
|
133
|
+
}
|
|
134
134
|
}
|