Skip to content

Instantly share code, notes, and snippets.

@gkhayes
Created January 21, 2019 06:53
Show Gist options
  • Save gkhayes/1f2585f1d7a300ac50610c75ec90ae75 to your computer and use it in GitHub Desktop.
Save gkhayes/1f2585f1d7a300ac50610c75ec90ae75 to your computer and use it in GitHub Desktop.
Pre-process the Iris dataset
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler, OneHotEncoder
# Split data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(data.data, data.target,
test_size = 0.2, random_state = 3)
# Normalize feature data
scaler = MinMaxScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
# One hot encode target values
one_hot = OneHotEncoder()
y_train_hot = one_hot.fit_transform(y_train.reshape(-1, 1)).todense()
y_test_hot = one_hot.transform(y_test.reshape(-1, 1)).todense()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment