Building my first maching learning system

记录一下自己学习中遇到的问题。。

1. IDE使用的是pycharm,暂时没有发现什么问题。

2. 需要用到依赖包scipy& numpy & scikit-learn & matplotlib

其中由于matplotlib 在windows上安装比较麻烦所以在ubuntu上实现。

matplotlib 安装代码:(2选1)

sudo apt install python-matplotlib

 
sudo pip install matplotlib

3.第一次接触Matplotlib 画图,尝试把《机器学习系统设计》第二章的第一个图画了一下,进行数据的可视化,先对整个iris数据集有一个视觉上的印象方便采取相应的算法,代码如下:

from matplotlib import pyplot as plt
from sklearn.datasets import load_iris
import numpy
data = load_iris()
features = data['data']
feature_names = data['feature_names']
target = data['target']
#plt.figure(12)
plt.subplot(231)
for t,marker,c in zip(xrange(3),">oh","rgb"):
    plt.scatter(features[target == t,0],features[target == t,1],50,marker = marker,c=c)
plt.xlabel(feature_names[0])
plt.ylabel(feature_names[1])
#plt.plot()
plt.subplot(232)
for t,marker,c in zip(xrange(3),">oh","rgb"):
    plt.scatter(features[target == t,0],features[target == t,2],50,marker = marker,c=c)
plt.xlabel(feature_names[0])
plt.ylabel(feature_names[2])
#plt.plot()
plt.subplot(233)
for t,marker,c in zip(xrange(3),">oh","rgb"):
    plt.scatter(features[target == t,0],features[target == t,3],50,marker = marker,c=c)
plt.xlabel(feature_names[0])
plt.ylabel(feature_names[3])
plt.subplot(234)
for t,marker,c in zip(xrange(3),">oh","rgb"):
    plt.scatter(features[target == t,1],features[target == t,2],50,marker = marker,c=c)
plt.xlabel(feature_names[1])
plt.ylabel(feature_names[2])
plt.subplot(235)
for t,marker,c in zip(xrange(3),">oh","rgb"):
    plt.scatter(features[target == t,1],features[target == t,3],50,marker = marker,c=c)
plt.xlabel(feature_names[1])
plt.ylabel(feature_names[3])
plt.subplot(236)
for t,marker,c in zip(xrange(3),">oh","rgb"):
    plt.scatter(features[target == t,2],features[target == t,3],50,marker = marker,c=c)
plt.xlabel(feature_names[2])
plt.ylabel(feature_names[3])
plt.show()

4.画出各个数据点的分布后可以构建第一个分类模型。

5.简单阐述K-means.(clustering 聚类)

k-means 算法的具体步骤:

  1. 选定 K 个中心 \mu_k 的初值。这个过程通常是针对具体的问题有一些启发式的选取方法,或者大多数情况下采用随机选取的办法。因为前面说过 k-means 并不能保证全局最优,而是否能收敛到全局最优解其实和初值的选取有很大的关系,所以有时候我们会多次选取初值跑 k-means ,并取其中最好的一次结果。
  2. 将每个数据点归类到离它最近的那个中心点所代表的 cluster 中。
  3. 用公式 \mu_k = \frac{1}{N_k}\sum_{j\in\text{cluster}_k}x_j 计算出每个 cluster 的新的中心点。
  4. 重复第二步,一直到迭代了最大的步数或者前后的 J 的值相差小于一个阈值为止。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值