说明

慕课网上例子,使用k-means算法分类图片, 此处调试运行通过, 并添加包管理内容, 使得其他同学容易运行。

例子地址: https://github.com/fanqingsong/cluster-images

运行环境:

python3.7

包管理工具:

pipenv

参考: https://www.cnblogs.com/wuzdandz/p/9545584.html

运行:

pipenv install

pipenv run ImageKmean.py

安装运行遇到问题

1、 安装依赖(numpy Pillow)很慢,

使用国内镜像替换:

http://greyli.com/set-custom-pypi-mirror-url-for-pip-pipenv-poetry-and-flit/

如果想对项目全局(per-project)设置,可以修改 Pipfile 中 [[source]] 小节:

[[source]]
url = "https://pypi.doubanio.com/simple"
verify_ssl = true
name = "douban"
1
2
3
4
5
[[source]]
 
url = "https://pypi.doubanio.com/simple"
verify_ssl = true
name = "douban"

如果不用pipenv, 使用pip安装

https://blog.csdn.net/lambert310/article/details/52412059

windows下,直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini,内容如下

 [global]
 index-url = https://pypi.tuna.tsinghua.edu.cn/simple

运行结果

输入为 三张红花 和 三张黄花

聚类输入参数为2类

分类结果为 黄花一类  红花一类

类一

类二

运行报错: ModuleNotFoundError: No module named 'PIL'

https://blog.csdn.net/qq_37721412/article/details/79159544

pip install Pillow

Pillow库

https://pillow.readthedocs.io/en/stable/handbook/overview.html

he Python Imaging Library adds image processing capabilities to your Python interpreter.

This library provides extensive file format support, an efficient internal representation, and fairly powerful image processing capabilities.

The core image library is designed for fast access to data stored in a few basic pixel formats. It should provide a solid foundation for a general image processing tool.

Let’s look at a few possible uses of this library.

参考

https://github.com/jump1003/ImageKmeans

https://scikit-learn.org/stable/auto_examples/index.html#general-examples

k-means cluster images的更多相关文章

  1. KNN 与 K - Means 算法比较

    KNN K-Means 1.分类算法 聚类算法 2.监督学习 非监督学习 3.数据类型:喂给它的数据集是带label的数据,已经是完全正确的数据 喂给它的数据集是无label的数据,是杂乱无章的,经过 ...

  2. 软件——机器学习与Python,聚类,K——means

    K-means是一种聚类算法: 这里运用k-means进行31个城市的分类 城市的数据保存在city.txt文件中,内容如下: BJ,2959.19,730.79,749.41,513.34,467. ...

  3. Python金融量化

    Python股票数据分析 最近在学习基于python的股票数据分析,其中主要用到了tushare和seaborn.tushare是一款财经类数据接口包,国内的股票数据还是比较全的 官网地址:http: ...

  4. 快速查找无序数组中的第K大数?

    1.题目分析: 查找无序数组中的第K大数,直观感觉便是先排好序再找到下标为K-1的元素,时间复杂度O(NlgN).在此,我们想探索是否存在时间复杂度 < O(NlgN),而且近似等于O(N)的高 ...

  5. matlab下K-means Cluster 算法实现

    一.概念介绍 K-means算法是硬聚类算法,是典型的局域原型的目标函数聚类方法的代表,它是数据点到原型的某种距离作为优化的目标函数,利用函数求极值的方法得到迭代运算的调整规则.K-means算法以欧 ...

  6. 网络费用流-最小k路径覆盖

    多校联赛第一场(hdu4862) Jump Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  7. 【十大经典数据挖掘算法】k

    [十大经典数据挖掘算法]系列 C4.5 K-Means SVM Apriori EM PageRank AdaBoost kNN Naïve Bayes CART 1. 引言 k-means与kNN虽 ...

  8. numpy.ones_like(a, dtype=None, order='K', subok=True)返回和原矩阵一样形状的1矩阵

    Return an array of ones with the same shape and type as a given array. Parameters: a : array_like Th ...

  9. 当我们在谈论kmeans(2)

        本稿为初稿,后续可能还会修改:如果转载,请务必保留源地址,非常感谢! 博客园:http://www.cnblogs.com/data-miner/ 其他:建设中- 当我们在谈论kmeans(2 ...

  10. scikit-learn包的学习资料

    http://scikit-learn.org/stable/modules/clustering.html#k-means http://my.oschina.net/u/175377/blog/8 ...

随机推荐

  1. redis -list

    列表的元素类型为string 按照插入顺序排序 增加: 例如: 从列表的 左侧 加入数据 a b c lpush 键 a b c 显示:1“c"2"b"3"c& ...

  2. SQL Server数据库————模糊查询和聚合函数

    ***********模糊查询*********/ 关键字: like (!!!!字符串类型) in (,,)  匹配()内的某个具体值(括号里可以写多个值) between... and.. 在某两 ...

  3. 用jenkins创建节点

    原料:(1)jre下载链接:https://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html ( ...

  4. linux下的别名机制

    相当于用户自己创建一个属于自己的命令.在当前用户的家目录下有一个.bashrc文件,编辑该文件: eg:alias cls='clear' 如果命令要生效需要重新登录.用户输入cls就可以达到清屏的目 ...

  5. 元数据Metadata

    元数据是什么? 元数据(Metadata),又称中介数据.中继数据,为描述数据的数据(data about data),主要是描述数据属性(property)的信息,用来支持如指示存储位置.历史数据. ...

  6. 【转】C# 定时器事件(设置时间间隔,间歇性执行某一函数,控制台程序)

    using System.Timers;定时器事件代码 static void Main(string[] args) { Method(); #region 定时器事件 Timer aTimer = ...

  7. 老白关于rac性能调优的建议(10gRAC)

    RAC应用设计方面需要在底层做很有设计.虽然ORACLE的售前人员总是说RAC的扩展性是透明的,只要把应用分到不同的节点,就可以平滑的扩展系统能力了.而事实上,RAC的CACHE FUSION机制决定 ...

  8. 04 前端篇(JQuery)

    jquery: http://www.cnblogs.com/yuanchenqi/articles/5663118.html 优点:简洁.兼容 jquery 对象:   jQuery 或  $ 基本 ...

  9. 利用node.js来实现长连接/聊天(通讯实例)

    首先: 需要在服务器端安装node.js,然后安装express,socket.io这两个模块,并配置好相关的环境变量等. 其次: 服务端代码如下: var app = require('expres ...

  10. mysql排序,同样的sql,mysql 每次查询结果顺序不一致

    某天项目中写了一句排序sql,但是发现每次执行的结果都不同,就是排序顺序不一样. select * from table_tmp order by printStatus asc,dealTime d ...