python - 如何在 Python 中创建高斯混合模型?
问题描述
出于可重复性的原因,我在这里分享几个数据集。数据集具有以下格式。
0.080505471,10
0.080709071,20
0.080835753,30
0.081004589,40
0.081009152,30
0.181258811,41
0.181674244,40
从第 2 列开始,我正在读取当前行并将其与前一行的值进行比较。如果它更大,我会继续比较。如果当前值小于前一行的值,我想将当前值(较小)除以前一个值(较大)。因此,以下代码:
import numpy as np
import scipy.stats
import matplotlib.pyplot as plt
import seaborn as sns
protocols = {}
types = {"data_g": "data_g.csv", "data_v": "data_v.csv", "data_c": "data_c.csv", "data_c": "data_c.csv"}
for protname, fname in types.items():
col_time,col_window = np.loadtxt(fname,delimiter=',').T
trailing_window = col_window[:-1] # "past" values at a given index
leading_window = col_window[1:] # "current values at a given index
decreasing_inds = np.where(leading_window < trailing_window)[0]
quotient = leading_window[decreasing_inds]/trailing_window[decreasing_inds]
quotient_times = col_time[decreasing_inds]
protocols[protname] = {
"col_time": col_time,
"col_window": col_window,
"quotient_times": quotient_times,
"quotient": quotient,
}
plt.figure(); plt.clf()
plt.plot(quotient_times, quotient, ".", label=protname, color="blue")
plt.ylim(0, 1.0001)
plt.title(protname)
plt.xlabel("quotient_times")
plt.ylabel("quotient")
plt.legend()
plt.show()
这给出了以下图。
从图中我们可以看出
- Data-G,不管数值
quotient_times
是多少,商总是>=0.9 quotient_times
当小于 3时, Data-V的商为 0.8,如果大于 3,则商保持为 0.5quotient_times
。quotient
无论值是多少, Data-C的常数都是 0.7quotient_times
。quotient
无论值是多少,Data-R的常数都是 0.5quotient_times
基于此要求,我们如何绘制高斯混合模型?任何帮助,将不胜感激。
解决方案
推荐阅读
- android - 无法将 altbeacon 库包含到新项目中
- python - 有条件地将某些行值复制到其他行
- java - 在 Java 中使用 BouncyCastle 生成数字签名
- matlab - 在 MATLAB 中根据另一个变量找到一个变量
- css - 使用 Chrome 打印背景不适合分页符之前的 div 框时,如何不显示两次框?
- javascript - 我查找最长单词的代码不起作用
- scala - 如何在scala程序中执行shell脚本(.sh文件)
- python-3.x - Python程序在if语句后不返回函数
- raspberry-pi - Google Assistant - Raspberry pi 仅作为 IoT 设备(没有语音控制,只有操作)
- javascript - 数据表列排序不起作用服务器端Spring MVC