Skip to content
Snippets Groups Projects
Select Git revision
  • f22eb7bf8f55112af0e91b9df40ad509e7dbfc58
  • main default protected
  • 3D_UNet
  • notebooksv1
  • scaleZYX_mean
  • notebooks
  • convert_tiff_folders
  • test
  • notebook_update
  • threshold-exploration
  • optimize_scaleZYXdask
  • layered_surface_segmentation
  • conv_zarr_tiff_folders
  • 3d_watershed
  • tr_val_te_splits
  • save_files_function
  • memmap_txrm
  • v0.4.1
  • v0.4.0
  • v0.3.9
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
  • v0.2.0
25 results

Unet.ipynb

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ex9_1_3.py 1.13 KiB
    # exercise 9.1.3
    import importlib_resources
    from matplotlib.pyplot import figure, show
    from scipy.io import loadmat
    from dtuimldmtools import dbplot, dbprobplot
    from sklearn.ensemble import RandomForestClassifier
    
    filename = importlib_resources.files("dtuimldmtools").joinpath("data/synth7.mat")
    
    # Load Matlab data file and extract variables of interest
    mat_data = loadmat(filename)
    X = mat_data['X']
    y = mat_data['y'].squeeze()
    attributeNames = [name[0] for name in mat_data['attributeNames'].squeeze()]
    classNames = [name[0][0] for name in mat_data['classNames']]
    N, M = X.shape
    C = len(classNames)
    
    
    # Number of rounds of bagging
    L = 10
    
    # Fit model using random tree classifier:
    rf_classifier = RandomForestClassifier(L)
    rf_classifier.fit(X, y)
    y_est = rf_classifier.predict(X).T
    y_est_prob = rf_classifier.predict_proba(X).T
    
    # Compute classification error
    ErrorRate = (y!=y_est).sum(dtype=float)/N
    print('Error rate: {:.2f}%'.format(ErrorRate*100))    
    
    # Plot decision boundaries    
    figure(1); dbprobplot(rf_classifier, X, y, 'auto', resolution=400)
    figure(2); dbplot(rf_classifier, X, y, 'auto', resolution=400)
    
    show()
    
    print('Ran Exercise 9.1.3')