python - 如何将 csv 数据集 100% 作为 sklearn 包的 make_blobs() 的输出
问题描述
我是 Python 的新手,只想检查、编辑、调整一些基本聚类功能的代码。
我有一个 csv 文件,其中大约 1000 个值分为两列,我想在 python 环境中导入它并让它 100% 兼容作为 make_blobs() 的输出
我导入了数据并使用以下方法创建了一个数组:
import pandas as pd
import numpy as np
X = pd.read_csv("/data.csv")
X = X.as_matrix()
我可以看到成功地将数据视为数组:
> array([[3.094545, 2.106678],
> [2.886592, 2.029667],
> [3.016772, 2.23431 ],
> [2.739621, 1.883947],
> [3.202192, 2.009674],
> [3.295198, 1.346389],
> [2.769266, 2.041654],
> [2.867035, 2.222251],
> [2.963459, 2.22474 ],
> [3.187592, 2.155406],
> [2.889698, 1.973654],
> [3.079113, 2.219817],
> [3.20275 , 1.833527],
> [3.008534, 2.005787],
> [3.16477 , 2.050318],
> [2.7942 , 1.685328],
> [3.159495, 2.02407 ],
> [3.058299, 1.428027],
> [3.092592, 1.923008],
. 问题是使用时:
from sklearn.datasets.samples_generator import make_blobs
centers = [[1, 1], [-1, -1], [1, -1]]
X, labels_true = make_blobs(n_samples = 300, centers=centers, cluster_std=0.5,
random_state=0)
名为 labels_true 的第二个变量包含从 0 到 2 不等的值。
我想知道我能做什么,让“data.csv”文件具有与 X 相同的输出,并且 labels_true
解决方案
您的数据未标记。
如果您有标签,则不需要聚类。
make_blobs
是合成的,所以它也可以生成“正确”的标签,但你将不得不这样做。
推荐阅读
- javascript - 从存储中下载 url 后如何通过时间戳在数据库中实时更改图像名称
- list - 如何更新变量以保持级联结构中列表的长度?
- php - 在第二个 php 文件(通过 jQuery load())中更改后,如何确保 index.php 中的 PHP 变量可用?
- javascript - 如何在 IIFE 中访问一个函数的内容?
- c# - 如何在 C# 的函数 posgrest 中将 null 设置为 Integer
- python - PyTorch C++ 扩展:如何索引张量并更新它?
- java - 尝试使用 java 读取 csv 文件并选择特定的行/列
- javascript - echarts:如何在 3D 轴标签中使用下标/上标(或乳胶/mathjax)?
- javascript - Dropzone 无法在服务器上运行。在本地主机上工作正常
- typescript - 我想将 Blob URL 转换为图像文件并调整图像大小以将图像发送到 APIservice