Created
January 21, 2019 06:53
-
-
Save gkhayes/1f2585f1d7a300ac50610c75ec90ae75 to your computer and use it in GitHub Desktop.
Pre-process the Iris dataset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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