File size: 767 Bytes
bd39f54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import numpy as np
import matplotlib.pyplot as plt
from sklearn.mixture import GaussianMixture


def gaussian_mix(x):
    x = x.reshape(-1, 1)
    n_components = 2000  # 你可以根据需要调整混合组件的数量
    gmm = GaussianMixture(n_components=n_components, covariance_type='full')

    # 拟合模型
    gmm.fit(x)

    # 预测每个数据点所属的组件
    continuous_data = gmm.sample(len(x))[0].reshape(-1)

    return continuous_data

    # 使用高斯混合模型拟合数据
    # gmm = GaussianMixture(n_components=50)  # 选择混合成分的数量
    # gmm.fit(x.reshape(-1, 1))

    # 生成连续数据
    # return np.linspace(min(x), max(x), len(x)).flatten()

    # z = np.exp(gmm.score_samples(y.reshape(-1, 1)))

    # return z