https://developer.ibm.com/tutorials/awb-k-means-clustering-in-python/

PCA: 对2D数据非常好理解,但是对tensor(3D以上维度),假设维度为N,

可以理解为 求一个 方阵, 每一条N维列向量的数据乘以这个方阵(即进行多维坐标轴旋转),

得到的是降维变换(小于等于N维空间的)后的向量;

算法会有一些前提条件与假设,而通过数据预处理,

不仅可以保障与满足这些,同时能提高模型的有效计算速度。

“不空”、“不漏”、“不乱”、“不限”、“不差”、“不异”:

  • Dedkind Split
  • 不限、不差、不异

    例如:

    • 大多数算法假设数据是完整而有效的。
    • Naive-Bayes算法假设数据维度之间的correlationship是非常小的。
    • K-Means算法要估计最佳的Number of Cluster簇数。

Preprocessing

  1. Ensure that the columns were imported with the correct data types.

    $ print(df.dtypes)

    distance_center float64

    num_rooms float64

    property_size float64

    age float64

    utility_cost float64

    label int64

    dtype: object

  2. Check for missing values.

    Consider imputation or removing missing values if there are many.

    $ df.isnull().sum()

    distance_center 0

    num_rooms 0

    property_size 0

    age 0

    utility_cost 0

    label 0

    dtype: int64

  3. Check for outliers.

    Consider removing outliers If appropriate, so that the final cluster shapes are not skewed.

  4. Standardize scales first using scikit-learn;

  5. Identify correlated features using mathematics(Measure of correlationship);

    Consider using a pairwise plot to identify strong correlations and remove features that are highly correlated.

EDA(Exploratory Data Analysis)

These are the steps you will follow:

  • Create a AI project and open a Jupyter Notebook.
  • Generate a data set and do preprocess.
  • Perform EDA (exploratory data analysis).
  • Choose K clusters using WCSS.
  • Interpret K-means clustering.

Example: Choose best K for K-Means model

When EDA is complete, you must choose how many clusters to separate your data into.

  • set K manually in scikit-learn If you already know how many groups you want to make.
  • use the elbow method to test different K values, If you are not sure how many groups are appropriate,
    • The elbow method works by computing the Within Cluster Sum of Squares (WCSS), quantifies the variance (or spread) of data within a cluster.
    • If WCSS decreases, the data within the clusters are more similar.
    • As K increases, there should be a natural decrease in WCSS because the distance between the data in its cluster to its center will be smaller.
    • The ideal K is the "elbow" point of the graph, where WCSS stops decreasing or starts to marginally decrease as K increases.
    • The elbow method is particularly useful for big data sets that have lots of potential clusters because there is a trade-off between computational power required to run the algorithm and the number of clusters generated.

Use the following steps to implement the elbow method.

  • Create an empty list to hold WCSS values at different K values.
  • Fit the clusters with different K values.
  • At each K value, append the WCSS value to the list.
  • Graph the WCSS values versus the number of clusters.

Use the elbow method to find a good number of clusters using WCSS (within-cluster sums of squares)

wcss = []

Let's check for up to 10 clusters

for i in range(1, 11):

kmeans = KMeans(n_clusters=i, init='k-means++', max_iter=300, n_init=10, random_state=42)

kmeans.fit(df)

wcss.append(kmeans.inertia_)

plt.plot(range(1, 11), wcss)

plt.title('Elbow Method')

plt.xlabel('Number of clusters')

plt.ylabel('WCSS')

plt.show()

Select the "elbow point" of the graph as your K value.



Elbow method graph

Rerun K-means with your chosen K value. Use the n_clusters parameter to set the K value.

Be sure to set the random_state parameter for reproducibility.

The graph indicates that 5 is the ideal number of clusters, which makes sense because we set the make-blobs number of centers parameter equal to 5.

Ideal number of clusters

Step 5. Interpret K-means clustering

**Using PCA(Principal Component Analysis) and similar dimensionality reduction technique

so you can graph your clusters in a two-dimensional space and visualize the groupings.

This tutorial does not cover the exact details of PCA,

but our data has five dimensions, and thus dimensionality reduction is needed to visualize clusters of data with more than two dimensions in a 2-D space.

It's likely that most data sets that you encounter when performing K-means clustering have data with more than two dimensions.

The following steps are the high-level steps to interpret K-means clustering.

