如何在Python中实现找到两个未知特征来从其余样本中聚类出已知样本?

问题描述 投票:0回答:1

我有一个名为:

synthetic_feature_file 
的数据集,包含超过 50,000 个特征和 43 个样本。给定
sample_indices = syn_data.index.isin([1, 6, 7, 11, 14, 15, 27])
,它代表已知样本的索引,我想将它们与其余样本分开,并用与其他样本不同的颜色标记它们。已知样本和其他样本的数据不应重叠。有人可以提供一段代码来处理这个问题吗?

另外,这是我之前写的代码。由于它只执行随机处理,所以我想实现其他方法或其他方式来满足上一段所述的要求:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

syn_data = pd.read_csv(synthetic_feature_file)
sample_indices = syn_data.index.isin([1, 6, 7, 11, 14, 15, 27])
x_feature = np.random.choice(syn_data.columns[70:85])
y_feature = np.random.choice(syn_data.columns[30:60])

plt.figure(figsize=(8, 6))
other_samples = syn_data.iloc[~sample_indices]
plt.scatter(other_samples[x_feature], other_samples[y_feature], color='blue', label='Other Samples')
red_samples = syn_data.iloc[sample_indices]
plt.scatter(red_samples[x_feature], red_samples[y_feature], color='red', label='Sample Indices')

plt.xlabel(x_feature)
plt.ylabel(y_feature)
plt.title("Visualization")
plt.legend()
plt.show()

我希望它可以像这样:link 图片来源:谷歌

python
1个回答
0
投票

聚类不太可能适用于随机数据(它只是不会形成聚类)。

为此,您可以使用seaborn包:https://pypi.org/project/seaborn

企鹅数据集是一个很好的演示:

import seaborn as sns

penguins = sns.load_dataset("penguins")
sns.jointplot(data=penguins, x="flipper_length_mm", y="bill_length_mm", hue="species")

给出了这个:

我相信这就是你想要的。

© www.soinside.com 2019 - 2024. All rights reserved.