python - sklearn.preprocessing.scale 是如何工作的?
问题描述
我有一个二维数据数组。描述一个人的收入和他的年龄 在准备模型之前,数据正在被缩放。缩放数据后,它将先前数据的值完全更改为一些新的(接近 0 )值。
from numpy import random, array
#Create fake income/age clusters for N people in k clusters
def createClusteredData(N, k):
random.seed(10)
pointsPerCluster = float(N)/k
X = []
for i in range (k):
incomeCentroid = random.uniform(20000.0, 200000.0)
ageCentroid = random.uniform(20.0, 70.0)
for j in range(int(pointsPerCluster)):
X.append([random.normal(incomeCentroid, 10000.0), random.normal(ageCentroid, 2.0)])
X = array(X)
return X
%matplotlib inline
from sklearn.cluster import KMeans
import matplotlib.pyplot as plt
from sklearn.preprocessing import scale
from numpy import random, float
data = createClusteredData(100, 5)
model = KMeans(n_clusters=5)
model = model.fit(scale(data))```
what does that scale actually do in that model? I came to know it brings data to the same level or at comparison state. But what Mathematical functions it performs in data. I have referenced the documentation of sci-kit learn but couldn't get what it means. Please explain the operations performed in simple language
解决方案
它正在从每个观察的数据中删除平均值,然后除以数据的标准差
查看参数以获取更多详细信息
with_mean boolean, True by default
If True, center the data before scaling.
with_std boolean, True by default
If True, scale the data to unit variance (or equivalently, unit standard deviation).
推荐阅读
- php - 如何获取 column1 中的 value1 和 column2 中的 value2 但 column1 中的 value2 在 column2 中没有 value1 的行?
- android - *** 帮助 *** ADB 命令行 - 更新/下载 Google Play 商店应用
- entity-framework - EF 非核心的 Microsoft.EntityFrameworkCore.InMemory 替代方案?
- python - 我的不和谐机器人可以从 subreddit 中抓取一个随机的“热门”帖子并根据命令链接它吗?
- django - 使用 Djongo 的 Django 中的 Mongodb 错误:pymongo.errors.OperationFailure:过滤器中不支持的类型
- haskell - 广度优先树和深度优先树的 Traversable 是否不同?
- python - 如何计算前一个日期直到第一个事件的移动平均值?
- javascript - 为什么“!duplicateNote.length”不起作用?
- common-lisp - 从序列中删除所有重复元素
- python - 如何格式化 API JSON 输出?