B.Germ
B.Germ

Reputation: 85

Modyfing python code and running PCA in Tableau

I am a beginner, my first time to use Tableau. I want to perfrorm PCA from Python code in Tableau Dekstop. I got main ideas behind that process, TabPy is installed.

My dataset is really big, having around 1000 + columns.

I took a look on modyfing python code (my python code at the end) to be able to run in tableau.

My question is, in my case how can specify _arg1,_arg2,_arg3,... because I used dataset.drop('Class', 1) to define x, and dataset['Class'] to define y?

Thank you in advance.

# importing or loading the dataset

dataset = pd.read_excel('NL_undivided.xlsx')

 

# distributing the dataset into two components X and Y

X = dataset.drop('Class', 1)

Y = dataset['Class']

 

from sklearn.preprocessing import StandardScaler

scaler = StandardScaler()

scaler.fit(X)

 

scaled_data = scaler.transform(X)

 

from sklearn.decomposition import PCA

pca = PCA(n_components=2)

pca.fit(scaled_data)

 

x_pca = pca.transform(scaled_data)

 

plt.figure(figsize=(20,10))

fig, ax = plt.subplots(figsize=(20, 10))

 

scatter = ax.scatter(x_pca[:,0],x_pca[:,1],c=Y,cmap='rainbow',)

 

# produce a legend with the unique colors from the scatter

legend1 = ax.legend(*scatter.legend_elements(),

                    loc="best", title="Cohorts")

ax.add_artist(legend1)

plt.figure(figsize=(15,8))

Upvotes: 0

Views: 387

Answers (0)

Related Questions