Skip to content

Instantly share code, notes, and snippets.

@peeush-agarwal
Created March 14, 2022 17:23
Show Gist options
  • Save peeush-agarwal/067fa7895587064b3ed7a4693e62c727 to your computer and use it in GitHub Desktop.
Save peeush-agarwal/067fa7895587064b3ed7a4693e62c727 to your computer and use it in GitHub Desktop.
PCA: standardize the wine dataframe
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
# split into training and testing sets
X, y = df_wine.iloc[:, 1:].values, df_wine.iloc[:, 0].values
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.3,
stratify=y, random_state=0
)
# standardize the features
sc = StandardScaler()
X_train_std = sc.fit_transform(X_train)
X_test_std = sc.transform(X_test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment