Skip to content

Instantly share code, notes, and snippets.

@gkhayes
Last active March 3, 2019 04:36
Show Gist options
  • Save gkhayes/0e371c437ce9512b9d6f4f3441bb8a29 to your computer and use it in GitHub Desktop.
Save gkhayes/0e371c437ce9512b9d6f4f3441bb8a29 to your computer and use it in GitHub Desktop.
Fit a logistic regression to the Iris dataset and make predictions - Attempt 2
# Initialize logistic regression object and fit object
lr_model2 = mlrose.LogisticRegression(algorithm = 'random_hill_climb', max_iters = 1000,
bias = True, learning_rate = 0.01,
early_stopping = True, clip_max = 5, max_attempts = 100,
random_state = 3)
lr_model2.fit(X_train_scaled, y_train_hot)
# Predict labels for train set and assess accuracy
y_train_pred = lr_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 = lr_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