资源简介
东华大学信息学院机器学习大作业全集-最后一个大作业,源代码,实验结果图,论文格式都很详细,别想了就是你想要的那个。

代码片段和文件信息
import numpy as np
import matplotlib.pyplot as plt
import math
“““
生成的三个高斯模型的数据点,每个高斯各500个点
“““
def get_data():
mean1 = [10]
cov1 = [[50][01]]
mean2 = [80]
cov2 = [[10][05]]
mean3 = [44]
cov3 = [[40][04]]
#生成数据点
data1 = np.random.multivariate_normal(mean1cov1500)
data2 = np.random.multivariate_normal(mean2cov2500)
data3 = np.random.multivariate_normal(mean3cov3500)
x1y1 = data1.T
x2y2 = data2.T
x3y3 = data3.T
plt.scatter(x1y1s=3c=‘g‘)
plt.scatter(x2y2s=3c=‘b‘)
plt.scatter(x3y3s=3c=‘r‘)
#合并成一个数据集
x = np.hstack((x1x2x3))
y = np.hstack((y1y2y3))
return xy
“““
计算矩阵的行列式的值和逆矩阵
“““
def get_det_inv(c):
det_c=np.linalg.det(c)
inv_c=np.linalg.inv(c)
return det_cinv_c
“““
do-M step 更新参数wcu
“““
def do_mstep(Plenxyu):
c=sum(P)
w=sum(P)/len
tem1=np.array([[0][0]])
tem2=np.array([[00][00]])
for i in range(len):
a = np.array([[x[i] y[i]]])
a = a.T
tem1=tem1+P[i]*a
tem2=tem2+P[i]*np.dot((a-u)(a-u).T)
u=tem1/c
c=tem2/c
return wuc
#获取生成点的二维坐标
xy=get_data()
len=len(x)
#plt.scatter(xys=1.5)
#高斯模型参数初始化
x_u1=[]
y_u1=[]
x_u2=[]
y_u2=[]
x_u3=[]
y_u3=[]
w1=0.4
u1=np.array([[1.1][0.1]])
c1=np.array([[30][03]])
w2=0.3
u2=np.array([[8.2][0.1]])
c2=np.array([[30][03]])
w3=0.3
u3=np.array([[4.2][4.2]])
c3=np.array([[30][03]])
#记录第一次的聚类中心
x_u1.append(u1[00])
y_u1.append(u1[10])
x_u2.append(u2[00])
y_u2.append(u2[10])
x_u3.append(u3[00])
y_u3.append(u3[10])
#设置迭代次数
flag=100
while(1):
#计算行列式的值和逆矩阵
det_c1inv_c1=get_det_inv(c1)
det_c2inv_c2=get_det_inv(c2)
det_c3inv_c3=get_det_inv(c3)
P1 = []
P2 = []
P3 = []
for i in range(len):
a=np.array([[x[i]y[i]]])
a=a.T
#do E-step
N1 = (1 / (2 * math.pi * math.sqrt(det_c1))) * np.exp(-0.5 * np.dot(np.dot((a - u1).T inv_c1) (a - u1)))
N1=N1[00]
N2 = (1 / (2 * math.pi * math.sqrt(det_c2))) * np.exp(-0.5 * np.dot(np.dot((a - u2).T inv_c2) (a - u2)))
N2 = N2[0 0]
N3 = (1 / (2 * math.pi * math.sqrt(det_c3))) * np.exp(-0.5 * np.dot(np.dot((a - u3).T inv_c3) (a - u3)))
N3 = N3[0 0]
tem=w1*N1+w2*N2+w3*N3
#计算先验概率
p1=w1*N1/tem
p2=w2*N2/tem
p3=w3*N3/tem
P1.append(p1)
P2.append(p2)
P3.append(p3)
# do M-step
w1_1=w1
w2u2c2=do_mstep(P2 len x y u2)
plt.plot(u2[0 0] u2[1 0])
w1u1c1=do_mstep(P1 len x y u1)
# plt.plot(u1[0 0] u1[1 0])
w3u3c3=do_mstep(P3 len x y u3)
plt.plot(u3[0 0] u3[1 0])
x_u1.append(u1[0 0])
y_u1.append(u1[1 0])
x_u2.append(u2[0 0])
y_u2.append(u2[1 0])
x_u3.append(u3[0 0])
y_u3.append(u3[1 0])
if abs(w1-w1_1) < 0.0001:
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-12-22 18:59 EM&GMM\
文件 1475530 2019-12-22 18:56 EM&GMM\EM&GMM.docx
目录 0 2019-12-19 21:42 EM&GMM\数据集\
文件 6254 2019-12-17 22:55 EM&GMM\数据集\The old faithful dataset.txt
文件 6245 2019-12-19 09:43 EM&GMM\数据集\Theoldfaithfuldataset.txt
文件 2087 2019-12-19 21:44 EM&GMM\数据集\dest.txt
文件 4900 2019-12-19 10:28 EM&GMM\数据集\iris.txt
目录 0 2019-12-22 18:56 EM&GMM\程序源代码\
文件 3434 2019-12-22 18:23 EM&GMM\程序源代码\实验一.py
文件 4009 2019-12-22 18:42 EM&GMM\程序源代码\实验三.py
文件 2938 2019-12-22 18:32 EM&GMM\程序源代码\实验二.py
文件 4083 2019-12-22 18:51 EM&GMM\程序源代码\思考题1-1.py
文件 3197 2019-12-19 23:25 EM&GMM\程序源代码\思考题1-2(k-means-2维).py
文件 3364 2019-12-19 23:27 EM&GMM\程序源代码\思考题1-2(k-means-3维).py
相关资源
- New Periodic Solutions for the Circular Restri
- Applications of Ghoussoub-Preiss’s MPL t
- On the existence of periodic solutions of plan
- Rabinowitz's Saddle Point Theorem and Period
- Multiple Periodic Solutions for Discrete Hamil
- Periodic Solutions for Some Second Order Hamil
- Rademacher系列的CHL模型中的精确半BPS黑
- 离散傅里叶变换DFT的数学-音频应用
- activitiDemo.rar
-
Design for em
bedded Image Processing on FPG - A Sequential Bundle Method for Solving a MPEC
- STC15F
- x86 Disassembly
- Assembly Language for x86 Processors (7th Ed
- dubbo分布式tcc事务demo
- 《emwin实战指南(基于STM32-ISO开发板)
- Apk加固Demo
- pcbtemp电流计算软件
- 实验三 消息中间件应用开发:Active
- Remote Desktop Organizer v1.4.7 支持win10
- Navicat Premium 15汉化包.zip55438
- 易语言播放器组件无缝转换(Demo2.e)
- res10_300x300_ssd_iter_140000.caffemodel与dep
- Wolfram Mathematica 矩阵初等变换函数(
- cc2541 BLE DEMO
- 联想扬天电脑用户手册
-
Windows em
bedded Compact 2013 应用开发调 - Diltiazem augmented pentobarbital-induced LORR
- 电脑卡西欧计算器 fx-991CN X Emulator19中
- porting.RTEMS移植指南.双语.V20131224.pdf
评论
共有 条评论