BigdataAIML-Important Data Features preprocessing points非常重要的数据维度预处理方面的更多相关文章

  1. Spring Data:企业级Java的现代数据访问技术(影印版)

    <Spring Data:企业级Java的现代数据访问技术(影印版)>基本信息原书名:Spring Data:Modern Data Access for Enterprise Java作 ...

  2. 17.1.1.8?Setting Up Replication with Existing Data设置复制使用存在的数据

    17.1.1.8?Setting Up Replication with Existing Data设置复制使用存在的数据 当设置复制使用存在的数据,你需要确定如何最好的从master 得到数据到sl ...

  3. 【转】Jmeter中使用CSV Data Set Config参数化不重复数据执行N遍

    Jmeter中使用CSV Data Set Config参数化不重复数据执行N遍 要求: 今天要测试上千条数据,且每条数据要求执行多次,(模拟多用户多次抽奖) 1.用户id有175个,且没有任何排序规 ...

  4. Jmeter===Jmeter中使用CSV Data Set Config参数化不重复数据执行N遍(转)

    Jmeter中使用CSV Data Set Config参数化不重复数据执行N遍 要求: 今天要测试上千条数据,且每条数据要求执行多次,(模拟多用户多次抽奖) 1.用户id有175个,且没有任何排序规 ...

  5. Azure Data Factory(二)复制数据

    一,引言 上一篇主要只讲了Azure Data Factory的一些主要概念,今天开始新的内容,我们开始通过Azure DevOps 或者 git 管理 Azure Data Factory 中的源代 ...

  6. 使用Spring Data ElasticSearch+Jsoup操作集群数据存储

    使用Spring Data ElasticSearch+Jsoup操作集群数据存储 1.使用Jsoup爬取京东商城的商品数据 1)获取商品名称.价格以及商品地址,并封装为一个Product对象,代码截 ...

  7. Define the Data Model and Set the Initial Data 定义数据模型并设置初始数据

    This topic describes how to define the business model and the business logic for WinForms and ASP.NE ...

  8. Jmeter—6 CSV Data Set Config 通过文件导入数据

    线程组循环次数大于1的时候,请求里每次提交的数据都相同.有的系统限制了不能提交相同数据,我们通过 CSV Data Set Config 加载csv文件数据. 1 创建一个文本文件,输入参数值保存为. ...

  9. 转:代码的坏味道之二十 :Data Class(纯稚的数据类)或POJO

    所谓Data Class是指:它们拥有一些值域(fields),以及用于访问(读写]这些值域的函数,除此之外一无长物.这样的classes只是一种「不会说话的数据容器」,它们几乎一定被其他classe ...

  10. [译] 使用Using Data Quality Services (DQS) 清理用户数据

    SQL Server 2012 Data Quality Services (DQS)  允许你使用自己的知识库来清洗数据. 在本文中我会展示一个简单示例. 使用DQS清理步骤如下: A. 建立DQS ...

随机推荐

  1. C#——基于CancellationTokenSource实现Task的取消

    参照:第七节:利用CancellationTokenSource实现任务取消和利用CancellationToken类检测取消异常. - Yaopengfei - 博客园 (cnblogs.com) ...

  2. 使用 GitHub Actions 构建 CosyVoice 项目的运行环境镜像并推送到阿里云容器镜像服务和 GitHub Package Registry

    使用 GitHub Actions 构建 CosyVoice 项目的运行环境镜像并推送到阿里云容器镜像服务和 GitHub Package Registry 概述 本文介绍了如何使用 GitHub A ...

  3. 【经验】Git|Windows下如何管理和部署多个Git账号的SSH密钥文件

    生成 SSH 密钥 先打开一个git窗口,生成ssh密钥. 如果打开的不是git窗口,而是cmd窗口,则需要先切换到C:\Users\用户名\.ssh目录下. 下面这条指令的your_email和yo ...

  4. 基于口令的密码—PBE

    目录 流程 加密流程 解密流程 盐的作用 通过拉伸来改良PBE的安全性 如何生成安全口令的建议 定义: PBE是一种根据口令生成密钥并用该密钥进行加密的方法. 加密和解密都使用同一个密钥. 口令一词多 ...

  5. vue3 基础-插件 plugin

    前几篇我们介绍了 mixin 混入的的方式能实现对代码的复用, 而本篇将要介绍的 plugin 将会更加适合这种通用性功能的代码的复用和扩展. 最常用的场景, 比如轮播图就非常实用 plugin 来实 ...

  6. 将Spring Boot项目部署到自己的服务器上

    第一步: 先准备好MobaXterm,链接上服务器后进入宝塔面板 https://www.bt.cn/new/download.html 找到Linux面板安装脚本复制命令 第二步: 进入MobaXt ...

  7. 金融科技应用:基于XGBoost与SHAP的信用评分模型构建全流程解析

    引言 在传统金融体系中,信用评估高度依赖央行征信数据,但全球仍有约20亿人口处于"信用隐形"状态.随着金融科技发展,通过整合社交数据.消费行为等替代数据源构建智能信用评估系统,已成 ...

  8. odoo14使用的文件服务器【NFS】

    linux系统之间要文件共享实现方式:目前测试系统为Ubuntu20.04LTS 条件:1.保证两个系统都是linux:            2.目前实现是同一个局域网内: 服务端:172.26.1 ...

  9. 洛谷 P5012 水の数列

    洛谷 P5012 水の数列 Problem 给你一个长度为\(n(n\le10^6)\)的数列,有\(T(T\le 10^3)\)组询问,每一组询问查询区间\([l,r]\),请选择一个\(x\),将 ...

  10. java的5种异常的语法

    1 try{}catch(){} ​ 2 try{}catch(){}catch(){} ​ 3 try{}catch(){}finally{} ​ 4 try{}catch(){}catch(){} ...