21 篇文章 6 订阅
13 篇文章 0 订阅
2 篇文章 0 订阅

# 灰色关联分析的步骤

（1）参考数列（又称母序列）为 Y = Y ( k ) ∣ k = 1 , 2... n Y={Y(k) | k = 1,2...n}

（2）比较数列（又称子序列）为 X i = X i ( k ) ∣ k = 1 , 2... n , i = 1 , 2... m X_i={X_i(k) | k = 1,2...n},i = 1,2...m

（1）初值化处理： x i ( k ) = x i ( k ) x i ( 1 ) , k = 1 , 2... n ; i = 0 , 1 , 2... m x_i(k)=\frac{x_i(k)}{x_i(1)},k=1,2...n;i=0,1,2...m

（2）均值化处理： x i ( k ) = x i ( k ) x i ˉ , k = 1 , 2... n ; i = 0 , 1 , 2... m x_i(k)=\frac{x_i(k)}{\bar{x_i}},k=1,2...n;i=0,1,2...m

△ i ( k ) = ∣ y ( k ) − x i ( k ) ∣ \triangle_i(k)=|y(k)-x_i(k)| ，则

ρ ∈ ( 0 , ∞ ) \rho\in(0,\infty) ，称为分辨系数。ρ越小，分辨力越大，一般ρ的取值区间为 ( 0 , 1 ) (0,1) ,具体取值可视情况而定。当 ρ ≤ 0.5463 \rho\le0.5463 时，分辨力最好，通常取 ρ = 0.5 ρ = 0.5

r i = 1 n ∑ k = 1 n ξ i ( k ) , k = 1 , 2 , Λ , n r_i=\frac{1}{n}\sum_{k=1}^n\xi_i(k),k=1,2,\Lambda,n

# 灰色关联分析的实例

20001988386839763
20012061408846808
20022335422960953
2003275048212581010
2004335651115771268
2005380656118931352

20000.73200.83610.68280.7439
20010.75880.88380.68850.7878
20020.85970.91410.78120.9292
20031.01251.04401.02370.9847
20041.23561.10691.28331.2363
20051.40131.21521.54051.3182

20000.47550.65910.8933
20010.42990.57390.7681
20020.63580.54650.5767
20030.75270.89930.7758
20040.42280.66611.0000
20050.33580.40370.5322

# 灰色关联分析matlab的实现

clc;
close;
clear all;
x=x(:,2:end)';
column_num=size(x,2);
index_num=size(x,1);

% 1、数据均值化处理
x_mean=mean(x,2);
for i = 1:index_num
x(i,:) = x(i,:)/x_mean(i,1);
end
% 2、提取参考队列和比较队列
ck=x(1,:)
cp=x(2:end,:)
cp_index_num=size(cp,1);

%比较队列与参考队列相减
for j = 1:cp_index_num
t(j,:)=cp(j,:)-ck;
end
%求最大差和最小差
mmax=max(max(abs(t)))
mmin=min(min(abs(t)))
rho=0.5;
%3、求关联系数
ksi=((mmin+rho*mmax)./(abs(t)+rho*mmax))

%4、求关联度
ksi_column_num=size(ksi,2);
r=sum(ksi,2)/ksi_column_num;

%5、关联度排序，得到结果r3>r2>r1
[rs,rind]=sort(r,'descend');


# 灰色关联分析python的实现

import pandas as pd
x=x.iloc[:,1:].T

# 1、数据均值化处理
x_mean=x.mean(axis=1)
for i in range(x.index.size):
x.iloc[i,:] = x.iloc[i,:]/x_mean[i]

# 2、提取参考队列和比较队列
ck=x.iloc[0,:]
cp=x.iloc[1:,:]

# 比较队列与参考队列相减
t=pd.DataFrame()
for j in range(cp.index.size):
temp=pd.Series(cp.iloc[j,:]-ck)
t=t.append(temp,ignore_index=True)

#求最大差和最小差
mmax=t.abs().max().max()
mmin=t.abs().min().min()
rho=0.5
#3、求关联系数
ksi=((mmin+rho*mmax)/(abs(t)+rho*mmax))

#4、求关联度
r=ksi.sum(axis=1)/ksi.columns.size

#5、关联度排序，得到结果r3>r2>r1
result=r.sort_values(ascending=False)


08-21
08-21

01-22 3万+
06-07 3万+
04-18
03-12
01-27 1万+
10-07 3853
05-01