""" logistic_regression_with_scikit_learn.py trains and uses a model to predict one of three classes for each input """ # Import needed libraries. import random from sklearn.datasets import load_iris from sklearn.linear_model import LogisticRegression # Set parameters. number_of_prediction_inputs = 100 # Load test data. X, y = load_iris(return_X_y=True) print("X - Data Features:") print(X) print("y - Data Classes:") print(y) # Instantiate a model. model = LogisticRegression(random_state=0) # Train the model. estimator = model.fit(X, y) # Get the training score (accuracy). score = estimator.score(X, y) print("Score:") print(score) # Create shuffled prediction input data. shuffled_input_data = X random.shuffle(shuffled_input_data) print("Shuffled Input Data:") print(shuffled_input_data) # Get prediction input data from the shuffled training data. prediction_input = shuffled_input_data[:number_of_prediction_inputs, :] print("Prediction Input:") print(prediction_input) # Make predictions. predicted_classes = estimator.predict(prediction_input) print("Predicted Classes: ") print(predicted_classes) # Get prediction probabilities for each class. probabilities = estimator.predict_proba(prediction_input) print("Probabilities: ") print(probabilities)