Commit 28d03f86 authored by whlviolin's avatar whlviolin

通用工具子系统算法库代码及示例

parent 902e5714
.idea/
.egg-info/
dist/
build/
venv/
debug/
__pycache__/
metastore_db/
*.pyc
*.iml
*.swp
*.log
Thumbs.db
.DS_Store
# -- coding: utf-8 --
import json
from flask_cors import CORS
from flask import Flask, request,jsonify
from cieccproject.ciecc.datasets.dataset import Datasets
from cieccproject.ciecc.algorithms.comprehen_evaluate import dea_analysis
from cieccproject.ciecc.datasets.dataset import Datasets
from cieccproject.ciecc.algorithms.comprehen_evaluate import ahp_analysis
from cieccproject.ciecc.algorithms.comprehen_evaluate import topsis_analysis
from cieccproject.ciecc.datasets.dataset import Datasets
from cieccproject.ciecc.algorithms.comprehen_evaluate import rsr_analysis
app = Flask(__name__)
CORS(app, resources=r'/*') # 注册CORS, "/*" 允许访问所有api
@app.route("/getAHPList", methods=["GET", "POST"])
def getAHPList():
fileName = request.args["fileName"]
path = 'data/' +fileName
criteria2 = Datasets.read_csv(path)
ahp2 = ahp_analysis.AHP()
ahp2.fit(criteria2)
ahp2.summary()
result = {
"code": 200,
"msg": "success",
"data": json.dumps(ahp2.to_json())
}
return jsonify(result)
@app.route("/getTOPSISList", methods=["GET", "POST"])
def getTOPSISList():
# 读取数据
fileName = request.args["fileName"]
path = 'data/' +fileName
df = Datasets.read_csv(path)
# 正向指标
positive_columns = json.loads(request.args["positive"]) #['风景', '人文']
# 反向指标
negative_columns = json.loads(request.args["negative"]) #['拥挤程度', '票价']
# 设置索引项
index_column = request.args["index"]#'风景地点'
#index_column = '风景地点'
print(index_column)
# 熵权法
topsis1 = topsis_analysis.TOPSIS(positive_columns=positive_columns, negative_columns=negative_columns,
index_column=index_column)
topsis1.fit(df)
topsis1.summary()
# 自定义权重
weights = [0.6, 0.2, 0.1, 0.1]
topsis2 = topsis_analysis.TOPSIS(positive_columns=positive_columns, negative_columns=negative_columns,
index_column=index_column, weights=weights)
topsis2.fit(df)
topsis2.summary()
result = {
"code": 200,
"msg": "success",
"data": json.dumps(topsis2.to_json())
}
return jsonify(result)
@app.route("/getRSRList", methods=["GET", "POST"])
def getRSRList():
# with open("D:\EarthDataMiner\project\ZXDataAnalysis\demo\AHP\RSR.json", 'r', encoding='UTF-8') as f:
# res = f.read()
# print(type(res))
# print(res)
number_bins = int(request.args["number_bins"])
# 读取数据
fileName = request.args["fileName"]
path = 'data/' +fileName
df = Datasets.read_csv(path)
# # 正向指标
# positive_columns = ['产前检查率']
# # 反向指标
# negative_columns = ['孕妇死亡率', '围产儿死亡率']
# # 设置索引项
# index_column = '省份'
weight_type = request.args["weight_type"]
rank_make_method = request.args["rank_make_method"]
# 正向指标
positive_columns = json.loads(request.args["positive"]) #['产前检查率']
# 反向指标
negative_columns = json.loads(request.args["negative"]) #['孕妇死亡率', '围产儿死亡率']
# 设置索引项
index_column = request.args["index"]#'省份'
# 编秩方法:{整秩方法};分档数量:{3挡};变量权重:{熵权法}
rsr1 = rsr_analysis.RSR(positive_columns=positive_columns, negative_columns=negative_columns,
index_column=index_column,
weight_type=weight_type, rank_make_method=rank_make_method, number_bins=number_bins)
rsr1.fit(df)
rsr1.summary()
result = {
"code": 200,
"msg": "success",
"data": json.dumps(rsr1.to_json())
}
return jsonify(result)
@app.route("/getDEAList", methods=["GET", "POST"])
def getDEAList():
filepath = ""
if(request.args["type"]=='CCR'):
filepath ="D:\EarthDataMiner\project\ZXDataAnalysis\demo\AHP\DEA_CCR.json"
else:
filepath ="D:\EarthDataMiner\project\ZXDataAnalysis\demo\AHP\DEA_BBC.json"
with open(filepath, 'r', encoding='UTF-8') as f:
res = f.read()
print(type(res))
print(res)
result = {
"code": 200,
"msg": "success",
"data": res
}
return jsonify(result)
'''
# 读取数据
df = Datasets.read_csv('../data/DEA数据.csv')
# 投入
input_columns = ['政府财政收入占GDP的比例', '环保投资占GDP的比例', '每千人科技人员数/人']
# 产出项
output_columns = ['人均GDP', '城市环境质量指数']
# 索引项
index_column = '城市名'
deaType = request.args["type"]
dea1 = dea_analysis.DEA(input_columns=input_columns, output_columns=output_columns, index_column=index_column,
method=deaType)
dea1.fit(df)
dea1.summary()
res = dea1.to_json()
'''
if __name__ == "__main__":
app.run(debug=True, port=8001)
import numpy as np
import pandas as pd
from sklearn.linear_model import Ridge, Lasso
import statsmodels.api as sm
df = pd.read_csv('data/岭回归50.csv')
X1 = df[['面积', '楼层', '单价', '周围学校数量(1km)', '距地铁站距离(km)']]
y1 = df['总价']
print('#' * 50 + ' sklearn ' + '#' * 50)
clf1 = Lasso(alpha=0.02)
clf1.fit(X1, y1)
print(clf1.score(X1, y1)) # 输出R2
print(clf1.coef_) # 回归系数
print(clf1.intercept_)
print('*' * 100)
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
X1_std = scaler.fit_transform(X1)
clf2 = Lasso(alpha=0.02)
clf2.fit(X1_std, y1)
# 对标准化系数进行逆标准化,得到非标准化系数
non_standardized_coefficients = clf2.coef_ / scaler.scale_
print(non_standardized_coefficients)
# 对截距进行逆标准化,得到非标准化截距
non_standardized_intercept = clf2.intercept_ - np.dot(non_standardized_coefficients, scaler.mean_)
print(non_standardized_intercept)
print('#' * 50 + ' statsmodels ' + '#' * 50)
X1 = sm.add_constant(X1)
# 模型训练
model = sm.OLS(y1, X1).fit_regularized(method='elastic_net', L1_wt=1, refit=True)
# 查看模型结果
print(model.summary())
import numpy as np
import pandas as pd
from sklearn.metrics import roc_curve, confusion_matrix, accuracy_score, precision_score, recall_score, f1_score, roc_auc_score, roc_curve
import statsmodels.api as sm
df = pd.read_csv('data/岭回归50.csv')
X = df[['面积', '楼层', '单价']]
y = df['配套电梯']
y = y.map({1.0: 0, 2.0: 1})
# 输出结果1:二分类因变量基本汇总
print('输出结果1:二分类因变量基本汇总')
print(y.value_counts())
# 添加截距项
X = sm.add_constant(X)
model = sm.Logit(y, X)
result = model.fit()
# 输出结果2:模型评价
print('输出结果2:模型评价')
# 获取似然比卡方值和p-value
p_value = result.llr_pvalue
# 获取AIC和BIC
aic = result.aic
bic = result.bic
print(result.llf, result.llnull)
# 打印结果
lr_chi2 = -2 * (result.llf - result.llnull)
print("似然比卡方值:", lr_chi2)
print("p-value:", p_value)
print("AIC:", aic)
print("BIC:", bic)
lr_chi2 = -2 * (model.loglike(result.params) - model.loglike(np.zeros(X.shape[1])))
print("似然比卡方值:", lr_chi2)
print("似然比卡方值:", -2*model.loglike(result.params))
# 输出结果3:二分类逻辑回归结果
print('输出结果3:二分类逻辑回归结果')
print(result.summary())
# 输出结果4:混淆矩阵
# 使用拟合的模型进行预测
predicted_probabilities = result.predict(X)
predicted_labels = (predicted_probabilities > 0.5).astype(int) # 使用0.5作为阈值进行二分类
# 计算混淆矩阵
conf_matrix = confusion_matrix(y, predicted_labels)
print("输出结果4:混淆矩阵")
print(conf_matrix)
# 输出结果5:ROC曲线
# 计算ROC曲线
fpr, tpr, thresholds = roc_curve(y, predicted_probabilities)
print(fpr, tpr, thresholds)
# 输出结果6:分类评价指标
# 准确率 召回率 精确率 F1 AUC
# 0.84 0.84 0.868 0.812 0.867
# 计算准确率
accuracy = accuracy_score(y, predicted_labels)
print("准确率:", accuracy)
# 计算精确率
precision = precision_score(y, predicted_labels)
print("精确率:", precision)
# 计算召回率
recall = recall_score(y, predicted_labels)
print("召回率:", recall)
# 计算F1分数
f1 = f1_score(y, predicted_labels)
print("F1分数:", f1)
# 计算AUC
roc_auc = roc_auc_score(y, predicted_labels)
print("AUC:", roc_auc)
# 正例的召回率
TPR = conf_matrix[1, 1] / (conf_matrix[1, 1] + conf_matrix[1, 0])
print("正例的召回率 (TPR):", TPR)
# 负例的召回率
TNR = conf_matrix[0, 0] / (conf_matrix[0, 0] + conf_matrix[0, 1])
print("负例的召回率 (TNR):", TNR)
print(TPR*0.74 + TNR*0.26)
# 计算宏平均召回率
macro_recall = recall_score(y, predicted_labels, average='macro')
print("宏平均召回率:", macro_recall)
import pandas as pd
from sklearn.linear_model import Ridge
from sklearn.metrics import r2_score
import statsmodels.api as sm
df = pd.read_csv('data/岭回归50.csv')
X = df[['面积', '楼层', '单价', '周围学校数量(1km)', '距地铁站距离(km)']]
y = df['总价']
print('#' * 50 + ' sklearn ' + '#' * 50)
clf = Ridge(fit_intercept=True, normalize=True, alpha=0.01)
clf.fit(X, y)
# 获取系数
coefficients = clf.coef_
# 进行预测
predictions = clf.predict(X)
# 计算R²分数
r_squared = r2_score(y, predictions)
# 计算调整R²
n_samples, n_features = X.shape
adjusted_r_squared = 1 - (1 - r_squared) * (n_samples - 1) / (n_samples - n_features - 1)
print("Coefficients:", coefficients)
print("R²:", r_squared)
print("Adjusted R²:", adjusted_r_squared)
print(clf.intercept_)
print(clf.get_params()) # 输出参数设置
print('#' * 50 + ' statsmodels ' + '#' * 50)
# 添加常数列作为截距项
X = sm.add_constant(X)
# 创建岭回归模型
ridge_model = sm.OLS(y, X)
ridge_results = ridge_model.fit_regularized(alpha=0.01, L1_wt=0) # L1_wt=0表示只使用岭回归
# 获取系数
coefficients = ridge_results.params[1:]
# 获取截距
intercept = ridge_results.params[0]
# 计算R²分数
r_squared = r2_score(y, ridge_results.fittedvalues)
print("Coefficients:", coefficients)
print("Intercept:", intercept)
print("R²:", r_squared)
"""Global configuration state and functions for management
"""
import os
from contextlib import contextmanager as contextmanager
import threading
_global_config = {
"assume_finite": bool(os.environ.get("SKLEARN_ASSUME_FINITE", False)),
"working_memory": int(os.environ.get("SKLEARN_WORKING_MEMORY", 1024)),
"print_changed_only": True,
"display": "text",
}
_threadlocal = threading.local()
def _get_threadlocal_config():
"""Get a threadlocal **mutable** configuration. If the configuration
does not exist, copy the default global configuration."""
if not hasattr(_threadlocal, "global_config"):
_threadlocal.global_config = _global_config.copy()
return _threadlocal.global_config
def get_config():
"""Retrieve current values for configuration set by :func:`set_config`.
Returns
-------
config : dict
Keys are parameter names that can be passed to :func:`set_config`.
See Also
--------
config_context : Context manager for global scikit-learn configuration.
set_config : Set global scikit-learn configuration.
"""
# Return a copy of the threadlocal configuration so that users will
# not be able to modify the configuration with the returned dict.
return _get_threadlocal_config().copy()
def set_config(
assume_finite=None, working_memory=None, print_changed_only=None, display=None
):
"""Set global scikit-learn configuration
.. versionadded:: 0.19
Parameters
----------
assume_finite : bool, default=None
If True, validation for finiteness will be skipped,
saving time, but leading to potential crashes. If
False, validation for finiteness will be performed,
avoiding error. Global default: False.
.. versionadded:: 0.19
working_memory : int, default=None
If set, scikit-learn will attempt to limit the size of temporary arrays
to this number of MiB (per job when parallelised), often saving both
computation time and memory on expensive operations that can be
performed in chunks. Global default: 1024.
.. versionadded:: 0.20
print_changed_only : bool, default=None
If True, only the parameters that were set to non-default
values will be printed when printing an estimator. For example,
``print(SVC())`` while True will only print 'SVC()' while the default
behaviour would be to print 'SVC(C=1.0, cache_size=200, ...)' with
all the non-changed parameters.
.. versionadded:: 0.21
display : {'text', 'diagram'}, default=None
If 'diagram', estimators will be displayed as a diagram in a Jupyter
lab or notebook context. If 'text', estimators will be displayed as
text. Default is 'text'.
.. versionadded:: 0.23
See Also
--------
config_context : Context manager for global scikit-learn configuration.
get_config : Retrieve current values of the global configuration.
"""
local_config = _get_threadlocal_config()
if assume_finite is not None:
local_config["assume_finite"] = assume_finite
if working_memory is not None:
local_config["working_memory"] = working_memory
if print_changed_only is not None:
local_config["print_changed_only"] = print_changed_only
if display is not None:
local_config["display"] = display
@contextmanager
def config_context(
*, assume_finite=None, working_memory=None, print_changed_only=None, display=None
):
"""Context manager for global scikit-learn configuration.
Parameters
----------
assume_finite : bool, default=None
If True, validation for finiteness will be skipped,
saving time, but leading to potential crashes. If
False, validation for finiteness will be performed,
avoiding error. If None, the existing value won't change.
The default value is False.
working_memory : int, default=None
If set, scikit-learn will attempt to limit the size of temporary arrays
to this number of MiB (per job when parallelised), often saving both
computation time and memory on expensive operations that can be
performed in chunks. If None, the existing value won't change.
The default value is 1024.
print_changed_only : bool, default=None
If True, only the parameters that were set to non-default
values will be printed when printing an estimator. For example,
``print(SVC())`` while True will only print 'SVC()', but would print
'SVC(C=1.0, cache_size=200, ...)' with all the non-changed parameters
when False. If None, the existing value won't change.
The default value is True.
.. versionchanged:: 0.23
Default changed from False to True.
display : {'text', 'diagram'}, default=None
If 'diagram', estimators will be displayed as a diagram in a Jupyter
lab or notebook context. If 'text', estimators will be displayed as
text. If None, the existing value won't change.
The default value is 'text'.
.. versionadded:: 0.23
Yields
------
None.
See Also
--------
set_config : Set global scikit-learn configuration.
get_config : Retrieve current values of the global configuration.
Notes
-----
All settings, not just those presently modified, will be returned to
their previous values when the context manager is exited.
Examples
--------
>>> import sklearn
>>> from sklearn.utils.validation import assert_all_finite
>>> with sklearn.config_context(assume_finite=True):
... assert_all_finite([float('nan')])
>>> with sklearn.config_context(assume_finite=True):
... with sklearn.config_context(assume_finite=False):
... assert_all_finite([float('nan')])
Traceback (most recent call last):
...
ValueError: Input contains NaN...
"""
old_config = get_config()
set_config(
assume_finite=assume_finite,
working_memory=working_memory,
print_changed_only=print_changed_only,
display=display,
)
try:
yield
finally:
set_config(**old_config)
This diff is collapsed.
"""
分类模型
"""
\ No newline at end of file
from cieccproject.ciecc.algorithms.base import BaseEstimator
import sklearn.ensemble
import sklearn.metrics
import numpy as np
import time
class AdaBoostClassifier(BaseEstimator):
def __init__(
self,
estimator=None,
n_estimators=50,
learning_rate=1.0,
algorithm="SAMME.R",
random_state=None,
):
"""在构造函数中指定训练模型所需的超参"""
self.estimator = estimator
self.n_estimators = n_estimators
self.learning_rate = learning_rate
self.algorithm = algorithm
self.random_state = random_state
def fit(self, X, y, sample_weight=None):
model = sklearn.ensemble.AdaBoostClassifier(
estimator=self.estimator,
n_estimators=self.n_estimators,
learning_rate=self.learning_rate,
algorithm=self.algorithm,
random_state=self.random_state,
)
start_time = time.time()
self._model = model.fit(X, np.ravel(y), sample_weight)
end_time = time.time()
self.time_trained = end_time - start_time
return self
def predict(self, X):
return self._model.predict(X)
def score(self, X, y):
return self.accuracy(X, np.ravel(y))
def summary(self):
summ = {
"model parameters": {
"time_trained": self.time_trained,
"maximum number of estimators": self.n_estimators,
"learning rate": self.learning_rate,
},
"feature importance": self.feature_importance(),
}
return summ
def feature_importance(self):
return [self._model.feature_names_in_, self._model.feature_importances_]
def confusion_matrix(self, X, y):
return sklearn.metrics.confusion_matrix(np.ravel(y), self._model.predict(X))
def accuracy(self, X, y):
return self._model.score(X, np.ravel(y))
def recall_rate(self, X, y):
return sklearn.metrics.recall_score(
np.ravel(y), self._model.predict(X), average="micro"
)
def precision_rate(self, X, y):
return sklearn.metrics.precision_score(
np.ravel(y), self._model.predict(X), average="micro"
)
def f1_score(self, X, y):
return sklearn.metrics.f1_score(
np.ravel(y), self._model.predict(X), average="micro"
)
from cieccproject.ciecc.algorithms.base import BaseEstimator
import sklearn.tree
import sklearn.metrics
import numpy as np
import time
class DecisionTreeClassifier(BaseEstimator):
def __init__(
self,
criterion="gini",
splitter="best",
max_depth=None,
min_samples_split=2,
min_samples_leaf=1,
min_weight_fraction_leaf=0.0,
max_features=None,
random_state=None,
max_leaf_nodes=None,
min_impurity_decrease=0.0,
class_weight=None,
ccp_alpha=0.0,
):
"""在构造函数中指定训练模型所需的超参"""
self.criterion = criterion
self.splitter = splitter
self.max_depth = max_depth
self.min_samples_split = min_samples_split
self.min_samples_leaf = min_samples_leaf
self.min_weight_fraction_leaf = min_weight_fraction_leaf
self.max_features = max_features
self.random_state = random_state
self.max_leaf_nodes = max_leaf_nodes
self.min_impurity_decrease = min_impurity_decrease
self.class_weight = class_weight
self.ccp_alpha = ccp_alpha
def fit(self, X, y, sample_weight=None, check_input=True):
model = sklearn.tree.DecisionTreeClassifier(
criterion=self.criterion,
splitter=self.splitter,
max_depth=self.max_depth,
min_samples_split=self.min_samples_split,
min_samples_leaf=self.min_samples_leaf,
min_weight_fraction_leaf=self.min_weight_fraction_leaf,
max_features=self.max_features,
random_state=self.random_state,
max_leaf_nodes=self.max_leaf_nodes,
min_impurity_decrease=self.min_impurity_decrease,
class_weight=self.class_weight,
ccp_alpha=self.ccp_alpha,
)
start_time = time.time()
self._model = model.fit(X, np.ravel(y), sample_weight, check_input)
end_time = time.time()
self.time_trained = end_time - start_time
return self
def predict(self, X):
return self._model.predict(X)
def score(self, X, y):
return self.accuracy(X, np.ravel(y))
def summary(self):
summ = {
"model parameters": {
"time_trained": self.time_trained,
"criterion": self.criterion,
"splitter": self.splitter,
"max features": self.max_features,
"min samples split": self.min_samples_split,
"min samples leaf": self.min_samples_leaf,
"min weight fraction leaf": self.min_weight_fraction_leaf,
"max leaf nodes": self.max_leaf_nodes,
"max depth": self.max_depth,
"min impurity decrease": self.min_impurity_decrease,
},
"tree structure": self.tree_structure(),
"feature importance": self.feature_importance(),
}
return summ
def tree_structure(self):
return sklearn.tree.export_graphviz(
self._model,
feature_names=self._model.feature_names_in_,
filled=True,
rounded=True,
special_characters=True,
)
def feature_importance(self):
return [self._model.feature_names_in_, self._model.feature_importances_]
def confusion_matrix(self, X, y):
return sklearn.metrics.confusion_matrix(np.ravel(y), self._model.predict(X))
def accuracy(self, X, y):
return self._model.score(X, np.ravel(y))
def recall_rate(self, X, y):
return sklearn.metrics.recall_score(
np.ravel(y), self._model.predict(X), average="micro"
)
def precision_rate(self, X, y):
return sklearn.metrics.precision_score(
np.ravel(y), self._model.predict(X), average="micro"
)
def f1_score(self, X, y):
return sklearn.metrics.f1_score(
np.ravel(y), self._model.predict(X), average="micro"
)
from cieccproject.ciecc.algorithms.base import BaseEstimator
import sklearn.discriminant_analysis
import sklearn.metrics
import numpy as np
class DiscriminantAnalysis(BaseEstimator):
def __init__(
self,
solver="svd",
shrinkage=None,
priors=None,
n_components=None,
store_covariance=False,
tol=1e-4,
covariance_estimator=None,
):
"""在构造函数中指定训练模型所需的超参"""
self.solver = solver
self.shrinkage = shrinkage
self.priors = priors
self.n_components = n_components
self.store_covariance = store_covariance # used only in svd solver
self.tol = tol # used only in svd solver
self.covariance_estimator = covariance_estimator
def fit(self, X, y):
model = sklearn.discriminant_analysis.LinearDiscriminantAnalysis(
solver=self.solver,
shrinkage=self.shrinkage,
priors=self.priors,
n_components=self.n_components,
store_covariance=self.store_covariance,
tol=self.tol,
covariance_estimator=self.covariance_estimator,
)
self._model = model.fit(X, np.ravel(y))
return self
def predict(self, X):
return self._model.predict(X)
def score(self, X, y):
return self.accuracy(X, np.ravel(y))
def summary(self):
disc_func = dict()
for i in range(len(self._model.classes_)):
disc_func[self._model.classes_[i]] = [
["intercept"] + list(self._model.feature_names_in_),
[self._model.intercept_[i]] + list(self._model.coef_[i]),
]
summ = {"discriminant function": disc_func}
return summ
def confusion_matrix(self, X, y):
return sklearn.metrics.confusion_matrix(np.ravel(y), self._model.predict(X))
def accuracy(self, X, y):
return self._model.score(X, np.ravel(y))
def recall_rate(self, X, y):
return sklearn.metrics.recall_score(
np.ravel(y), self._model.predict(X), average="micro"
)
def precision_rate(self, X, y):
return sklearn.metrics.precision_score(
np.ravel(y), self._model.predict(X), average="micro"
)
def f1_score(self, X, y):
return sklearn.metrics.f1_score(
np.ravel(y), self._model.predict(X), average="micro"
)
from cieccproject.ciecc.algorithms.base import BaseEstimator
import sklearn.ensemble
import sklearn.metrics
import numpy as np
import time
class GradientBoostingClassifier(BaseEstimator):
def __init__(
self,
loss="log_loss",
learning_rate=0.1,
n_estimators=100,
subsample=1.0,
criterion="friedman_mse",
min_samples_split=2,
min_samples_leaf=1,
min_weight_fraction_leaf=0.0,
max_depth=3,
min_impurity_decrease=0.0,
init=None,
random_state=None,
max_features=None,
verbose=0,
max_leaf_nodes=None,
warm_start=False,
validation_fraction=0.1,
n_iter_no_change=None,
tol=1e-4,
ccp_alpha=0.0,
):
"""在构造函数中指定训练模型所需的超参"""
self.loss = loss
self.learning_rate = learning_rate
self.n_estimators = n_estimators
self.subsample = subsample
self.criterion = criterion
self.min_samples_split = min_samples_split
self.min_samples_leaf = min_samples_leaf
self.min_weight_fraction_leaf = min_weight_fraction_leaf
self.max_depth = max_depth
self.min_impurity_decrease = min_impurity_decrease
self.init = init
self.random_state = random_state
self.max_features = max_features
self.verbose = verbose
self.max_leaf_nodes = max_leaf_nodes
self.warm_start = warm_start
self.validation_fraction = validation_fraction
self.n_iter_no_change = n_iter_no_change
self.tol = tol
self.ccp_alpha = ccp_alpha
def fit(self, X, y, sample_weight=None, monitor=None):
model = sklearn.ensemble.GradientBoostingClassifier(
loss=self.loss,
learning_rate=self.learning_rate,
n_estimators=self.n_estimators,
subsample=self.subsample,
criterion=self.criterion,
min_samples_split=self.min_samples_split,
min_samples_leaf=self.min_samples_leaf,
min_weight_fraction_leaf=self.min_weight_fraction_leaf,
max_depth=self.max_depth,
min_impurity_decrease=self.min_impurity_decrease,
init=self.init,
random_state=self.random_state,
max_features=self.max_features,
verbose=self.verbose,
max_leaf_nodes=self.max_leaf_nodes,
warm_start=self.warm_start,
validation_fraction=self.validation_fraction,
n_iter_no_change=self.n_iter_no_change,
tol=self.tol,
ccp_alpha=self.ccp_alpha,
)
start_time = time.time()
self._model = model.fit(X, np.ravel(y), sample_weight, monitor)
end_time = time.time()
self.time_trained = end_time - start_time
return self
def predict(self, X):
return self._model.predict(X)
def score(self, X, y):
return self.accuracy(X, np.ravel(y))
def summary(self):
summ = {
"model parameters": {
"time_trained": self.time_trained,
"loss function": self.loss,
"criterion": self.criterion,
"number of boosting stages to perform": self.n_estimators,
"learning_rate": self.learning_rate,
"fraction of samples to be used": self.subsample,
"max features": self.max_features,
"min samples split": self.min_samples_split,
"min samples leaf": self.min_samples_leaf,
"min weight fraction leaf": self.min_weight_fraction_leaf,
"max depth": self.max_depth,
"max leaf nodes": self.max_leaf_nodes,
"min impurity decrease": self.min_impurity_decrease,
},
"feature importance": self.feature_importance(),
}
return summ
def feature_importance(self):
return [self._model.feature_names_in_, self._model.feature_importances_]
def confusion_matrix(self, X, y):
return sklearn.metrics.confusion_matrix(np.ravel(y), self._model.predict(X))
def accuracy(self, X, y):
return self._model.score(X, np.ravel(y))
def recall_rate(self, X, y):
return sklearn.metrics.recall_score(
np.ravel(y), self._model.predict(X), average="micro"
)
def precision_rate(self, X, y):
return sklearn.metrics.precision_score(
np.ravel(y), self._model.predict(X), average="micro"
)
def f1_score(self, X, y):
return sklearn.metrics.f1_score(
np.ravel(y), self._model.predict(X), average="micro"
)
from cieccproject.ciecc.algorithms.base import BaseEstimator
import sklearn.neighbors
import sklearn.metrics
import numpy as np
import time
class KNearestNeighbors(BaseEstimator):
def __init__(
self,
n_neighbors=5,
weights="uniform",
algorithm="auto",
leaf_size=30,
p=2,
metric="minkowski",
metric_params=None,
n_jobs=None,
):
"""在构造函数中指定训练模型所需的超参"""
self.n_neighbors = n_neighbors
self.weights = weights
self.algorithm = algorithm
self.leaf_size = leaf_size
self.p = p
self.metric = metric
self.metric_params = metric_params
self.n_jobs = n_jobs
def fit(self, X, y):
model = sklearn.neighbors.KNeighborsClassifier(
n_neighbors=self.n_neighbors,
weights=self.weights,
algorithm=self.algorithm,
leaf_size=self.leaf_size,
p=self.p,
metric=self.metric,
metric_params=self.metric_params,
n_jobs=self.n_jobs,
)
start_time = time.time()
self._model = model.fit(X, np.ravel(y))
end_time = time.time()
self.time_trained = end_time - start_time
return self
def predict(self, X):
return self._model.predict(X)
def score(self, X, y):
return self.accuracy(X, np.ravel(y))
def summary(self):
summ = {
"model parameters": {
"time_trained": self.time_trained,
"algorithm": self.algorithm,
"leaf size": self.leaf_size,
"number of neighbors": self.n_neighbors,
"weight function": self.weights,
"metric to use for distance computation": self.metric,
"power parameter for the Minkowski metric": self.p,
}
}
return summ
def confusion_matrix(self, X, y):
return sklearn.metrics.confusion_matrix(np.ravel(y), self._model.predict(X))
def accuracy(self, X, y):
return self._model.score(X, np.ravel(y))
def recall_rate(self, X, y):
return sklearn.metrics.recall_score(
np.ravel(y), self._model.predict(X), average="micro"
)
def precision_rate(self, X, y):
return sklearn.metrics.precision_score(
np.ravel(y), self._model.predict(X), average="micro"
)
def f1_score(self, X, y):
return sklearn.metrics.f1_score(
np.ravel(y), self._model.predict(X), average="micro"
)
from cieccproject.ciecc.algorithms.base import BaseEstimator
import sklearn.ensemble
import sklearn.metrics
import numpy as np
import time
class RandomForestClassifier(BaseEstimator):
def __init__(
self,
n_estimators=100,
criterion="gini",
max_depth=None,
min_samples_split=2,
min_samples_leaf=1,
min_weight_fraction_leaf=0.0,
max_features="sqrt",
max_leaf_nodes=None,
min_impurity_decrease=0.0,
bootstrap=True,
oob_score=False,
n_jobs=None,
random_state=None,
verbose=0,
warm_start=False,
class_weight=None,
ccp_alpha=0.0,
max_samples=None,
):
"""在构造函数中指定训练模型所需的超参"""
self.n_estimators = n_estimators
self.criterion = criterion
self.max_depth = max_depth
self.min_samples_split = min_samples_split
self.min_samples_leaf = min_samples_leaf
self.min_weight_fraction_leaf = min_weight_fraction_leaf
self.max_features = max_features
self.max_leaf_nodes = max_leaf_nodes
self.min_impurity_decrease = min_impurity_decrease
self.bootstrap = bootstrap
self.oob_score = oob_score
self.n_jobs = n_jobs
self.random_state = random_state
self.verbose = verbose
self.warm_start = warm_start
self.class_weight = class_weight
self.ccp_alpha = ccp_alpha
self.max_samples = max_samples
def fit(self, X, y, sample_weight=None):
model = sklearn.ensemble.RandomForestClassifier(
n_estimators=self.n_estimators,
criterion=self.criterion,
max_depth=self.max_depth,
min_samples_split=self.min_samples_split,
min_samples_leaf=self.min_samples_leaf,
min_weight_fraction_leaf=self.min_weight_fraction_leaf,
max_features=self.max_features,
max_leaf_nodes=self.max_leaf_nodes,
min_impurity_decrease=self.min_impurity_decrease,
bootstrap=self.bootstrap,
oob_score=self.oob_score,
n_jobs=self.n_jobs,
random_state=self.random_state,
verbose=self.verbose,
warm_start=self.warm_start,
class_weight=self.class_weight,
ccp_alpha=self.ccp_alpha,
max_samples=self.max_samples,
)
start_time = time.time()
self._model = model.fit(X, np.ravel(y), sample_weight)
end_time = time.time()
self.time_trained = end_time - start_time
return self
def predict(self, X):
return self._model.predict(X)
def score(self, X, y):
return self.accuracy(X, np.ravel(y))
def summary(self):
summ = {
"model parameters": {
"time_trained": self.time_trained,
"criterion": self.criterion,
"number of trees": self.n_estimators,
"bootstrap": self.bootstrap,
"use out-of-bag samples": self.oob_score,
"max features": self.max_features,
"min samples split": self.min_samples_split,
"min samples leaf": self.min_samples_leaf,
"min weight fraction leaf": self.min_weight_fraction_leaf,
"max depth": self.max_depth,
"max leaf nodes": self.max_leaf_nodes,
"min impurity decrease": self.min_impurity_decrease,
},
"feature importance": self.feature_importance(),
}
return summ
def feature_importance(self):
return [self._model.feature_names_in_, self._model.feature_importances_]
def confusion_matrix(self, X, y):
return sklearn.metrics.confusion_matrix(np.ravel(y), self._model.predict(X))
def accuracy(self, X, y):
return self._model.score(X, np.ravel(y))
def recall_rate(self, X, y):
return sklearn.metrics.recall_score(
np.ravel(y), self._model.predict(X), average="micro"
)
def precision_rate(self, X, y):
return sklearn.metrics.precision_score(
np.ravel(y), self._model.predict(X), average="micro"
)
def f1_score(self, X, y):
return sklearn.metrics.f1_score(
np.ravel(y), self._model.predict(X), average="micro"
)
"""
分类模型
"""
\ No newline at end of file
from cieccproject.ciecc.algorithms.base import BaseEstimator
import sklearn.cluster
import sklearn.metrics
import scipy.stats
import pandas as pd
import numpy as np
class HierarchyLinkage(BaseEstimator):
def __init__(
self,
n_clusters=2,
metric="euclidean",
memory=None,
connectivity=None,
compute_full_tree="auto",
linkage="ward",
distance_threshold=None,
compute_distances=False,
):
"""在构造函数中指定训练模型所需的超参"""
self.n_clusters = n_clusters
self.metric = metric
self.memory = memory
self.connectivity = connectivity
self.compute_full_tree = compute_full_tree
self.linkage = linkage
self.distance_threshold = distance_threshold
self.compute_distances = compute_distances
def fit(self, X, y=None):
model = sklearn.cluster.AgglomerativeClustering(
n_clusters=self.n_clusters,
metric=self.metric,
memory=self.memory,
connectivity=self.connectivity,
compute_full_tree=self.compute_full_tree,
linkage=self.linkage,
distance_threshold=self.distance_threshold,
compute_distances=self.compute_distances,
)
self._model = model.fit(X, y)
return self
def predict(self, X):
"""聚类标注"""
return self._model.fit_predict(X)
def score(self, X, y=None):
return self.evaluate(X)
def summary(self):
"""聚类汇总"""
summ = {}
return summ
def evaluate(self, X):
"""评价指标"""
labels = self.predict(X)
silhouette = sklearn.metrics.silhouette_score(X, labels)
dbi = sklearn.metrics.davies_bouldin_score(X, labels)
ch = sklearn.metrics.calinski_harabasz_score(X, labels)
ret = {"silhouette coefficient": silhouette, "DBI": dbi, "CH": ch}
return ret
from cieccproject.ciecc.algorithms.base import BaseEstimator
import sklearn.cluster
import sklearn.metrics
import scipy.stats
import pandas as pd
import numpy as np
class KMeans(BaseEstimator):
def __init__(
self,
n_clusters=8,
init="k-means++",
n_init="auto",
max_iter=300,
tol=1e-4,
verbose=0,
random_state=None,
copy_x=True,
algorithm="lloyd",
):
"""在构造函数中指定训练模型所需的超参"""
self.n_clusters = n_clusters
self.init = init
self.n_init = n_init
self.max_iter = max_iter
self.tol = tol
self.verbose = verbose
self.random_state = random_state
self.copy_x = copy_x
self.algorithm = algorithm
def fit(self, X, y=None, sample_weight=None):
model = sklearn.cluster.KMeans(
n_clusters=self.n_clusters,
init=self.init,
n_init=self.n_init,
max_iter=self.max_iter,
tol=self.tol,
verbose=self.verbose,
random_state=self.random_state,
copy_x=self.copy_x,
algorithm=self.algorithm,
)
self._model = model.fit(X, y, sample_weight)
return self
def predict(self, X):
"""聚类标注"""
return self._model.predict(X)
def score(self, X, y=None, sample_weight=None):
return self._model.score(X, y, sample_weight)
def summary(self):
"""聚类汇总"""
summ = {}
group = pd.DataFrame(self._model.labels_).groupby(self._model.labels_)
count = group.count().T
for i in range(self.n_clusters):
summ["class {}".format(i)] = {
"frequency": count[i].iloc[0],
"percentage": (count[i].iloc[0]) * 100 / len(self._model.labels_),
}
summ["total"] = {"frequency": len(self._model.labels_), "percentage": 100}
return pd.DataFrame(summ).T
def diff_analyse(self, X: pd.DataFrame):
"""字段差异性分析"""
classes = self.predict(X)
group = X.groupby(classes)
avg = group.mean().T
std = group.std().T
test = {}
for i in range(self._model.n_features_in_):
test[self._model.feature_names_in_[i]] = scipy.stats.f_oneway(
*(group.apply(lambda x: x.iloc[:, i].ravel()))
)
return {"average": avg, "standard deviation": std, "F test": test}
def centers(self):
"""聚类中心点坐标"""
ret = pd.DataFrame(self._model.cluster_centers_)
ret.columns = self._model.feature_names_in_
return ret
def evaluate(self, X):
"""评价指标"""
labels = self.predict(X)
silhouette = sklearn.metrics.silhouette_score(X, labels)
dbi = sklearn.metrics.davies_bouldin_score(X, labels)
ch = sklearn.metrics.calinski_harabasz_score(X, labels)
ret = {"silhouette coefficient": silhouette, "DBI": dbi, "CH": ch}
return ret
def choose_n_cluster(self, X, max_n=5):
"""聚类个数选择"""
# 计算不同聚类数下的轮廓系数
silhouette_scores = []
for k in range(2, max_n + 1):
kmeans = sklearn.cluster.KMeans(
n_clusters=k,
init=self.init,
n_init=self.n_init,
max_iter=self.max_iter,
verbose=self.verbose,
random_state=self.random_state,
copy_x=self.copy_x,
algorithm=self.algorithm,
).fit(X)
silhouette_score = sklearn.metrics.silhouette_score(X, kmeans.labels_)
silhouette_scores.append(silhouette_score)
# 找到轮廓系数最高的聚类数
elbow_k = np.argmax(silhouette_scores) + 2
return elbow_k
"""
综合评价
"""
\ No newline at end of file
import numpy as np
from cieccproject.ciecc.algorithms.base import BaseEstimator
class AHP(BaseEstimator):
"""层次分析法是 多目标决策问题 的一个解决方案。"""
def __init__(self):
self.RI = (0, 0, 0.58, 0.9, 1.12, 1.24, 1.32, 1.41, 1.45, 1.49)
self.weight = None
self.max_eigenvalue = None
self.max_eigenvector = None
self.ci_value = None
self.ri_value = None
self.cr_value = None
self.consistency = None
self.data = None
def __check_data(self, data):
data = np.array(data)
n, n1 = data.shape
if n != n1:
raise ValueError('不是一个方阵')
for i in range(n):
for j in range(n):
if np.abs(data[i, j] * data[j, i] - 1) > 1e-7:
raise ValueError('不是反互对称矩阵')
# 如果超过10个指标,输出为预览前10个指标
data = data[0:len(self.RI), 0:len(self.RI)]
return data
def __calculate_weights(self, data):
self.data = np.array(data)
m = len(data)
# 权重值
self.weight = (data / data.sum(axis=0)).sum(axis=1) / m
# 特征向量
self.max_eigenvector = (self.weight * data).sum(axis=1)
# 最大特征根
self.max_eigenvalue = sum(self.max_eigenvector / (m * self.weight))
# 判断一致性
self.ci_value = (self.max_eigenvalue - m) / (m - 1)
self.cr_value = self.ci_value / self.RI[m - 1]
self.ri_value = self.RI[m - 1]
if self.cr_value < 0.1:
self.consistency = True
else:
self.consistency = False
def fit(self, X, y=None):
data = self.__check_data(X)
self.__calculate_weights(data)
def predict(self, X):
pass
def score(self, X, y):
pass
def summary(self):
print('输出结果1:指标指数')
print(self.data)
print('输出结果2:AHP层次分析结果')
print(f'特征向量:{self.max_eigenvector}')
print(f'权重值:{self.weight}')
print(f'最大特征根:{self.max_eigenvalue}')
print(f'CI值:{self.ci_value}')
print('输出结果3:一致性检验结果')
print(f'最大特征根:{self.max_eigenvalue}')
print(f'CI值:{self.ci_value}')
print(f'RI值:{self.ri_value}')
print(f'CR值:{self.cr_value}')
print(f'一致性检验结果:{self.consistency}')
def to_json(self):
results_json = {
'result1': {'name': '输出结果1:指标指数', 'value': self.data.tolist()},
'result2': {'name': '输出结果2:AHP层次分析结果',
'value': {'特征向量': self.max_eigenvector.tolist(), '权重值': self.weight.tolist(),
'最大特征根': self.max_eigenvalue, 'CI值': self.ci_value}},
'result3': {'name': '输出结果3:一致性检验结果',
'value': {'最大特征根': self.max_eigenvalue.tolist(), 'CI值': self.ci_value, 'RI值': self.ri_value,
'CR值': self.cr_value, '一致性检验结果': self.consistency}}
}
return results_json
import pandas as pd
import numpy as np
from cieccproject.ciecc.algorithms.base import BaseEstimator
def normalize_dataframe(df, positive_columns, negative_columns):
"""数据归一化"""
for col in df.columns:
if col in positive_columns:
max_value = df[col].max()
min_value = df[col].min()
df.loc[:, col] = (df[col] - min_value) / (max_value - min_value)
elif col in negative_columns:
max_value = df[col].max()
min_value = df[col].min()
df.loc[:, col] = (max_value - df[col]) / (max_value - min_value)
return df
def standardize_dataframe(df):
"""数据标准化"""
df = df / np.sqrt((df ** 2).sum())
return df
def data_direction_1(datas, offset=0):
"""
指标属性同向化-极小型指标:期望指标值越小越好(如患病率、死亡率等)
"""
def normalization(data):
return 1 / (data + offset)
return list(map(normalization, datas))
def data_direction_2(datas, x_min, x_max):
"""
指标属性同向化-中间型指标:期望指标值既不要太大也不要太小,适当取中间值最好(如水质量评估 PH 值)
"""
def normalization(data):
if data <= x_min or data >= x_max:
return 0
elif x_min < data < (x_min + x_max) / 2:
return 2 * (data - x_min) / (x_max - x_min)
elif x_max > data >= (x_min + x_max) / 2:
return 2 * (x_max - data) / (x_max - x_min)
return list(map(normalization, datas))
def data_direction_3(datas, x_min, x_max, x_minimum, x_maximum):
"""
指标属性同向化-区间型指标:期望指标的取值最好落在某一个确定的区间最好(如体温)
"""
def normalization(data):
if x_min <= data <= x_max:
return 1
elif data <= x_minimum or data >= x_maximum:
return 0
elif x_max < data < x_maximum:
return 1 - (data - x_max) / (x_maximum - x_max)
elif x_min > data > x_minimum:
return 1 - (x_min - data) / (x_min - x_minimum)
return list(map(normalization, datas))
class TOPSIS(BaseEstimator):
def __init__(self, positive_columns=None, negative_columns=None, index_column=None, weights=None,
standardization=False):
# 正向指标名称
self.positive_columns = positive_columns
# 负向指标名称
self.negative_columns = negative_columns
# 索引项
self.index_column = index_column
# 权重w
self.weights = weights
# 是否标准化
self.standardization = standardization
# 评估数据
self.data = None
# 信息熵值e
self.entropy = None
# 信息效用值d
self.coefficient = None
# 正理想解与负理想解
self.ideal_solutions = None
# 评价法计算结果
self.results = None
def fit(self, X, y=None):
self.data = X[self.positive_columns + self.negative_columns]
self.data.index = X[self.index_column]
# 归一化
std_df = normalize_dataframe(self.data.copy(), self.positive_columns, self.negative_columns)
# 标准化
if self.standardization:
std_df = standardize_dataframe(std_df)
# 距离
if self.weights is None:
self.weights = self.__entropy_weight(std_df)
# TOPSIS评价法
self.results = self.__topsis(std_df, self.weights)
return self
def __entropy_weight(self, df):
"""熵权法"""
# 归一化
normalized_data = df / df.sum(axis=0)
# 计算熵值
self.entropy = np.nansum(-normalized_data * np.log(np.maximum(normalized_data, 0.00001)) / np.log(len(df)),
axis=0)
# self.entropy = np.nansum(-normalized_data * np.log(normalized_data) / np.log(len(df)),axis=0)
# 信息效用值d
self.coefficient = 1 - self.entropy
# 计算权系数
self.weights = (1 - self.entropy) / (1 - self.entropy).sum()
return self.weights
def __topsis(self, df, weight=None):
"""TOPSIS评价法计算"""
# 最优最劣方案
Z = pd.DataFrame([df.max(), df.min()], index=['正理想解', '负理想解'])
self.ideal_solutions = Z.T
# 最优或最劣解的距离
result = pd.DataFrame(index=df.index)
result['正理想解距离(D+)'] = np.sqrt(((df - Z.loc['正理想解']) ** 2 * weight).sum(axis=1))
result['负理想解距离(D-)'] = np.sqrt(((df - Z.loc['负理想解']) ** 2 * weight).sum(axis=1))
# 综合得分指数
result['综合得分指数'] = result['负理想解距离(D-)'] / (result['负理想解距离(D-)'] + result['正理想解距离(D+)'])
result['排序'] = result.rank(ascending=False)['综合得分指数']
return result
def get_params(self, deep=True):
pass
def set_params(self, **params):
pass
def predict(self, X):
pass
def score(self, X, y=None):
pass
def summary(self):
"""结果汇总"""
if self.entropy is not None:
print('输出结果:指标权重计算')
ew_array = np.array([self.entropy, self.coefficient, self.weights]).T
ew_df = pd.DataFrame(ew_array, columns=['信息熵值e', '信息效用值d', '权重'], index=self.data.columns)
print(ew_df)
print('输出结果:TOPSIS评价法计算结果')
print(self.results)
print('输出结果:中间值展示')
print(self.ideal_solutions)
def to_json(self):
if self.entropy is not None:
ew_array = np.array([self.entropy, self.coefficient, self.weights]).T
ew_df = pd.DataFrame(ew_array, columns=['信息熵值e', '信息效用值d', '权重'], index=self.data.columns)
results_json = {
'result1': {'name': '输出结果1:指标权重计算', 'value': eval(ew_df.to_json())},
'result2': {'name': '输出结果2:TOPSIS评价法计算结果', 'value': eval(self.results.to_json())},
'result3': {'name': '输出结果3:中间值展示', 'value': eval(self.ideal_solutions.to_json())}
}
else:
results_json = {
'result1': {'name': '输出结果1:秩值计算', 'value': eval(self.results.to_json())},
'result2': {'name': '输出结果2:RSR分布表', 'value': eval(self.ideal_solutions.to_json())}
}
return results_json
"""
关联分析
"""
\ No newline at end of file
"""
降维方法
"""
\ No newline at end of file
"""
数据预处理
"""
\ No newline at end of file
from cieccproject.ciecc.algorithms.base import BaseTransformer
from sklearn.preprocessing import Binarizer as _Binarizer
class Binarizer(BaseTransformer):
def __init__(self, threshold=0.0, copy=True):
self._scaler = _Binarizer(threshold=threshold, copy=copy)
def fit(self, X):
self._scaler.fit(X)
return self
def transform(self, X):
return self._scaler.transform(X)
def fit_transform(self, X):
return self._scaler.fit_transform(X)
def inverse_transform(self, X):
return self._scaler.inverse_transform(X)
from cieccproject.ciecc.algorithms.base import BaseTransformer
import pandas as pd
class DescriptiveStats(BaseTransformer):
def __init__(self, percentiles=None, include=None, exclude=None, datetime_is_numeric=False):
self.percentiles = percentiles
self.include = include
self.exclude = exclude
self.datetime_is_numeric = datetime_is_numeric
def fit(self, X):
self.df_ = pd.DataFrame(X)
return self
def transform(self, X):
return self.df_.describe(percentiles=self.percentiles, include=self.include, exclude=self.exclude,
datetime_is_numeric=self.datetime_is_numeric)
def fit_transform(self, X):
self.df_ = pd.DataFrame(X)
return self.df_.describe(percentiles=self.percentiles, include=self.include, exclude=self.exclude,
datetime_is_numeric=self.datetime_is_numeric)
from cieccproject.ciecc.algorithms.base import BaseTransformer
from sklearn.preprocessing import FunctionTransformer as _FunctionTransformer
class FunctionTransformer(BaseTransformer):
def __init__(self, func=None, inverse_func=None, validate=False, accept_sparse=False,
check_inverse=True, kw_args=None, inv_kw_args=None):
self._scaler = _FunctionTransformer(func=func, inverse_func=inverse_func, validate=validate,
accept_sparse=accept_sparse, check_inverse=check_inverse, kw_args=kw_args,
inv_kw_args=inv_kw_args)
def fit(self, X):
self._scaler.fit(X)
return self
def transform(self, X):
return self._scaler.transform(X)
def fit_transform(self, X):
return self._scaler.fit_transform(X)
def inverse_transform(self, X):
return self._scaler.inverse_transform(X)
from cieccproject.ciecc.algorithms.base import BaseTransformer
from sklearn.impute import SimpleImputer as _SimpleImputer
from sklearn.experimental import enable_iterative_imputer
from sklearn.impute import IterativeImputer as _IterativeImputer
from sklearn.impute import KNNImputer as _KNNImputer
class Imputer(BaseTransformer):
def __init__(self, method='simple', **kwargs):
if method == 'simple':
# 单变量插补
self._scaler = _SimpleImputer(**kwargs)
elif method == 'iterative':
# 多变量插补
self._scaler = _IterativeImputer(**kwargs)
else:
# 最邻近插补
self._scaler = _KNNImputer(**kwargs)
def fit(self, X):
self._scaler.fit(X)
return self
def transform(self, X):
return self._scaler.transform(X)
def fit_transform(self, X):
return self._scaler.fit_transform(X)
from cieccproject.ciecc.algorithms.base import BaseTransformer
from sklearn.preprocessing import QuantileTransformer as _QuantileTransformer
from sklearn.preprocessing import PowerTransformer as _PowerTransformer
class NoLinearTransformer(BaseTransformer):
def __init__(self, method='quantile', **kwargs):
if method == 'quantile':
# 分位数转换
self._scaler = _QuantileTransformer(**kwargs)
else:
# 幂函数转换
self._scaler = _PowerTransformer(**kwargs)
def fit(self, X):
self._scaler.fit(X)
return self
def transform(self, X):
return self._scaler.transform(X)
def fit_transform(self, X):
return self._scaler.fit_transform(X)
def inverse_transform(self, X):
return self._scaler.inverse_transform(X)
from cieccproject.ciecc.algorithms.base import BaseTransformer
from sklearn.preprocessing import Normalizer as _Normalizer
class Normalizer(BaseTransformer):
def __init__(self, norm='l2', copy=True):
self._scaler = _Normalizer(norm=norm, copy=copy)
def fit(self, X):
self._scaler.fit(X)
return self
def transform(self, X):
return self._scaler.transform(X)
def fit_transform(self, X):
return self._scaler.fit_transform(X)
def inverse_transform(self, X):
return self._scaler.inverse_transform(X)
from cieccproject.ciecc.algorithms.base import BaseTransformer
from sklearn.preprocessing import OneHotEncoder as _OneHotEncoder
import numpy as np
class OneHotEncoder(BaseTransformer):
def __init__(self, categories='auto', drop=None, sparse=True, dtype=np.float64, handle_unknown='error'):
self._scaler = _OneHotEncoder(categories=categories, drop=drop, sparse=sparse, dtype=dtype,
handle_unknown=handle_unknown)
def fit(self, X):
self._scaler.fit(X)
return self
def transform(self, X):
return self._scaler.transform(X)
def fit_transform(self, X):
return self._scaler.fit_transform(X)
def inverse_transform(self, X):
return self._scaler.inverse_transform(X)
from cieccproject.ciecc.algorithms.base import BaseTransformer
from sklearn.preprocessing import PolynomialFeatures as _PolynomialFeatures
class PolynomialTransformer(BaseTransformer):
def __init__(self, degree=2, interaction_only=False, include_bias=True, order='C'):
self._scaler = _PolynomialFeatures(degree=degree, interaction_only=interaction_only,
include_bias=include_bias, order=order)
def fit(self, X):
self._scaler.fit(X)
return self
def transform(self, X):
return self._scaler.transform(X)
def fit_transform(self, X):
return self._scaler.fit_transform(X)
\ No newline at end of file
This diff is collapsed.
from cieccproject.ciecc.algorithms.base import BaseTransformer
from sklearn.preprocessing import MinMaxScaler as _MinMaxScaler
from sklearn.preprocessing import MaxAbsScaler as _MaxAbsScaler
from sklearn.preprocessing import RobustScaler as _RobustScaler
class ZoomScaler(BaseTransformer):
def __init__(self, method='minmax'):
if method == 'minmax':
self._scaler = _MinMaxScaler(feature_range=(0, 1))
elif method == 'maxabs':
self._scaler = _MaxAbsScaler()
else:
self._scaler = _RobustScaler(quantile_range=(25.0, 75.0))
def fit(self, X):
self._scaler.fit(X)
return self
def transform(self, X):
return self._scaler.transform(X)
def fit_transform(self, X):
return self._scaler.fit_transform(X)
def inverse_transform(self, X):
return self._scaler.inverse_transform(X)
"""
领域分析
"""
\ No newline at end of file
from cieccproject.ciecc.algorithms.base import BaseEstimator
import sklearn.linear_model
import numpy as np
class LassoRegression(BaseEstimator):
def __init__(
self,
alpha="auto",
fit_intercept=True,
precompute=False,
copy_X=True,
max_iter=1000,
tol=1e-4,
warm_start=False,
positive=False,
random_state=None,
selection="cyclic",
):
"""在构造函数中指定训练模型所需的超参"""
self.alpha = alpha
self.fit_intercept = fit_intercept
self.precompute = precompute
self.copy_X = copy_X
self.max_iter = max_iter
self.tol = tol
self.warm_start = warm_start
self.positive = positive
self.random_state = random_state
self.selection = selection
def fit(self, X, y, sample_weight=None, check_input=True):
if self.alpha == "auto":
self.alpha = self.cal_alpha(X, y)
model = sklearn.linear_model.Lasso(
alpha=self.alpha,
fit_intercept=self.fit_intercept,
precompute=self.precompute,
copy_X=self.copy_X,
max_iter=self.max_iter,
tol=self.tol,
warm_start=self.warm_start,
positive=self.positive,
random_state=self.random_state,
selection=self.selection,
)
self._model = model.fit(X, np.ravel(y), sample_weight, check_input)
return self
def predict(self, X):
return self._model.predict(X)
def score(self, X, y):
return self.rsquared(X, np.ravel(y))
def summary(self):
summ = {"alpha": self.alpha, "intercept": self._model.intercept_}
for i in range(self._model.n_features_in_):
summ[self._model.feature_names_in_[i]] = self._model.coef_[i]
return summ
def cal_alpha(self, X, y):
alphas = np.logspace(-5, 2, 500)
return (
sklearn.linear_model.LassoCV(
alphas=alphas,
fit_intercept=self.fit_intercept,
precompute=self.precompute,
max_iter=self.max_iter,
tol=self.tol,
copy_X=self.copy_X,
positive=self.positive,
random_state=self.random_state,
selection=self.selection,
)
.fit(X, np.ravel(y))
.alpha_
)
def rsquared(self, X, y):
return self._model.score(X, np.ravel(y))
from cieccproject.ciecc.algorithms.base import BaseEstimator
import statsmodels.api as sm
import statsmodels.stats.outliers_influence
import sklearn.preprocessing
class LinearRegression(BaseEstimator):
def __init__(self, method="pinv", cov_type="nonrobust", cov_kwds=None, use_t=None):
"""在构造函数中指定训练模型所需的超参"""
self.method = method
self.cov_type = cov_type
self.cov_kwds = cov_kwds
self.use_t = use_t
def fit(self, X, y, missing="none", hasconst=None):
x_with_const = sm.add_constant(X)
model = sm.OLS(y, x_with_const, missing=missing, hasconst=hasconst)
self._model = model.fit(
method=self.method,
cov_type=self.cov_type,
cov_kwds=self.cov_kwds,
use_t=self.use_t,
)
x_std = sklearn.preprocessing.StandardScaler().fit_transform(X)
y_std = sklearn.preprocessing.StandardScaler().fit_transform(y)
self._std_model = sm.OLS(y_std, x_std, missing=missing, hasconst=hasconst).fit(
method=self.method,
cov_type=self.cov_type,
cov_kwds=self.cov_kwds,
use_t=self.use_t,
)
self._vif = []
for i in range(x_std.shape[1]):
self._vif.append(
statsmodels.stats.outliers_influence.variance_inflation_factor(x_std, i)
)
return self
def predict(self, X):
x_with_const = sm.add_constant(X)
return self._model.predict(x_with_const)
def score(self, X, y):
return self._model.rsquared
def summary(self):
return self._model.summary()
def params(self):
"""提取回归系数"""
return self._model.params
def std_params(self):
"""提取标准化回归系数"""
return self._std_model.params
def bse(self):
"""提取回归系数标准差"""
return self._model.bse
def pvalues(self):
"""提取回归系数p值"""
return self._model.pvalues
def tvalues(self):
"""提取回归系数t值"""
return self._model.tvalues
def vif(self):
"""提取变量VIF值"""
return self._vif
def rsquared(self):
"""提取模型R2"""
return self._model.rsquared
def adj_rsquared(self):
"""提取模型调整R2"""
return self._model.rsquared_adj
def f_test_value(self):
"""提取模型F检验统计量"""
return self._model.fvalue
def f_test_pvalue(self):
"""提取模型F检验p值"""
return self._model.f_pvalue
def conf_int(self):
"""提取回归系数置信区间 默认5%"""
return self._model.conf_int()
def fittedvalues(self):
"""提取模型预测值"""
return self._model.fittedvalues
from cieccproject.ciecc.algorithms.base import BaseEstimator
import sklearn.linear_model
import sklearn.metrics
import sklearn.preprocessing
import numpy as np
import pandas as pd
class LogisticRegression(BaseEstimator):
def __init__(
self,
penalty="l2",
dual=False,
tol=1e-4,
C=1.0,
fit_intercept=True,
intercept_scaling=1,
class_weight=None,
random_state=None,
solver="lbfgs",
max_iter=100,
multi_class="auto",
verbose=0,
warm_start=False,
n_jobs=None,
l1_ratio=None,
):
"""在构造函数中指定训练模型所需的超参"""
self.penalty = penalty
self.dual = dual
self.tol = tol
self.C = C
self.fit_intercept = fit_intercept
self.intercept_scaling = intercept_scaling
self.class_weight = class_weight
self.random_state = random_state
self.solver = solver
self.max_iter = max_iter
self.multi_class = multi_class
self.verbose = verbose
self.warm_start = warm_start
self.n_jobs = n_jobs
self.l1_ratio = l1_ratio
def fit(self, X, y, sample_weight=None):
model = sklearn.linear_model.LogisticRegression(
penalty=self.penalty,
dual=self.dual,
tol=self.tol,
C=self.C,
fit_intercept=self.fit_intercept,
intercept_scaling=self.intercept_scaling,
class_weight=self.class_weight,
random_state=self.random_state,
solver=self.solver,
max_iter=self.max_iter,
multi_class=self.multi_class,
verbose=self.verbose,
warm_start=self.warm_start,
n_jobs=self.n_jobs,
l1_ratio=self.l1_ratio,
)
self._model = model.fit(X, np.ravel(y), sample_weight)
return self
def predict(self, X):
return self._model.predict(X)
def score(self, X, y):
return self.accuracy(X, np.ravel(y))
def summary(self):
summ = {"intercept": self._model.intercept_, "coefficient": self._model.coef_}
return summ
def class_freq(self, y: pd.DataFrame):
total = y.count().iloc[0]
ret = {"total": {"frequency": total, "percentage": 100}}
for c in self._model.classes_:
count = y.value_counts()[c]
ret[c] = {"frequency": count, "percentage": (count * 100 / total)}
return ret
def confusion_matrix(self, X, y):
return sklearn.metrics.confusion_matrix(np.ravel(y), self._model.predict(X))
def accuracy(self, X, y):
return self._model.score(X, np.ravel(y))
def recall_rate(self, X, y):
return sklearn.metrics.recall_score(
np.ravel(y), self._model.predict(X), average="micro"
)
def precision_rate(self, X, y):
return sklearn.metrics.precision_score(
np.ravel(y), self._model.predict(X), average="micro"
)
def f1_score(self, X, y):
return sklearn.metrics.f1_score(
np.ravel(y), self._model.predict(X), average="micro"
)
def auc_score(self, X, y):
y_score = self._model.predict_proba(X)
y_one_hot = sklearn.preprocessing.label_binarize(y, classes=np.arange(len(self._model.classes_)))
fpr, tpr, threshold = sklearn.metrics.roc_curve(y_one_hot.ravel(), y_score.ravel())
return sklearn.metrics.auc(fpr, tpr)
from cieccproject.ciecc.algorithms.base import BaseEstimator
import sklearn.neural_network
import sklearn.metrics
import numpy as np
import time
class MLPRegression(BaseEstimator):
def __init__(
self,
hidden_layer_sizes=(100,),
activation="relu",
solver="adam",
alpha=0.0001,
batch_size="auto",
learning_rate="constant",
learning_rate_init=0.001,
power_t=0.5,
max_iter=200,
shuffle=True,
random_state=None,
tol=1e-4,
verbose=False,
warm_start=False,
momentum=0.9,
nesterovs_momentum=True,
early_stopping=False,
validation_fraction=0.1,
beta_1=0.9,
beta_2=0.999,
epsilon=1e-8,
n_iter_no_change=10,
max_fun=15000,
):
"""在构造函数中指定训练模型所需的超参"""
self.hidden_layer_sizes = hidden_layer_sizes
self.activation = activation
self.solver = solver
self.alpha = alpha
self.batch_size = batch_size
self.learning_rate = learning_rate
self.learning_rate_init = learning_rate_init
self.power_t = power_t
self.max_iter = max_iter
self.shuffle = shuffle
self.random_state = random_state
self.tol = tol
self.verbose = verbose
self.warm_start = warm_start
self.momentum = momentum
self.nesterovs_momentum = nesterovs_momentum
self.early_stopping = early_stopping
self.validation_fraction = validation_fraction
self.beta_1 = beta_1
self.beta_2 = beta_2
self.epsilon = epsilon
self.n_iter_no_change = n_iter_no_change
self.max_fun = max_fun
def fit(self, X, y):
model = sklearn.neural_network.MLPRegressor(
hidden_layer_sizes=self.hidden_layer_sizes,
activation=self.activation,
solver=self.solver,
alpha=self.alpha,
batch_size=self.batch_size,
learning_rate=self.learning_rate,
learning_rate_init=self.learning_rate_init,
power_t=self.power_t,
max_iter=self.max_iter,
shuffle=self.shuffle,
random_state=self.random_state,
tol=self.tol,
verbose=self.verbose,
warm_start=self.warm_start,
momentum=self.momentum,
nesterovs_momentum=self.nesterovs_momentum,
early_stopping=self.early_stopping,
validation_fraction=self.validation_fraction,
beta_1=self.beta_1,
beta_2=self.beta_2,
epsilon=self.epsilon,
n_iter_no_change=self.n_iter_no_change,
max_fun=self.max_fun,
)
start_time = time.time()
self._model = model.fit(X, np.ravel(y))
end_time = time.time()
self.time_trained = end_time - start_time
return self
def predict(self, X):
return self._model.predict(X)
def score(self, X, y):
return self.rsquared(X, np.ravel(y))
def summary(self):
summ = {
"model parameters": {
"time_trained": self.time_trained,
"activation function": self.activation,
"solver for weight optimization": self.solver,
"learning rate schedule for weight updates": self.learning_rate,
"initial learning rate": self.learning_rate_init,
"strength of the L2 regularization term": self.alpha,
"number of iterations": self._model.n_iter_,
"hidden layer sizes": self.hidden_layer_sizes,
}
}
return summ
def mse(self, X, y):
return sklearn.metrics.mean_squared_error(np.ravel(y), self._model.predict(X))
def rmse(self, X, y):
return sklearn.metrics.mean_squared_error(
np.ravel(y), self._model.predict(X), squared=False
)
def mae(self, X, y):
return sklearn.metrics.mean_absolute_error(np.ravel(y), self._model.predict(X))
def mape(self, X, y):
return (
sklearn.metrics.mean_absolute_percentage_error(
np.ravel(y), self._model.predict(X)
)
* 100
)
def rsquared(self, X, y):
return self._model.score(X, np.ravel(y))
from cieccproject.ciecc.algorithms.base import BaseEstimator
import sklearn.linear_model
import sklearn.preprocessing
import numpy as np
class PolynomialRegression(BaseEstimator):
def __init__(
self,
fit_intercept=True,
copy_X=True,
n_jobs=None,
positive=False,
degree=2,
interaction_only=False,
include_bias=True,
order="C",
):
"""在构造函数中指定训练模型所需的超参"""
self.fit_intercept = fit_intercept
self.copy_X = copy_X
self.n_jobs = n_jobs
self.positive = positive
self.degree = degree
self.interaction_only = interaction_only
self.include_bias = include_bias
self.order = order
def fit(self, X, y):
x_poly = sklearn.preprocessing.PolynomialFeatures(
degree=self.degree,
interaction_only=self.interaction_only,
include_bias=self.include_bias,
order=self.order,
).fit_transform(X)
model = sklearn.linear_model.LinearRegression(
fit_intercept=self.fit_intercept,
copy_X=self.copy_X,
n_jobs=self.n_jobs,
positive=self.positive,
)
self._model = model.fit(x_poly, np.ravel(y))
return self
def predict(self, X):
x_poly = sklearn.preprocessing.PolynomialFeatures(
degree=self.degree,
interaction_only=self.interaction_only,
include_bias=self.include_bias,
order=self.order,
).fit_transform(X)
return self._model.predict(x_poly)
def score(self, X, y):
x_poly = sklearn.preprocessing.PolynomialFeatures(
degree=self.degree,
interaction_only=self.interaction_only,
include_bias=self.include_bias,
order=self.order,
).fit_transform(X)
return self._model.score(x_poly, np.ravel(y))
def summary(self):
summ = {
"coefficient": self._model.coef_,
"intercept": self._model.intercept_[0],
}
return summ
from cieccproject.ciecc.algorithms.base import BaseEstimator
import sklearn.linear_model
import numpy as np
class RidgeRegression(BaseEstimator):
def __init__(
self,
alpha=1.0,
fit_intercept=True,
copy_X=True,
max_iter=None,
tol=1e-4,
solver="auto",
positive=False,
random_state=None,
):
"""在构造函数中指定训练模型所需的超参"""
self.alpha = alpha
self.fit_intercept = fit_intercept
self.copy_X = copy_X
self.max_iter = max_iter
self.tol = tol
self.solver = solver
self.positive = positive
self.random_state = random_state
def fit(self, X, y, sample_weight=None):
model = sklearn.linear_model.Ridge(
alpha=self.alpha,
fit_intercept=self.fit_intercept,
copy_X=self.copy_X,
max_iter=self.max_iter,
tol=self.tol,
solver=self.solver,
positive=self.positive,
random_state=self.random_state,
)
self._model = model.fit(X, np.ravel(y), sample_weight)
return self
def predict(self, X):
return self._model.predict(X)
def score(self, X, y):
return self._model.score(X, np.ravel(y))
def summary(self):
return self._model
from cieccproject.ciecc.algorithms.base import BaseEstimator
import sklearn.svm
import sklearn.metrics
import numpy as np
import time
class SvmRegression(BaseEstimator):
def __init__(
self,
kernel="rbf",
degree=3,
gamma="scale",
coef0=0.0,
tol=1e-3,
C=1.0,
epsilon=0.1,
shrinking=True,
cache_size=200,
verbose=False,
max_iter=-1,
):
"""在构造函数中指定训练模型所需的超参"""
self.kernel = kernel
self.degree = degree
self.gamma = gamma
self.coef0 = coef0
self.tol = tol
self.C = C
self.epsilon = epsilon
self.shrinking = shrinking
self.cache_size = cache_size
self.verbose = verbose
self.max_iter = max_iter
def fit(self, X, y, sample_weight=None):
model = sklearn.svm.SVR(
kernel=self.kernel,
degree=self.degree,
gamma=self.gamma,
coef0=self.coef0,
tol=self.tol,
C=self.C,
epsilon=self.epsilon,
shrinking=self.shrinking,
cache_size=self.cache_size,
verbose=self.verbose,
max_iter=self.max_iter,
)
start_time = time.time()
self._model = model.fit(X, np.ravel(y), sample_weight)
end_time = time.time()
self.time_trained = end_time - start_time
return self
def predict(self, X):
return self._model.predict(X)
def score(self, X, y):
return self.rsquared(X, np.ravel(y))
def summary(self):
summ = {
"model parameters": {
"time_trained": self.time_trained,
"regularization parameter": self.C,
"kernel function": self.kernel,
"kernel coefficient": self.gamma,
"independent term in kernel function": self.coef0,
"degree of the polynomial kernel function": self.degree,
"tolerance for stopping criterion": self.tol,
"limit on iterations within solver": self.max_iter,
"shrinking heuristic": self.shrinking,
}
}
return summ
def mse(self, X, y):
return sklearn.metrics.mean_squared_error(np.ravel(y), self._model.predict(X))
def rmse(self, X, y):
return sklearn.metrics.mean_squared_error(
np.ravel(y), self._model.predict(X), squared=False
)
def mae(self, X, y):
return sklearn.metrics.mean_absolute_error(np.ravel(y), self._model.predict(X))
def mape(self, X, y):
return (
sklearn.metrics.mean_absolute_percentage_error(
np.ravel(y), self._model.predict(X)
)
* 100
)
def rsquared(self, X, y):
return self._model.score(X, np.ravel(y))
"""
统计检验
"""
\ No newline at end of file
"""
时间序列分析
"""
\ No newline at end of file
from cieccproject.ciecc.algorithms.base import BaseEstimator
import statsmodels.tsa.stattools
import statsmodels.stats.diagnostic
import pmdarima.arima
import sklearn.metrics
import pandas as pd
class ARIMA(BaseEstimator):
def __init__(
self,
order="auto",
seasonal_order=(0, 0, 0, 0),
start_params=None,
method="lbfgs",
maxiter=50,
suppress_warnings=False,
out_of_sample_size=0,
scoring="mse",
scoring_args=None,
trend=None,
with_intercept=True,
**sarimax_kwargs,
):
"""在构造函数中指定训练模型所需的超参"""
self.order = order
self.seasonal_order = seasonal_order
self.start_params = start_params
self.method = method
self.maxiter = maxiter
self.suppress_warnings = suppress_warnings
self.out_of_sample_size = out_of_sample_size
self.scoring = scoring
self.scoring_args = scoring_args
self.trend = trend
self.with_intercept = with_intercept
self.sarimax_kwargs = sarimax_kwargs
def fit(self, y, X=None, **fit_args):
if self.order == "auto":
y_diff = self.adf_test(y)
self.order = self.order_selection(y, y_diff)
else:
self.adf_test(y, choose_d=False, d=self.order[1])
self._model = pmdarima.arima.ARIMA(
order=self.order,
seasonal_order=self.seasonal_order,
start_params=self.start_params,
method=self.method,
maxiter=self.maxiter,
suppress_warnings=self.suppress_warnings,
out_of_sample_size=self.out_of_sample_size,
scoring=self.scoring,
scoring_args=self.scoring_args,
trend=self.trend,
with_intercept=self.with_intercept,
**self.sarimax_kwargs,
).fit(y=y, X=None, **fit_args)
return self
def predict(
self, n_periods=10, X=None, return_conf_int=False, alpha=0.05, **kwargs
):
return self._model.predict(
n_periods=n_periods,
X=X,
return_conf_int=return_conf_int,
alpha=alpha,
kwargs=kwargs,
)
def score(self, X, y):
return sklearn.metrics.r2_score(y, self._model.predict_in_sample())
def summary(self):
return self._model.summary()
def adf_test(self, y, choose_d=True, d=None):
zero_res = statsmodels.tsa.stattools.adfuller(y)
first_diff = pd.DataFrame(y).diff(1).dropna()
first_res = statsmodels.tsa.stattools.adfuller(first_diff)
second_diff = first_diff.diff(1).dropna()
second_res = statsmodels.tsa.stattools.adfuller(second_diff)
if choose_d:
print("ADF test")
print("zero difference")
print(
{
"t": zero_res[0],
"p-value": zero_res[1],
"AIC": zero_res[5],
"critical values": zero_res[4],
}
)
print("first difference")
print(
{
"t": first_res[0],
"p-value": first_res[1],
"AIC": first_res[5],
"critical values": first_res[4],
}
)
print("second difference")
print(
{
"t": second_res[0],
"p-value": second_res[1],
"AIC": second_res[5],
"critical values": second_res[4],
}
)
if zero_res[1] < 0.05:
print("choose zero difference")
return y
elif first_res[1] < 0.05:
print("choose first difference")
return first_diff
else:
print("choose second difference")
return second_diff
else:
if d == 0:
print("ADF test")
print("zero difference")
print(
{
"t": zero_res[0],
"p-value": zero_res[1],
"AIC": zero_res[5],
"critical values": zero_res[4],
}
)
elif d == 1:
print("ADF test")
print("first difference")
print(
{
"t": first_res[0],
"p-value": first_res[1],
"AIC": first_res[5],
"critical values": first_res[4],
}
)
elif d == 2:
print("ADF test")
print("second difference")
print(
{
"t": second_res[0],
"p-value": second_res[1],
"AIC": second_res[5],
"critical values": second_res[4],
}
)
else:
raise Exception("Invalid d value.")
def order_selection(self, y, y_diff):
# 一般阶数不超过length/10
pmax = int(len(y_diff) / 10)
# 一般阶数不超过length/10
qmax = int(len(y_diff) / 10)
return pmdarima.arima.auto_arima(
y=y, start_p=0, start_q=0, max_p=pmax, max_q=qmax
).order
def df_residuals(self):
return self._model.df_resid()
def q_statistics(self, y):
return statsmodels.stats.diagnostic.acorr_ljungbox(y)
"""
数据集管理
"""
\ No newline at end of file
import pandas as pd
from cieccproject.ciecc.datasets.econdataframe import EconDataFrame
class Datasets(object):
"""数据对象操作类"""
@staticmethod
def read_csv(file_name, nrows=None):
"""从csv文件中读取数据"""
df = pd.read_csv(file_name, nrows=nrows)
return EconDataFrame(df)
@staticmethod
def read_excel(file_name, nrows=None):
"""从excel文件中读取数据"""
df = pd.read_excel(file_name, nrows=nrows)
return EconDataFrame(df)
@staticmethod
def read_json(self):
"""从json文件中读取数据"""
pass
@staticmethod
def read_db(self):
"""从SQL数据库中读取数据"""
pass
@staticmethod
def load_array(numpy_array):
"""从numpy数组中加载数据"""
df = pd.DataFrame(numpy_array)
return EconDataFrame(df)
@staticmethod
def load_data(self):
"""加载内置的测试数据集"""
pass
import json
import warnings
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
class EconDataFrame(pd.DataFrame):
"""
A EconDataFrame object is a pandas.DataFrame that has a column
with system:time. In addition to the standard DataFrame constructor arguments,
EconDataFrame also accepts the following keyword arguments
"""
_metadata = ["system:time"]
@property
def _constructor(self):
"""This is the key to letting Pandas know how to keep
derivative `SomeData` the same type as yours. It should
be enough to return the name of the Class. However, in
some cases, `__finalize__` is not called and `my_attr` is
not carried over. We can fix that by constructing a callable
that makes sure to call `__finlaize__` every time."""
def _c(*args, **kwargs):
return EconDataFrame(*args, **kwargs).__finalize__(self)
return _c
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@classmethod
def from_json(cls, data, **kwargs):
"""
Construct GeoDataFrame from dict of array-like or dicts by
overriding DataFrame.from_dict method with geometry and crs
"""
dataframe = super().from_dict(data, **kwargs)
return EconDataFrame(dataframe)
@classmethod
def from_file(cls, filename, **kwargs):
"""Alternate constructor to create a ``EconDataFrame`` from a file.
"""
dataframe = pd.read_csv(filename, **kwargs)
return EconDataFrame(dataframe)
def get_columns(self):
"""返回DataFrame列名称"""
return self.columns.to_list()
def get_shape(self):
"""返回DataFrame行列数"""
return len(self.index), len(self.columns)
def get_size(self):
"""返回DataFrame行数"""
return len(self)
def select(self, names: list):
return self[names]
class EconPanel(object):
pass
import json
import warnings
import numpy as np
import pandas as pd
from pandas import Series, MultiIndex
from pandas.core.internals import SingleBlockManager
_SERIES_WARNING_MSG = """\
You are passing non-geometry data to the GeoSeries constructor. Currently,
it falls back to returning a pandas Series. But in the future, we will start
to raise a TypeError instead."""
class EconSeries(Series):
"""
A Series object designed to store economic data objects.
"""
_metadata = ["name"]
def __init__(self, *args, **kwargs):
# need to overwrite Series init to prevent calling it for GeoSeries
# (doesn't know crs, all work is already done above)
super().__init__(*args, **kwargs)
@property
def geometry(self):
return self
@classmethod
def from_file(cls, filename, **kwargs):
"""Alternate constructor to create a ``EconSeries`` from a file.
"""
from .econdataframe import EconDataFrame
df = EconDataFrame.from_file(filename, **kwargs)
return EconSeries(df.geometry, crs=df.crs)
def to_file(self, filename, driver=None, index=None, **kwargs):
"""Write the ``EconSeries`` to a file.
"""
from .econdataframe import EconDataFrame
data = EconDataFrame({"geometry": self}, index=self.index)
data.crs = self.crs
data.to_file(filename, driver, index=index, **kwargs)
#
# Implement pandas methods
#
def _wrapped_pandas_method(self, mtd, *args, **kwargs):
"""Wrap a generic pandas method to ensure it returns a EconSeries"""
val = getattr(super(), mtd)(*args, **kwargs)
if type(val) == Series:
val.__class__ = EconSeries
val.crs = self.crs
return val
def __getitem__(self, key):
return self._wrapped_pandas_method("__getitem__", key)
def __finalize__(self, other, method=None, **kwargs):
"""propagate metadata from other to self"""
# NOTE: backported from pandas master (upcoming v0.13)
for name in self._metadata:
object.__setattr__(self, name, getattr(other, name, None))
return self
def isna(self):
"""
Detect missing values.
"""
if self.is_empty.any():
warnings.warn(
"GeoSeries.isna() previously returned True for both missing (None) "
"and empty geometries. Now, it only returns True for missing values. "
"Since the calling GeoSeries contains empty geometries, the result "
"has changed compared to previous versions of GeoPandas.\n"
"Given a GeoSeries 's', you can use 's.is_empty | s.isna()' to get "
"back the old behaviour.\n\n"
"To further ignore this warning, you can do: \n"
"import warnings; warnings.filterwarnings('ignore', 'GeoSeries.isna', "
"UserWarning)",
UserWarning,
stacklevel=2,
)
return super().isna()
def isnull(self):
"""Alias for `isna` method. See `isna` for more detail."""
return self.isna()
def notna(self):
"""
Detect non-missing values.
"""
if self.is_empty.any():
warnings.warn(
"GeoSeries.notna() previously returned False for both missing (None) "
"and empty geometries. Now, it only returns False for missing values. "
"Since the calling GeoSeries contains empty geometries, the result "
"has changed compared to previous versions of GeoPandas.\n"
"Given a GeoSeries 's', you can use '~s.is_empty & s.notna()' to get "
"back the old behaviour.\n\n"
"To further ignore this warning, you can do: \n"
"import warnings; warnings.filterwarnings('ignore', "
"'GeoSeries.notna', UserWarning)",
UserWarning,
stacklevel=2,
)
return super().notna()
def notnull(self):
"""Alias for `notna` method. See `notna` for more detail."""
return self.notna()
def to_json(self, **kwargs):
"""
Returns a GeoJSON string representation of the GeoSeries.
"""
return json.dumps(self.__geo_interface__, **kwargs)
"""
评估方法
"""
\ No newline at end of file
"""
基础函数库
"""
from itertools import compress
import numpy as np
from scipy.sparse import issparse
from .version import parse as parse_version
np_version = parse_version(np.__version__)
def _determine_key_type(key, accept_slice=True):
"""Determine the data type of key.
Parameters
----------
key : scalar, slice or array-like
The key from which we want to infer the data type.
accept_slice : bool, default=True
Whether or not to raise an error if the key is a slice.
Returns
-------
dtype : {'int', 'str', 'bool', None}
Returns the data type of key.
"""
err_msg = (
"No valid specification of the columns. Only a scalar, list or "
"slice of all integers or all strings, or boolean mask is "
"allowed"
)
dtype_to_str = {int: "int", str: "str", bool: "bool", np.bool_: "bool"}
array_dtype_to_str = {
"i": "int",
"u": "int",
"b": "bool",
"O": "str",
"U": "str",
"S": "str",
}
if key is None:
return None
if isinstance(key, tuple(dtype_to_str.keys())):
try:
return dtype_to_str[type(key)]
except KeyError:
raise ValueError(err_msg)
if isinstance(key, slice):
if not accept_slice:
raise TypeError(
"Only array-like or scalar are supported. A Python slice was given."
)
if key.start is None and key.stop is None:
return None
key_start_type = _determine_key_type(key.start)
key_stop_type = _determine_key_type(key.stop)
if key_start_type is not None and key_stop_type is not None:
if key_start_type != key_stop_type:
raise ValueError(err_msg)
if key_start_type is not None:
return key_start_type
return key_stop_type
if isinstance(key, (list, tuple)):
unique_key = set(key)
key_type = {_determine_key_type(elt) for elt in unique_key}
if not key_type:
return None
if len(key_type) != 1:
raise ValueError(err_msg)
return key_type.pop()
if hasattr(key, "dtype"):
try:
return array_dtype_to_str[key.dtype.kind]
except KeyError:
raise ValueError(err_msg)
raise ValueError(err_msg)
def _array_indexing(array, key, key_dtype, axis):
"""Index an array or scipy.sparse consistently across NumPy version."""
if np_version < parse_version("1.12") or issparse(array):
# FIXME: Remove the check for NumPy when using >= 1.12
# check if we have an boolean array-likes to make the proper indexing
if key_dtype == "bool":
key = np.asarray(key)
if isinstance(key, tuple):
key = list(key)
return array[key] if axis == 0 else array[:, key]
def _pandas_indexing(X, key, key_dtype, axis):
"""Index a pandas dataframe or a series."""
if hasattr(key, "shape"):
# Work-around for indexing with read-only key in pandas
# FIXME: solved in pandas 0.25
key = np.asarray(key)
key = key if key.flags.writeable else key.copy()
elif isinstance(key, tuple):
key = list(key)
if key_dtype == "int" and not (isinstance(key, slice) or np.isscalar(key)):
# using take() instead of iloc[] ensures the return value is a "proper"
# copy that will not raise SettingWithCopyWarning
return X.take(key, axis=axis)
else:
# check whether we should index with loc or iloc
indexer = X.iloc if key_dtype == "int" else X.loc
return indexer[:, key] if axis else indexer[key]
def _list_indexing(X, key, key_dtype):
"""Index a Python list."""
if np.isscalar(key) or isinstance(key, slice):
# key is a slice or a scalar
return X[key]
if key_dtype == "bool":
# key is a boolean array-like
return list(compress(X, key))
# key is a integer array-like of key
return [X[idx] for idx in key]
def _safe_indexing(X, indices, *, axis=0):
"""Return rows, items or columns of X using indices.
.. warning::
This utility is documented, but **private**. This means that
backward compatibility might be broken without any deprecation
cycle.
Parameters
----------
X : array-like, sparse-matrix, list, pandas.DataFrame, pandas.Series
Data from which to sample rows, items or columns. `list` are only
supported when `axis=0`.
indices : bool, int, str, slice, array-like
- If `axis=0`, boolean and integer array-like, integer slice,
and scalar integer are supported.
- If `axis=1`:
- to select a single column, `indices` can be of `int` type for
all `X` types and `str` only for dataframe. The selected subset
will be 1D, unless `X` is a sparse matrix in which case it will
be 2D.
- to select multiples columns, `indices` can be one of the
following: `list`, `array`, `slice`. The type used in
these containers can be one of the following: `int`, 'bool' and
`str`. However, `str` is only supported when `X` is a dataframe.
The selected subset will be 2D.
axis : int, default=0
The axis along which `X` will be subsampled. `axis=0` will select
rows while `axis=1` will select columns.
Returns
-------
subset
Subset of X on axis 0 or 1.
Notes
-----
CSR, CSC, and LIL sparse matrices are supported. COO sparse matrices are
not supported.
"""
if indices is None:
return X
if axis not in (0, 1):
raise ValueError(
"'axis' should be either 0 (to index rows) or 1 (to index "
" column). Got {} instead.".format(axis)
)
indices_dtype = _determine_key_type(indices)
if axis == 0 and indices_dtype == "str":
raise ValueError("String indexing is not supported with 'axis=0'")
if axis == 1 and X.ndim != 2:
raise ValueError(
"'X' should be a 2D NumPy array, 2D sparse matrix or pandas "
"dataframe when indexing the columns (i.e. 'axis=1'). "
"Got {} instead with {} dimension(s).".format(type(X), X.ndim)
)
if axis == 1 and indices_dtype == "str" and not hasattr(X, "loc"):
raise ValueError(
"Specifying the columns using strings is only supported for "
"pandas DataFrames"
)
if hasattr(X, "iloc"):
return _pandas_indexing(X, indices, indices_dtype, axis=axis)
elif hasattr(X, "shape"):
return _array_indexing(X, indices, indices_dtype, axis=axis)
else:
return _list_indexing(X, indices, indices_dtype)
\ No newline at end of file
"""Vendoered from
https://github.com/pypa/packaging/blob/main/packaging/_structures.py
"""
# Copyright (c) Donald Stufft and individual contributors.
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
class InfinityType:
def __repr__(self) -> str:
return "Infinity"
def __hash__(self) -> int:
return hash(repr(self))
def __lt__(self, other: object) -> bool:
return False
def __le__(self, other: object) -> bool:
return False
def __eq__(self, other: object) -> bool:
return isinstance(other, self.__class__)
def __ne__(self, other: object) -> bool:
return not isinstance(other, self.__class__)
def __gt__(self, other: object) -> bool:
return True
def __ge__(self, other: object) -> bool:
return True
def __neg__(self: object) -> "NegativeInfinityType":
return NegativeInfinity
Infinity = InfinityType()
class NegativeInfinityType:
def __repr__(self) -> str:
return "-Infinity"
def __hash__(self) -> int:
return hash(repr(self))
def __lt__(self, other: object) -> bool:
return True
def __le__(self, other: object) -> bool:
return True
def __eq__(self, other: object) -> bool:
return isinstance(other, self.__class__)
def __ne__(self, other: object) -> bool:
return not isinstance(other, self.__class__)
def __gt__(self, other: object) -> bool:
return False
def __ge__(self, other: object) -> bool:
return False
def __neg__(self: object) -> InfinityType:
return Infinity
NegativeInfinity = NegativeInfinityType()
import warnings
import functools
__all__ = ["deprecated"]
class deprecated:
"""Decorator to mark a function or class as deprecated.
Issue a warning when the function is called/the class is instantiated and
adds a warning to the docstring.
The optional extra argument will be appended to the deprecation message
and the docstring. Note: to use this with the default value for extra, put
in an empty of parentheses:
>>> from sklearn.utils import deprecated
>>> deprecated()
<sklearn.utils.deprecation.deprecated object at ...>
>>> @deprecated()
... def some_function(): pass
Parameters
----------
extra : str, default=''
To be added to the deprecation messages.
"""
# Adapted from https://wiki.python.org/moin/PythonDecoratorLibrary,
# but with many changes.
def __init__(self, extra=""):
self.extra = extra
def __call__(self, obj):
"""Call method
Parameters
----------
obj : object
"""
if isinstance(obj, type):
return self._decorate_class(obj)
elif isinstance(obj, property):
# Note that this is only triggered properly if the `property`
# decorator comes before the `deprecated` decorator, like so:
#
# @deprecated(msg)
# @property
# def deprecated_attribute_(self):
# ...
return self._decorate_property(obj)
else:
return self._decorate_fun(obj)
def _decorate_class(self, cls):
msg = "Class %s is deprecated" % cls.__name__
if self.extra:
msg += "; %s" % self.extra
# FIXME: we should probably reset __new__ for full generality
init = cls.__init__
def wrapped(*args, **kwargs):
warnings.warn(msg, category=FutureWarning)
return init(*args, **kwargs)
cls.__init__ = wrapped
wrapped.__name__ = "__init__"
wrapped.__doc__ = self._update_doc(init.__doc__)
wrapped.deprecated_original = init
return cls
def _decorate_fun(self, fun):
"""Decorate function fun"""
msg = "Function %s is deprecated" % fun.__name__
if self.extra:
msg += "; %s" % self.extra
@functools.wraps(fun)
def wrapped(*args, **kwargs):
warnings.warn(msg, category=FutureWarning)
return fun(*args, **kwargs)
wrapped.__doc__ = self._update_doc(wrapped.__doc__)
# Add a reference to the wrapped function so that we can introspect
# on function arguments in Python 2 (already works in Python 3)
wrapped.__wrapped__ = fun
return wrapped
def _decorate_property(self, prop):
msg = self.extra
@property
@functools.wraps(prop)
def wrapped(*args, **kwargs):
warnings.warn(msg, category=FutureWarning)
return prop.fget(*args, **kwargs)
wrapped.__doc__ = self._update_doc(wrapped.__doc__)
return wrapped
def _update_doc(self, olddoc):
newdoc = "DEPRECATED"
if self.extra:
newdoc = "%s: %s" % (newdoc, self.extra)
if olddoc:
newdoc = "%s\n\n %s" % (newdoc, olddoc)
return newdoc
def _is_deprecated(func):
"""Helper to check if func is wrapped by our deprecated decorator"""
closures = getattr(func, "__closure__", [])
if closures is None:
closures = []
is_deprecated = "deprecated" in "".join(
[c.cell_contents for c in closures if isinstance(c.cell_contents, str)]
)
return is_deprecated
"""
The :mod:`sklearn.exceptions` module includes all custom warnings and error
classes used across scikit-learn.
"""
from .deprecation import deprecated
__all__ = [
"NotFittedError",
"ChangedBehaviorWarning",
"ConvergenceWarning",
"DataConversionWarning",
"DataDimensionalityWarning",
"EfficiencyWarning",
"FitFailedWarning",
"NonBLASDotWarning",
"SkipTestWarning",
"UndefinedMetricWarning",
"PositiveSpectrumWarning",
]
class NotFittedError(ValueError, AttributeError):
"""Exception class to raise if estimator is used before fitting.
This class inherits from both ValueError and AttributeError to help with
exception handling and backward compatibility.
Examples
--------
>>> from sklearn.svm import LinearSVC
>>> from sklearn.exceptions import NotFittedError
>>> try:
... LinearSVC().predict([[1, 2], [2, 3], [3, 4]])
... except NotFittedError as e:
... print(repr(e))
NotFittedError("This LinearSVC instance is not fitted yet. Call 'fit' with
appropriate arguments before using this estimator."...)
.. versionchanged:: 0.18
Moved from sklearn.utils.validation.
"""
@deprecated("ChangedBehaviorWarning is deprecated in 0.24 and will be removed in 1.1")
class ChangedBehaviorWarning(UserWarning):
"""Warning class used to notify the user of any change in the behavior.
.. versionchanged:: 0.18
Moved from sklearn.base.
"""
class ConvergenceWarning(UserWarning):
"""Custom warning to capture convergence problems
.. versionchanged:: 0.18
Moved from sklearn.utils.
"""
class DataConversionWarning(UserWarning):
"""Warning used to notify implicit data conversions happening in the code.
This warning occurs when some input data needs to be converted or
interpreted in a way that may not match the user's expectations.
For example, this warning may occur when the user
- passes an integer array to a function which expects float input and
will convert the input
- requests a non-copying operation, but a copy is required to meet the
implementation's data-type expectations;
- passes an input whose shape can be interpreted ambiguously.
.. versionchanged:: 0.18
Moved from sklearn.utils.validation.
"""
class DataDimensionalityWarning(UserWarning):
"""Custom warning to notify potential issues with data dimensionality.
For example, in random projection, this warning is raised when the
number of components, which quantifies the dimensionality of the target
projection space, is higher than the number of features, which quantifies
the dimensionality of the original source space, to imply that the
dimensionality of the problem will not be reduced.
.. versionchanged:: 0.18
Moved from sklearn.utils.
"""
class EfficiencyWarning(UserWarning):
"""Warning used to notify the user of inefficient computation.
This warning notifies the user that the efficiency may not be optimal due
to some reason which may be included as a part of the warning message.
This may be subclassed into a more specific Warning class.
.. versionadded:: 0.18
"""
class FitFailedWarning(RuntimeWarning):
"""Warning class used if there is an error while fitting the estimator.
This Warning is used in meta estimators GridSearchCV and RandomizedSearchCV
and the cross-validation helper function cross_val_score to warn when there
is an error while fitting the estimator.
.. versionchanged:: 0.18
Moved from sklearn.cross_validation.
"""
@deprecated("NonBLASDotWarning is deprecated in 0.24 and will be removed in 1.1")
class NonBLASDotWarning(EfficiencyWarning):
"""Warning used when the dot operation does not use BLAS.
This warning is used to notify the user that BLAS was not used for dot
operation and hence the efficiency may be affected.
.. versionchanged:: 0.18
Moved from sklearn.utils.validation, extends EfficiencyWarning.
"""
class SkipTestWarning(UserWarning):
"""Warning class used to notify the user of a test that was skipped.
For example, one of the estimator checks requires a pandas import.
If the pandas package cannot be imported, the test will be skipped rather
than register as a failure.
"""
class UndefinedMetricWarning(UserWarning):
"""Warning used when the metric is invalid
.. versionchanged:: 0.18
Moved from sklearn.base.
"""
class PositiveSpectrumWarning(UserWarning):
"""Warning raised when the eigenvalues of a PSD matrix have issues
This warning is typically raised by ``_check_psd_eigenvalues`` when the
eigenvalues of a positive semidefinite (PSD) matrix such as a gram matrix
(kernel) present significant negative eigenvalues, or bad conditioning i.e.
very small non-zero eigenvalues compared to the largest eigenvalue.
.. versionadded:: 0.22
"""
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
{"result1": {"name": "输出结果1:指标指数", "value": [[1.0, 0.5, 3.0, 4.0, 2.0], [2.0, 1.0, 5.0, 4.0, 3.0], [0.3333333333333333, 0.2, 1.0, 0.5, 0.3333333333333333], [0.25, 0.25, 2.0, 1.0, 1.0], [0.5, 0.3333333333333333, 3.0, 1.0, 1.0]]}, "result2": {"name": "输出结果2:AHP层次分析结果", "value": {"特征向量": [1.3959644109800522, 2.14618131260467, 0.34067086777201483, 0.5557282567970785, 0.7236478444507641], "权重值": [0.26636828586776445, 0.41498765398661125, 0.06674521168786028, 0.10903448306993666, 0.14286436538782732], "最大特征根": 5.135709191858394, "CI值": 0.03392729796459859}}, "result3": {"name": "输出结果3:一致性检验结果", "value": {"最大特征根": 5.135709191858394, "CI值": 0.03392729796459859, "RI值": 1.12, "CR值": 0.030292230325534453, "一致性检验结果": true}}}
\ No newline at end of file
景色,费用,居住,饮食,旅途
1.00000000 ,0.50000000 ,3.00000000 ,4.00000000 ,2.00000000
2.00000000 ,1.00000000 ,5.00000000 ,4.00000000 ,3.00000000
0.33333333 ,0.20000000 ,1.00000000 ,0.50000000 ,0.33333333
0.25000000 ,0.25000000 ,2.00000000 ,1.00000000 ,1.00000000
0.50000000 ,0.33333333 ,3.00000000 ,1.00000000 ,1.00000000
{"result1": {"name": "输出结果1:效益分析表", "value": {"技术效益": {"城市1": 0.9071068469, "城市2": 1.0, "城市3": 0.9383730712, "城市4": 0.8901497523, "城市5": 1.0, "城市6": 0.9843260132, "城市7": 0.8930188683, "城市8": 1.0, "城市9": 1.0, "城市10": 1.0}, "规模效益": {"城市1": 0.9886289313, "城市2": 1.0, "城市3": 0.9964800112, "城市4": 0.94113333, "城市5": 0.878494253, "城市6": 0.8456149781, "城市7": 0.8917038282, "城市8": 1.0, "城市9": 1.0, "城市10": 1.0}, "综合效益": {"城市1": 0.8967920726, "城市2": 1.0, "城市3": 0.9350700085, "城市4": 0.8377496006, "城市5": 0.878494253, "城市6": 0.8323608201, "城市7": 0.7963083435, "城市8": 1.0, "城市9": 1.0, "城市10": 1.0}, "松弛变量S-": {"城市1": 1.4747631044, "城市2": 0.0, "城市3": 0.0022596677, "城市4": 0.0100634463, "城市5": 0.0406662616, "城市6": 25.5560124056, "城市7": 0.0451206249, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "松弛变量S+": {"城市1": 0.0, "城市2": 0.0, "城市3": 23431.7584516791, "城市4": 0.0, "城市5": 6793.5343285065, "城市6": 0.0, "城市7": 0.0, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "有效性": {"城市1": "非DEA有效", "城市2": "DEA强有效", "城市3": "非DEA有效", "城市4": "非DEA有效", "城市5": "非DEA有效", "城市6": "非DEA有效", "城市7": "非DEA有效", "城市8": "DEA强有效", "城市9": "DEA强有效", "城市10": "DEA强有效"}}}, "result2": {"name": "输出结果2:效益有效性分析", "value": {"技术效益": [0.907106846851185, 1.0, 0.9383730712044418, 0.8901497522620344, 1.0, 0.984326013196599, 0.8930188683481013, 1.0, 1.0, 1.0], "规模效益": [0.9886289313004191, 1.0, 0.9964800111620568, 0.9411333300170103, 0.878494253004664, 0.8456149781331181, 0.891703828173358, 1.0, 1.0, 1.0], "综合效益": [0.8967920725777799, 1.0, 0.9350700084679756, 0.8377496005601852, 0.878494253004664, 0.8323608201251014, 0.7963083435370419, 1.0, 1.0, 1.0], "index": ["城市1", "城市2", "城市3", "城市4", "城市5", "城市6", "城市7", "城市8", "城市9", "城市10"]}}, "result3": {"name": "输出结果3:规模报酬分析", "value": {"规模报酬系数": {"城市1": 0.9768530563, "城市2": 1.0, "城市3": 1.0124269349, "城市4": 0.9202066336, "城市5": 0.7882840289, "城市6": 0.7741966414, "城市7": 0.8275171242, "城市8": 1.0, "城市9": 1.0, "城市10": 1.0}, "类型": {"城市1": "规模报酬递增", "城市2": "规模报酬固定", "城市3": "规模报酬递减", "城市4": "规模报酬递增", "城市5": "规模报酬递增", "城市6": "规模报酬递增", "城市7": "规模报酬递增", "城市8": "规模报酬固定", "城市9": "规模报酬固定", "城市10": "规模报酬固定"}}}, "result4": {"name": "输出结果4: 象限分析", "value": {"投入": [-10.171192370620714, -6.98788589343945, -18.526402702963487, -0.3029409510519386, 36.41468427675583, -23.034887890682814, 12.725694808462372, 8.803865012454684, 22.933028478382283, -21.853962767296863], "产出": [27358.216844024082, -42232.47712241886, -15247.235046034262, 27554.118777116648, -24731.28572506368, -43758.369217579595, 244.00063710547823, 55906.4389832688, 10920.107963476052, 3986.4839061054377]}}, "result5": {"name": "输出结果5:象限分析输出汇总", "value": {"投入": {"城市1": -10.1711923706, "城市2": -6.9878858934, "城市3": -18.526402703, "城市4": -0.3029409511, "城市5": 36.4146842768, "城市6": -23.0348878907, "城市7": 12.7256948085, "城市8": 8.8038650125, "城市9": 22.9330284784, "城市10": -21.8539627673}, "产出": {"城市1": 27358.2168440241, "城市2": -42232.4771224189, "城市3": -15247.2350460343, "城市4": 27554.1187771166, "城市5": -24731.2857250637, "城市6": -43758.3692175796, "城市7": 244.0006371055, "城市8": 55906.4389832688, "城市9": 10920.1079634761, "城市10": 3986.4839061054}, "象限分布": {"城市1": "第四象限", "城市2": "第三象限", "城市3": "第三象限", "城市4": "第四象限", "城市5": "第二象限", "城市6": "第三象限", "城市7": "第一象限", "城市8": "第一象限", "城市9": "第一象限", "城市10": "第四象限"}}}, "result6": {"name": "输出结果6:投入冗余分析", "value": {"松驰变量S-政府财政收入占GDP的比例": {"城市1": 0.018810797, "城市2": 0.0, "城市3": 0.0, "城市4": 0.0073642435, "城市5": 0.0372255468, "城市6": 0.0467101755, "城市7": 0.0377141299, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "松驰变量S-环保投资占GDP的比例": {"城市1": 0.0, "城市2": 0.0, "城市3": 0.0022596677, "城市4": 0.0026992027, "城市5": 0.0034407147, "城市6": 0.0, "城市7": 0.007406495, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "松驰变量S-每千人科技人员数\\/人": {"城市1": 1.4559523074, "城市2": 0.0, "城市3": 0.0, "城市4": 0.0, "城市5": 0.0, "城市6": 25.5093022301, "城市7": 0.0, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "松驰变量S-汇总": {"城市1": 1.0, "城市2": 0.0, "城市3": 0.0, "城市4": 0.0, "城市5": 0.0, "城市6": 26.0, "城市7": 0.0, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "投入冗余率_政府财政收入占GDP的比例": {"城市1": 0.0850148654, "城市2": 0.0, "城市3": 0.0, "城市4": 0.0325337327, "城市5": 0.1522684794, "城市6": 0.2064884962, "城市7": 0.1413704363, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "投入冗余率_环保投资占GDP的比例": {"城市1": 0.0, "城市2": 0.0, "城市3": 0.0378280772, "城市4": 0.0498686663, "城市5": 0.0688756118, "城市6": 0.0, "城市7": 0.1235591432, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "投入冗余率_每千人科技人员数\\/人": {"城市1": 0.0088565604, "城市2": 0.0, "城市3": 0.0, "城市4": 0.0, "城市5": 0.0, "城市6": 0.1439120186, "城市7": 0.0, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}}}, "result7": {"name": "输出结果7:产出不足分析", "value": {"松驰变量S+人均GDP": {"城市1": 0.0, "城市2": 0.0, "城市3": 23431.7584516791, "城市4": 0.0, "城市5": 6793.5343285065, "城市6": 0.0, "城市7": 0.0, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "松驰变量S+城市环境质量指数": {"城市1": 0.0, "城市2": 0.0, "城市3": 0.0, "城市4": 0.0, "城市5": 0.0, "城市6": 0.0, "城市7": 0.0, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "松驰变量S+汇总": {"城市1": 0.0, "城市2": 0.0, "城市3": 23432.0, "城市4": 0.0, "城市5": 6794.0, "城市6": 0.0, "城市7": 0.0, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "产出不足率_人均GDP": {"城市1": 0.0, "城市2": 0.0, "城市3": 0.2127505294, "城市4": 0.0, "城市5": 0.0674944693, "城市6": 0.0, "城市7": 0.0, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "产出不足率_城市环境质量指数": {"城市1": 0.0, "城市2": 0.0, "城市3": 0.0, "城市4": 0.0, "城市5": 0.0, "城市6": 0.0, "城市7": 0.0, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}}}}
\ No newline at end of file
{"result1": {"name": "输出结果1:效益分析表", "value": {"综合效益": {"城市1": 0.8967920726, "城市2": 1.0, "城市3": 0.9350700085, "城市4": 0.8377496006, "城市5": 0.878494253, "城市6": 0.8323608201, "城市7": 0.7963083435, "城市8": 1.0, "城市9": 1.0, "城市10": 1.0}, "松弛变量S-": {"城市1": 1.4747631044, "城市2": 0.0, "城市3": 0.0022596677, "城市4": 0.0100634463, "城市5": 0.0406662616, "城市6": 25.5560124056, "城市7": 0.0451206249, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "松弛变量S+": {"城市1": 0.0, "城市2": 0.0, "城市3": 23431.7584516791, "城市4": 0.0, "城市5": 6793.5343285065, "城市6": 0.0, "城市7": 0.0, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "有效性": {"城市1": "非DEA有效", "城市2": "DEA强有效", "城市3": "非DEA有效", "城市4": "非DEA有效", "城市5": "非DEA有效", "城市6": "非DEA有效", "城市7": "非DEA有效", "城市8": "DEA强有效", "城市9": "DEA强有效", "城市10": "DEA强有效"}}}, "result2": {"name": "输出结果2:效益有效性分析", "value": {"综合效益": [0.8967920725777799, 1.0, 0.9350700084679756, 0.8377496005601852, 0.878494253004664, 0.8323608201251014, 0.7963083435370419, 1.0, 1.0, 1.0], "index": ["城市1", "城市2", "城市3", "城市4", "城市5", "城市6", "城市7", "城市8", "城市9", "城市10"]}}, "result3": {"name": "输出结果3: 象限分析", "value": {"投入": [-10.171192370620714, -6.98788589343945, -18.526402702963487, -0.3029409510519386, 36.41468427675583, -23.034887890682814, 12.725694808462372, 8.803865012454684, 22.933028478382283, -21.853962767296863], "产出": [27358.216844024082, -42232.47712241886, -15247.235046034262, 27554.118777116648, -24731.28572506368, -43758.369217579595, 244.00063710547823, 55906.4389832688, 10920.107963476052, 3986.4839061054377]}}, "result4": {"name": "输出结果4:象限分析输出汇总", "value": {"投入": {"城市1": -10.1711923706, "城市2": -6.9878858934, "城市3": -18.526402703, "城市4": -0.3029409511, "城市5": 36.4146842768, "城市6": -23.0348878907, "城市7": 12.7256948085, "城市8": 8.8038650125, "城市9": 22.9330284784, "城市10": -21.8539627673}, "产出": {"城市1": 27358.2168440241, "城市2": -42232.4771224189, "城市3": -15247.2350460343, "城市4": 27554.1187771166, "城市5": -24731.2857250637, "城市6": -43758.3692175796, "城市7": 244.0006371055, "城市8": 55906.4389832688, "城市9": 10920.1079634761, "城市10": 3986.4839061054}, "象限分布": {"城市1": "第四象限", "城市2": "第三象限", "城市3": "第三象限", "城市4": "第四象限", "城市5": "第二象限", "城市6": "第三象限", "城市7": "第一象限", "城市8": "第一象限", "城市9": "第一象限", "城市10": "第四象限"}}}, "result5": {"name": "输出结果5:投入冗余分析", "value": {"松驰变量S-政府财政收入占GDP的比例": {"城市1": 0.018810797, "城市2": 0.0, "城市3": 0.0, "城市4": 0.0073642435, "城市5": 0.0372255468, "城市6": 0.0467101755, "城市7": 0.0377141299, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "松驰变量S-环保投资占GDP的比例": {"城市1": 0.0, "城市2": 0.0, "城市3": 0.0022596677, "城市4": 0.0026992027, "城市5": 0.0034407147, "城市6": 0.0, "城市7": 0.007406495, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "松驰变量S-每千人科技人员数\\/人": {"城市1": 1.4559523074, "城市2": 0.0, "城市3": 0.0, "城市4": 0.0, "城市5": 0.0, "城市6": 25.5093022301, "城市7": 0.0, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "松驰变量S-汇总": {"城市1": 1.0, "城市2": 0.0, "城市3": 0.0, "城市4": 0.0, "城市5": 0.0, "城市6": 26.0, "城市7": 0.0, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "投入冗余率_政府财政收入占GDP的比例": {"城市1": 0.0850148654, "城市2": 0.0, "城市3": 0.0, "城市4": 0.0325337327, "城市5": 0.1522684794, "城市6": 0.2064884962, "城市7": 0.1413704363, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "投入冗余率_环保投资占GDP的比例": {"城市1": 0.0, "城市2": 0.0, "城市3": 0.0378280772, "城市4": 0.0498686663, "城市5": 0.0688756118, "城市6": 0.0, "城市7": 0.1235591432, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "投入冗余率_每千人科技人员数\\/人": {"城市1": 0.0088565604, "城市2": 0.0, "城市3": 0.0, "城市4": 0.0, "城市5": 0.0, "城市6": 0.1439120186, "城市7": 0.0, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}}}, "result6": {"name": "输出结果6:产出不足分析", "value": {"松驰变量S+人均GDP": {"城市1": 0.0, "城市2": 0.0, "城市3": 23431.7584516791, "城市4": 0.0, "城市5": 6793.5343285065, "城市6": 0.0, "城市7": 0.0, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "松驰变量S+城市环境质量指数": {"城市1": 0.0, "城市2": 0.0, "城市3": 0.0, "城市4": 0.0, "城市5": 0.0, "城市6": 0.0, "城市7": 0.0, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "松驰变量S+汇总": {"城市1": 0.0, "城市2": 0.0, "城市3": 23432.0, "城市4": 0.0, "城市5": 6794.0, "城市6": 0.0, "城市7": 0.0, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "产出不足率_人均GDP": {"城市1": 0.0, "城市2": 0.0, "城市3": 0.2127505294, "城市4": 0.0, "城市5": 0.0674944693, "城市6": 0.0, "城市7": 0.0, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}, "产出不足率_城市环境质量指数": {"城市1": 0.0, "城市2": 0.0, "城市3": 0.0, "城市4": 0.0, "城市5": 0.0, "城市6": 0.0, "城市7": 0.0, "城市8": 0.0, "城市9": 0.0, "城市10": 0.0}}}}
\ No newline at end of file
城市名,政府财政收入占GDP的比例,环保投资占GDP的比例,每千人科技人员数/人,人均GDP,城市环境质量指数
城市1,0.2212647974528904,0.0491979419997336,164.3925221476873,152742.7027737305,30.54008270903903
城市2,0.1824354439273296,0.0490685079728454,161.2091674755783,83152.00889149064,36.51343988793383
城市3,0.1762546455483456,0.0597351980096123,172.7476849776795,110137.2509636013,36.02854494054782
城市4,0.2263571663733694,0.0541262267411049,154.5242698068128,152938.6046752807,28.50291828609647
城市5,0.2444730977907392,0.0499554870381134,117.8066403261514,100653.2001397634,26.75653706383506
城市6,0.2262119987718575,0.0445348834379542,177.2562325706743,81626.11664922578,27.03162227856709
城市7,0.2667752244944158,0.0599429134160142,141.4956727230155,125628.4865058203,26.81394339708482
城市8,0.1843636273971721,0.0438368442626567,145.4174078242079,181290.9248999168,29.47615527630422
城市9,0.2252267686229245,0.0513075136075718,131.2882827780171,136304.5939439337,33.94276185200264
城市10,0.1262726716713249,0.0538931875159639,176.0751882474749,129370.9699260908,36.54747500199031
{"result1": {"name": "输出结果1:指标权重计算", "value": {"信息熵值e": {"产前检查率": 0.941715268, "孕妇死亡率": 0.9280708455, "围产儿死亡率": 0.9322884812}, "信息效用值d": {"产前检查率": 0.058284732, "孕妇死亡率": 0.0719291545, "围产儿死亡率": 0.0677115188}, "权重": {"产前检查率": 0.2944782756, "孕妇死亡率": 0.3634154715, "围产儿死亡率": 0.3421062529}}}, "result2": {"name": "输出结果2:秩值计算", "value": {"X1:产前检查率": {"A": 1.0, "B": 0.7951153324, "C": 0.9877883311, "D": 0.5447761194, "E": 0.4687924016, "F": 0.7157394844, "G": 0.7659430122, "H": 0.9816824966, "I": 0.6757123474, "J": 0.0}, "R1:产前检查率": {"A": 10.0, "B": 8.1560379919, "C": 9.8900949796, "D": 5.9029850746, "E": 5.2191316147, "F": 7.4416553596, "G": 7.8934871099, "H": 9.8351424695, "I": 7.0814111262, "J": 1.0}, "X2:孕妇死亡率": {"A": 0.3622396722, "B": 0.3724820758, "C": 0.6415158757, "D": 0.3840901332, "E": 0.7867872994, "F": 0.6278593377, "G": 0.5407989075, "H": 0.8501194947, "I": 1.0, "J": 0.0}, "R2:孕妇死亡率": {"A": 4.2601570502, "B": 4.3523386821, "C": 6.7736428815, "D": 4.4568111984, "E": 8.0810856948, "F": 6.6507340389, "G": 5.8671901673, "H": 8.6510754524, "I": 10.0, "J": 1.0}, "X3:围产儿死亡率": {"A": 0.7679671458, "B": 0.3624229979, "C": 0.8244353183, "D": 0.6765913758, "E": 0.8850102669, "F": 0.9958932238, "G": 0.636550308, "H": 1.0, "I": 0.386036961, "J": 0.0}, "R3:围产儿死亡率": {"A": 7.9117043121, "B": 4.2618069815, "C": 8.4199178645, "D": 7.0893223819, "E": 8.9650924025, "F": 9.9630390144, "G": 6.7289527721, "H": 10.0, "I": 4.4743326489, "J": 1.0}, "RSR": {"A": 0.7199633255, "B": 0.5441474035, "C": 0.8254571287, "D": 0.5783276524, "E": 0.7540726615, "F": 0.8016803429, "G": 0.6758704972, "H": 0.9461232988, "I": 0.7250173629, "J": 0.1}, "RSR_Rank": {"A": 6.0, "B": 9.0, "C": 2.0, "D": 8.0, "E": 4.0, "F": 3.0, "G": 7.0, "H": 1.0, "I": 5.0, "J": 10.0}}}, "result3": {"name": "输出结果3:RSR分布表", "value": {"频数": {"0.1": 1, "0.5441474034747824": 1, "0.5783276524428377": 1, "0.6758704972369379": 1, "0.7199633255235339": 1, "0.7250173628902006": 1, "0.7540726614865456": 1, "0.8016803429262873": 1, "0.8254571286969441": 1, "0.9461232988198599": 1}, "累计频数Σf": {"0.1": 1, "0.5441474034747824": 2, "0.5783276524428377": 3, "0.6758704972369379": 4, "0.7199633255235339": 5, "0.7250173628902006": 6, "0.7540726614865456": 7, "0.8016803429262873": 8, "0.8254571286969441": 9, "0.9461232988198599": 10}, "评价秩数": {"0.1": 1.0, "0.5441474034747824": 2.0, "0.5783276524428377": 3.0, "0.6758704972369379": 4.0, "0.7199633255235339": 5.0, "0.7250173628902006": 6.0, "0.7540726614865456": 7.0, "0.8016803429262873": 8.0, "0.8254571286969441": 9.0, "0.9461232988198599": 10.0}, "评价秩数\\/n*100%": {"0.1": 10.0, "0.5441474034747824": 20.0, "0.5783276524428377": 30.0, "0.6758704972369379": 40.0, "0.7199633255235339": 50.0, "0.7250173628902006": 60.0, "0.7540726614865456": 70.0, "0.8016803429262873": 80.0, "0.8254571286969441": 90.0, "0.9461232988198599": 97.5}, "Probit": {"0.1": 3.7184484345, "0.5441474034747824": 4.1583787664, "0.5783276524428377": 4.4755994873, "0.6758704972369379": 4.7466528969, "0.7199633255235339": 5.0, "0.7250173628902006": 5.2533471031, "0.7540726614865456": 5.5244005127, "0.8016803429262873": 5.8416212336, "0.8254571286969441": 6.2815515655, "0.9461232988198599": 6.9599639845}}}, "result4": {"name": "输出结果4:线性回归", "value": {"回归系数": {"const": -0.3901225141, "Probit": 0.2034621275}, "回归系数标准差": {"const": 0.2116725148, "Probit": 0.0400868413}, "回归系数t值": {"const": -1.8430475705, "Probit": 5.0755340315}, "回归系数p值": {"const": 0.1025648751, "Probit": 0.0009584153}, "置信区间": {"0": {"const": -0.8782402085, "Probit": 0.1110217056}, "1": {"const": 0.0979951803, "Probit": 0.2959025494}}, "R方": 0.7630405151007185, "调整R方": 0.7334205794883083, "F-statistic": 25.76104570534647, "Prob(F-statistic)": 0.0009584153473809211, "回归直线方程": "y = -0.390122514137597 + 0.20346212745681286*Probit"}}, "result5": {"name": "输出结果5:拟合效果", "value": [[0.1, 0.5441474034747824, 0.5783276524428377, 0.6758704972369379, 0.7199633255235339, 0.7250173628902006, 0.7540726614865456, 0.8016803429262873, 0.8254571286969441, 0.9461232988198599], [0.36644091517515376, 0.455950076450895, 0.5204924791914457, 0.5756415825574368, 0.6271881231464673, 0.6787346637354978, 0.7338837671014886, 0.7984261698420396, 0.8879353311177807, 1.0259665651797185]]}, "result6": {"name": "输出结果6:分档排序临界值表格", "value": {"Probit": [4, 6], "RSR临界值": [0.4237259956896544, 0.83065025060328]}}, "result7": {"name": "输出结果7:分档等级结果汇总", "value": {"RSR_Rank": {"C": 2.0, "H": 1.0, "A": 6.0, "B": 9.0, "D": 8.0, "E": 4.0, "F": 3.0, "G": 7.0, "I": 5.0, "J": 10.0}, "Probit": {"C": 6.2815515655, "H": 6.9599639845, "A": 5.0, "B": 4.1583787664, "D": 4.4755994873, "E": 5.5244005127, "F": 5.8416212336, "G": 4.7466528969, "I": 5.2533471031, "J": 3.7184484345}, "RSR Regression": {"C": 0.8879353311, "H": 1.0259665652, "A": 0.6271881231, "B": 0.4559500765, "D": 0.5204924792, "E": 0.7338837671, "F": 0.7984261698, "G": 0.5756415826, "I": 0.6787346637, "J": 0.3664409152}, "Level": {"C": 3, "H": 3, "A": 2, "B": 2, "D": 2, "E": 2, "F": 2, "G": 2, "I": 2, "J": 1}}}}
\ No newline at end of file
省份,产前检查率,孕妇死亡率,围产儿死亡率
A,99.54,60.27,16.15
B,96.52,59.67,20.1
C,99.36,43.91,15.6
D,92.83,58.99,17.04
E,91.71,35.4,15.01
F,95.35,44.71,13.93
G,96.09,49.81,17.43
H,99.27,31.69,13.89
I,94.76,22.91,19.87
J,84.8,81.49,23.63
{"result1": {"name": "输出结果1:指标权重计算", "value": {"信息熵值e": {"风景": 0.7952181417, "人文": 0.8198796941, "拥挤程度": 0.7956405386, "票价": 0.7952181417}, "信息效用值d": {"风景": 0.2047818583, "人文": 0.1801203059, "拥挤程度": 0.2043594614, "票价": 0.2047818583}, "权重": {"风景": 0.2578975364, "人文": 0.2268393477, "拥挤程度": 0.2573655795, "票价": 0.2578975364}}}, "result2": {"name": "输出结果2:TOPSIS评价法计算结果", "value": {"正理想解距离(D+)": {"A": 0.5886481603, "B": 0.6895608079, "C": 0.5529759728, "D": 0.5813420332, "E": 0.6388260691}, "负理想解距离(D-)": {"A": 0.7397042647, "B": 0.4667574851, "C": 0.4832633808, "D": 0.6605914744, "E": 0.612004544}, "综合得分指数": {"A": 0.5568584442, "B": 0.4036583075, "C": 0.4663626981, "D": 0.5319056699, "E": 0.4892785143}, "排序": {"A": 1.0, "B": 5.0, "C": 4.0, "D": 2.0, "E": 3.0}}}, "result3": {"name": "输出结果3:中间值展示", "value": {"正理想解": {"风景": 1.0, "人文": 1.0, "拥挤程度": 1.0, "票价": 1.0}, "负理想解": {"风景": 0.0, "人文": 0.0, "拥挤程度": 0.0, "票价": 0.0}}}}
\ No newline at end of file
风景地点,风景,人文,拥挤程度,票价
A,4,5,2,30
B,7,6,8,50
C,5,7,6,40
D,6,10,10,35
E,8,2,5,45
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment