Lukas00990 2022-10-27 07:39 采纳率: 40.8%
浏览 50
已结题

机器学习的数据维度 定义

现在在做机器学习,想问下下面这个数据维度是多少?

是12维还是2维

img

我之所以会疑惑,是因为下面这个例子。 这的1 我理解就是表格,为什么这个是三维? 而如果以1的定义,2 的例子应该是个三维数据,为什么是二维呢?我很疑惑
1、输入4个3维的数据,然后通过t-SNE降维称2维的数据

import numpy as np
from sklearn.manifold import TSNE
X = np.array([[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]])
tsne = TSNE(n_components=2)
tsne.fit_transform(X)
print(tsne.embedding_)

from time import time
import matplotlib.pyplot as plt
from matplotlib.ticker import NullFormatter
from sklearn import manifold, datasets
from mpl_toolkits.mplot3d import Axes3D

# X是一个(1000, 3)的2维数据,color是一个(1000,)的1维数据
n_points = 1000
X, color = datasets.samples_generator.make_s_curve(n_points, random_state=0)
n_neighbors = 10
n_components = 2

# 创建了一个figure,标题为"Manifold Learning with 1000 points, 10 neighbors"
fig = plt.figure(figsize=(8, 8))
plt.suptitle("Manifold Learning with %i points, %i neighbors" % (1000, n_neighbors), fontsize=14)

'''绘制S曲线的3D图像'''
ax = fig.add_subplot(211, projection='3d')
ax.scatter(X[:, 0], X[:, 1], X[:, 2], c=color, cmap=plt.cm.Spectral)
ax.view_init(4, -72)  # 初始化视角

'''t-SNE'''
t0 = time()
tsne = manifold.TSNE(n_components=n_components, init='pca', random_state=0)
Y = tsne.fit_transform(X)  # 转换后的输出
t1 = time()
print("t-SNE: %.2g sec" % (t1 - t0))  # 算法用时

ax = fig.add_subplot(2, 1, 2)
plt.scatter(Y[:, 0], Y[:, 1], c=color, cmap=plt.cm.Spectral)
plt.title("t-SNE (%.2g sec)" % (t1 - t0))
ax.xaxis.set_major_formatter(NullFormatter())  # 设置标签显示格式为空
ax.yaxis.set_major_formatter(NullFormatter())
plt.show()

  • 写回答

5条回答 默认 最新

查看更多回答(4条)

报告相同问题?

问题事件

  • 系统已结题 11月4日
  • 已采纳回答 10月27日
  • 创建了问题 10月27日