How to prepare a machine learning workflow in Python?

This recipe helps you prepare a machine learning workflow in Python
In [2]:
## How to prepare a machine leaning workflow in Python 
def Kickstarter_Example_25():
    print()
    print(format('How to prepare a machine leaning workflow in Python', '*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # Load libraries
    from sklearn import datasets
    from sklearn.preprocessing import StandardScaler
    from sklearn.linear_model import Perceptron
    from sklearn.model_selection import train_test_split
    from sklearn.metrics import accuracy_score, confusion_matrix

    # Load the iris dataset
    iris = datasets.load_iris()

    # Create our X and y data
    X = iris.data
    y = iris.target

    # Split the data into 70% training data and 30% test data
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)

    # Preprocess The X Data By Scaling
    sc = StandardScaler(with_mean=True, with_std=True)
    sc.fit(X_train)

    # Apply the scaler to the X training data
    X_train_std = sc.transform(X_train)

    # Apply the SAME scaler to the X test data
    X_test_std = sc.transform(X_test)

    #Train A Perceptron Learner
    ppn = Perceptron(alpha=0.0001, class_weight=None, eta0=0.1,
                     fit_intercept=True, n_iter=40, n_jobs=4,
                     penalty=None, random_state=0, shuffle=True,
                     verbose=0, warm_start=False)

    # Train the perceptron
    ppn.fit(X_train_std, y_train)

    # Apply The Trained Learner To Test Data
    y_pred = ppn.predict(X_test_std)

    # Compare The Predicted Y With The True Y
    # View the predicted y test data
    print(); print("y_pred: ", y_pred)

    # View the true y test data
    print(); print("y_test: ", y_test)

    # Examine Accuracy Metric
    print(); print('Accuracy: %.2f' % accuracy_score(y_test, y_pred))
    print(); print('Comfusion Matrix:\n', confusion_matrix(y_test, y_pred))

Kickstarter_Example_25()
***************How to prepare a machine leaning workflow in Python****************

y_pred:  [1 1 1 1 2 0 0 1 2 0 1 1 1 1 1 1 2 0 1 1 0 1 0 1 2 1 2 1 0 1 0 2 1 0 1 0 1
 0 1 0 2 0 1 1 1]

y_test:  [2 2 2 1 2 0 0 2 2 0 2 1 2 1 1 2 2 0 1 1 0 1 0 1 2 2 2 2 0 2 0 2 1 0 2 0 2
 0 1 0 2 0 2 1 2]

Accuracy: 0.69

Comfusion Matrix:
 [[13  0  0]
 [ 0 11  0]
 [ 0 14  7]]