import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
df= pd.read_csv(r'C:\Users\Vikipedia\Downloads\mushrooms.csv')
df.head()

Calculate the unique number of each category of each column:
X = df.drop('class', axis=1)
y = df['class']
y = y.map({'p':'Posionous','e': 'Edible'})
cat_cols= X.select_dtypes(include='object').columns.tolist()
for col in cat_cols:
print (f" col name : {col}, N Unique : {X[col].nunique()}")

Compute and generate a table:
for col in cat_cols:
X[col]=X[col].astype('category')
X[col]=X[col].cat.codes
X.head()

本文比较了t-SNE和PCA在蘑菇分类任务中的性能。t-SNE展现出优于PCA的聚类能力,能将有毒和可食用蘑菇清晰区分开,而PCA的分类效果不佳。通过调整t-SNE的困惑度和n_iter参数,如困惑度为30,n_iter为5000,可获得稳定的聚类形状。结论是t-SNE在处理线性和非线性数据集时提供更优的可视化和聚类结果,但可能不保留数据的全局结构。
最低0.47元/天 解锁文章
3756

被折叠的 条评论
为什么被折叠?



