Skip to content

Instantly share code, notes, and snippets.

@gkhayes
Last active March 3, 2019 04:34
Show Gist options
  • Select an option

  • Save gkhayes/8e41e09569d227f805ce62c8f5adfc46 to your computer and use it in GitHub Desktop.

Select an option

Save gkhayes/8e41e09569d227f805ce62c8f5adfc46 to your computer and use it in GitHub Desktop.
Attempt 2 at fitting a neural network from the Iris dataset
# Initialize neural network object and fit object
nn_model2 = mlrose.NeuralNetwork(hidden_nodes = [2], activation = 'relu',
algorithm = 'gradient_descent', max_iters = 1000,
bias = True, is_classifier = True, learning_rate = 0.0001,
early_stopping = True, clip_max = 5, max_attempts = 100,
random_state = 3)
nn_model2.fit(X_train_scaled, y_train_hot)
# Predict labels for train set and assess accuracy
y_train_pred = nn_model2.predict(X_train_scaled)
y_train_accuracy = accuracy_score(y_train_hot, y_train_pred)
print('Training accuracy: ', y_train_accuracy)
# Predict labels for test set and assess accuracy
y_test_pred = nn_model2.predict(X_test_scaled)
y_test_accuracy = accuracy_score(y_test_hot, y_test_pred)
print('Test accuracy: ', y_test_accuracy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment