Running Jupyter with SciKit-learn

For more information on Scikit check out (https://scikit-learn.org/)

First start your Jupyter server using the short process:

  1. Open https://ondemand.hpc.fau.edu
  2. Login
  3. Click Interactive Apps -> Jupyter Notebook
  4. Enter the requirements for your job
  5. Click “Launch”
  6. Wait for allocation to a node, once available click "Connect to Jupyter"
  7. Create a new notebook by clicking: New -> Python 3 or open an existing notebook  
  8. Enter "pip install --user -U scikit-learn “
    1. You may wish to update your pip if you wish. This is not required.
    2. Enter “pip install upgrade --user pip”
  9. Enter "pip install --user matplotlib"
  10. Wait for this to complete.

Running Scikit-learn code:

  1. Click “New”
  2. Click "Python 3”
  3. Enter the following demo code from (https://scikit-learn.org/stable/auto_examples/plot_isotonic_regression.html#sphx-glr-auto-examples-plot-isotonic-regression-py)
    print(__doc__)
    
    # Author: Nelle Varoquaux <nelle.varoquaux@gmail.com>
    #         Alexandre Gramfort <alexandre.gramfort@inria.fr>
    # License: BSD
    
    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib.collections import LineCollection
    
    from sklearn.linear_model import LinearRegression
    from sklearn.isotonic import IsotonicRegression
    from sklearn.utils import check_random_state
    
    n = 100
    x = np.arange(n)
    rs = check_random_state(0)
    y = rs.randint(-50, 50, size=(n,)) + 50. * np.log1p(np.arange(n))
    
    # #############################################################################
    # Fit IsotonicRegression and LinearRegression models
    
    ir = IsotonicRegression()
    
    y_ = ir.fit_transform(x, y)
    
    lr = LinearRegression()
    lr.fit(x[:, np.newaxis], y)  # x needs to be 2d for LinearRegression
    
    # #############################################################################
    # Plot result
    
    segments = [[[i, y[i]], [i, y_[i]]] for i in range(n)]
    lc = LineCollection(segments, zorder=0)
    lc.set_array(np.ones(len(y)))
    lc.set_linewidths(np.full(n, 0.5))
    
    fig = plt.figure()
    plt.plot(x, y, 'r.', markersize=12)
    plt.plot(x, y_, 'g.-', markersize=12)
    plt.plot(x, lr.predict(x[:, np.newaxis]), 'b-')
    plt.gca().add_collection(lc)
    plt.legend(('Data', 'Isotonic Fit', 'Linear Fit'), loc='lower right')
    plt.title('Isotonic regression')
    plt.show()
    
  4. Click Run and you will be presented with the graph confirming Sci-kit is working in Jupyter.

Details

Article ID: 142267
Created
Mon 10/3/22 9:33 AM
Modified
Thu 5/11/23 12:41 PM