### Activate and Instantiate Julia Packages Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/boston.ipynb Activates the current Julia project environment and installs necessary packages. This is a standard setup step for Julia projects using Pkg. ```julia using Pkg Pkg.activate(@__DIR__) Pkg.instantiate() ``` -------------------------------- ### Julia Package Management Setup Source: https://github.com/fluxml/mljflux.jl/blob/dev/examples/iris/iris.ipynb Activates the current Julia project environment and installs necessary packages. This is a standard setup step for Julia projects. ```julia using Pkg Pkg.activate(@__DIR__) Pkg.instantiate() ``` -------------------------------- ### Install Dependencies Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/early_stopping/notebook.unexecuted.ipynb Activates the current directory as a Julia environment and installs necessary packages. This is a standard setup step for Julia projects. ```julia using Pkg Pkg.activate(@__DIR__); Pkg.instantiate(); ``` -------------------------------- ### Setup Julia Environment Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/extended_examples/MNIST/notebook.unexecuted.ipynb Installs and activates the necessary Julia packages for the MLJFlux MNIST tutorial. ```julia using Pkg const DIR = @__DIR__ Pkg.activate(DIR) Pkg.instantiate() ``` -------------------------------- ### Setup Julia Environment Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/extended_examples/MNIST/notebook.ipynb Installs and activates the necessary Julia packages for the MLJFlux MNIST tutorial. ```julia using Pkg const DIR = @__DIR__ Pkg.activate(DIR) Pkg.instantiate() ``` -------------------------------- ### Setup Project Environment Source: https://github.com/fluxml/mljflux.jl/blob/dev/examples/iris/iris.md Activates the current Julia project environment and instantiates all necessary packages defined in the Project.toml. ```Julia using Pkg Pkg.activate(@__DIR__) Pkg.instantiate() ``` -------------------------------- ### Install Dependencies Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/early_stopping/notebook.ipynb Activates the current directory as a Julia environment and installs necessary packages. This is a standard setup step for Julia projects. ```julia using Pkg Pkg.activate(@__DIR__); Pkg.instantiate(); ``` -------------------------------- ### Julia Package Setup Source: https://github.com/fluxml/mljflux.jl/blob/dev/examples/mnist/notebook.unexecuted.ipynb Sets up the Julia package environment by activating the current directory and instantiating dependencies. This ensures all required packages are installed and configured. ```julia using Pkg const DIR = @__DIR__ Pkg.activate(DIR) Pkg.instantiate() ``` -------------------------------- ### Activate and Instantiate Julia Packages Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/hyperparameter_tuning/notebook.unexecuted.ipynb Activates the current Julia project environment and instantiates all necessary packages. This is a standard setup step for Julia projects. ```julia using Pkg Pkg.activate(@__DIR__); Pkg.instantiate(); ``` -------------------------------- ### Julia Package Setup Source: https://github.com/fluxml/mljflux.jl/blob/dev/examples/mnist/notebook.ipynb Sets up the Julia package environment by activating the current directory and instantiating dependencies. This ensures all required packages are installed and configured. ```julia using Pkg const DIR = @__DIR__ Pkg.activate(DIR) Pkg.instantiate() ``` -------------------------------- ### Setup MLJFlux Project Dependencies Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/entity_embeddings/notebook.unexecuted.ipynb Activates the current Julia project environment and installs necessary packages using Pkg. This is a standard setup step for Julia projects to ensure all required libraries are available. ```julia using Pkg Pkg.activate(@__DIR__); Pkg.instantiate(); ``` -------------------------------- ### Activate and Instantiate Julia Environment Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/incremental_training/notebook.unexecuted.ipynb Sets up the Julia environment by activating the current project and installing required packages. This ensures all dependencies are met before running the MLJFlux workflow. ```julia using Pkg Pkg.activate(@__DIR__); Pkg.instantiate(); ``` -------------------------------- ### Julia Package Management Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/comparison/notebook.unexecuted.ipynb Activates the current Julia environment and instantiates project dependencies. This is a standard setup for Julia projects. ```julia using Pkg Pkg.activate(@__DIR__); Pkg.instantiate(); ``` -------------------------------- ### Julia Package Management Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/comparison/notebook.ipynb Activates the current Julia environment and instantiates project dependencies. This is a standard setup for Julia projects. ```julia using Pkg Pkg.activate(@__DIR__); Pkg.instantiate(); ``` -------------------------------- ### Activate and Instantiate Julia Environment Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/incremental_training/notebook.ipynb Sets up the Julia environment by activating the current project and installing required packages. This ensures all dependencies are met before running the MLJFlux workflow. ```julia using Pkg Pkg.activate(@__DIR__); Pkg.instantiate(); ``` -------------------------------- ### Activate and Instantiate Julia Packages Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/live_training/notebook.unexecuted.ipynb Activates the current Julia project environment and instantiates the necessary packages. This is a standard setup step for Julia projects to ensure all dependencies are met. ```julia using Pkg Pkg.activate(@__DIR__); Pkg.instantiate(); ``` -------------------------------- ### Activate and Instantiate Julia Packages Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/hyperparameter_tuning/notebook.ipynb Activates the current Julia project environment and instantiates all necessary packages. This is a standard setup step for Julia projects. ```julia using Pkg Pkg.activate(@__DIR__); Pkg.instantiate(); ``` -------------------------------- ### Import MLJFlux and Dependencies Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/boston.ipynb Imports core libraries for machine learning in Julia, including MLJ, Flux, MLJFlux, and CategoricalArrays. These are essential for building and training models. ```julia using MLJ import Flux using MLJFlux using CategoricalArrays ``` -------------------------------- ### Plotting Setup Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/extended_examples/MNIST/notebook.md Configures the plotting backend to GR and sets the plot size for visualizations. ```julia using Plots gr(size=(600, 300*(sqrt(5)-1))); nothing #hide ``` -------------------------------- ### Activate and Instantiate Julia Project Source: https://github.com/fluxml/mljflux.jl/blob/dev/examples/boston/notebook.ipynb Activates the current Julia project directory and instantiates its dependencies using Pkg. This is a standard setup for Julia projects to manage packages. ```julia using Pkg Pkg.activate(@__DIR__) Pkg.instantiate() ``` -------------------------------- ### Activate and Instantiate Julia Project Source: https://github.com/fluxml/mljflux.jl/blob/dev/examples/boston/notebook.unexecuted.ipynb Activates the current Julia project directory and instantiates its dependencies using Pkg. This is a standard setup for Julia projects to manage packages. ```julia using Pkg Pkg.activate(@__DIR__) Pkg.instantiate() ``` -------------------------------- ### Activate and Instantiate Julia Environment Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/architecture_search/notebook.unexecuted.ipynb Activates the current Julia project directory and instantiates the project dependencies. This is a standard setup step for Julia projects to ensure all required packages are available. ```Julia using Pkg Pkg.activate(@__DIR__); Pkg.instantiate(); ``` -------------------------------- ### Import Flux Library Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/entity_embeddings_demo.ipynb Imports the Flux.jl library, a powerful and flexible deep learning framework for Julia. It provides the building blocks for constructing neural network architectures. ```Julia using Flux ``` -------------------------------- ### Create and Fit Machine Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/mnist.ipynb Creates an MLJ `machine` that links the configured `model` with a subset of the training data. The `fit!` function then trains this machine on the provided data. ```julia mach = machine(model, train_imgs[1:10], train_labels[1:10]); fit!(mach) ``` -------------------------------- ### Activate and Instantiate Julia Environment Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/architecture_search/notebook.ipynb Activates the current Julia project directory and instantiates the project dependencies. This is a standard setup step for Julia projects to ensure all required packages are available. ```Julia using Pkg Pkg.activate(@__DIR__); Pkg.instantiate(); ``` -------------------------------- ### Update Epochs and Refit Again Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/mnist.ipynb Further illustrates model retraining by increasing the number of epochs to 4 and refitting the machine. This shows how to adjust training parameters and re-apply them. ```julia model.n = 4 fit!(mach) ``` -------------------------------- ### Create Machine Learning Model Instance Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/entity_embeddings_demo.ipynb Constructs a `machine` object using the defined `nnreg` regressor and the input data `x` and target `y`. This prepares the model for training within the MLJ framework. ```Julia mach= machine(nnreg, x, vec(y)) ``` -------------------------------- ### Fit the Machine Learning Model Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/entity_embeddings_demo.ipynb Trains the machine learning model represented by `mach` using the provided data. The `verbosity=2` argument enables detailed output during the fitting process. ```Julia fit!(mach, verbosity=2) ``` -------------------------------- ### Quick Start: Neural Network Classification Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/index.md Demonstrates a typical workflow using MLJFlux for classification. It involves loading data, instantiating a NeuralNetworkClassifier with a specified MLP builder and optimiser, wrapping it in an MLJ machine, and evaluating its performance using cross-validation and accuracy. ```Julia using MLJ, Flux, MLJFlux import RDatasets import Optimisers # 1. Load Data iris = RDatasets.dataset("datasets", "iris"); y, X = unpack(iris, ==(:Species), colname -> true, rng=123); # 2. Load and instantiate model NeuralNetworkClassifier = @load NeuralNetworkClassifier pkg="MLJFlux" clf = NeuralNetworkClassifier( builder=MLJFlux.MLP(; hidden=(5,4), σ=Flux.relu), optimiser=Optimisers.Adam(0.01), batch_size=8, epochs=100, acceleration=CUDALibs() # For GPU support ) # 3. Wrap it in a machine mach = machine(clf, X, y) # 4. Evaluate the model cv=CV(nfolds=5) evaluate!(mach, resampling=cv, measure=accuracy) ``` -------------------------------- ### Fit Custom Neural Network Model Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/boston.ipynb Fits the MLJ machine for the custom neural network, training the model on the data. `verbosity=2` provides detailed output during the fitting process. ```julia fit!(mymach, verbosity=2) ``` -------------------------------- ### Plot Learning Curve Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/boston.ipynb Plots the generated learning curve using the Plots.jl package. It visualizes model performance (measurements) against parameter values, with custom axis labels. ```julia using Plots pyplot() plot(curve.parameter_values, curve.measurements, xlab=curve.parameter_name) ``` -------------------------------- ### Setup and Data Loading Source: https://github.com/fluxml/mljflux.jl/blob/dev/README.md Imports necessary MLJFlux and related packages, then loads and prepares the Iris dataset. Features are converted to Float32 for potential GPU optimization. ```julia using MLJ, MLJFlux, RDatasets, Plots iris = RDatasets.dataset("datasets", "iris"); y, X = unpack(iris, ==(:Species), rng=123); X = Float32.(X); # To optmise for GPUs ``` -------------------------------- ### Load Boston Dataset Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/boston.ipynb Loads the Boston housing dataset using MLJ's data loading capabilities. It returns the data as a task object, from which features (X_) and target (y_) are extracted. ```julia task = load_boston() X_, y_ = task() ``` -------------------------------- ### Import MLJFlux and Flux Packages Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/mnist.ipynb Imports essential Julia packages for machine learning, including Flux for neural networks, MLJFlux for integration, and MLJBase for general ML operations. These packages provide the foundation for building and training models. ```julia using Flux using Flux.Data.MNIST using MLJFlux using CategoricalArrays using MLJBase using MLJ ``` -------------------------------- ### Generate Learning Curve Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/boston.ipynb Generates a learning curve for the neural network model by evaluating performance across a range of a specified parameter (`n`). It uses MLJ's `learning_curve!` function. ```julia # learning curves: nn = machine(nnmodel, X, y) r = range(nnmodel, :n, lower=1, upper=50) curve = learning_curve!(nn, nested_range=(n=r,), n=4) ``` -------------------------------- ### Import MLJFlux and MLJ Libraries Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/entity_embeddings_demo.ipynb Imports the core MLJFlux and MLJ libraries, which are essential for machine learning tasks in Julia. MLJ provides a unified interface for various models, while MLJFlux integrates Flux.jl for deep learning. ```Julia using MLJFlux using MLJ ``` -------------------------------- ### Setup IteratedModel with Live Plotting Callback in Julia Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/live_training/notebook.md Sets up an IteratedModel for live training, defining stop conditions, validation measures, and a callback function to plot validation losses in real-time. This allows monitoring training progress visually. ```Julia stop_conditions = [ Step(1), # Repeatedly train for one iteration NumberLimit(100), # Don't train for more than 100 iterations ] validation_losses = [] gr(reuse=true) # use the same window for plots function plot_loss(loss) push!(validation_losses, loss) display(plot(validation_losses, label="validation loss", xlim=(1, 100))) sleep(.01) # to catch up with the plots while they are being generated end callbacks = [ WithLossDo(plot_loss,)] iterated_model = IteratedModel( model=clf, resampling=Holdout(), measures=log_loss, iteration_parameter=:(epochs), controls=vcat(stop_conditions, callbacks), retrain=true, ) ``` -------------------------------- ### Load MNIST Dataset Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/mnist.ipynb Loads the MNIST handwritten digit dataset, preparing training images and labels. The images are loaded as a `CategoricalArray` of grayscale pixel data, ready for input into a neural network. ```julia train_labels, train_imgs = CategoricalArray(MNIST.labels()), MNIST.images(); ``` -------------------------------- ### Instantiate and Configure Model Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/mnist.ipynb Creates an instance of the `ImageClassifier` model using the custom `densenet` builder. It specifies the builder, optimizer (ADAM), loss function (MSE), and an initial number of epochs (`n`). ```julia builder = densenet(25, 20) model = ImageClassifier(builder=builder, optimiser = ADAM(0.0003), loss=Flux.mse, n=1) ``` -------------------------------- ### Install MLJFlux and Dependencies Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/index.md Installs the MLJ, MLJFlux, Optimisers, and Flux Julia packages using the Pkg manager. It highlights that Optimisers.jl is now required for optimisers, replacing native Flux.jl optimisers since MLJFlux v0.5. ```Julia import Pkg Pkg.activate("my_environment", shared=true) Pkg.add(["MLJ", "MLJFlux", "Optimisers", "Flux"]) ``` -------------------------------- ### Generate Network Space Example Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/architecture_search/notebook.md Generates an array of possible neural network architectures using the `generate_networks` function. This example creates networks with three hidden layers, where each layer can have between 1 and 64 neurons, with increments of 4 neurons. It then displays the first 5 generated network configurations. ```Julia networks_space = generate_networks( min_neurons = 1, max_neurons = 64, neuron_step = 4, num_layers = 3, ) networks_space[1:5] ``` -------------------------------- ### Standardize Input Features (X) Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/boston.ipynb Applies standardization to the input features `X_` using MLJ's `Standardizer`. This preprocesses the features for model training. ```julia stand_model = Standardizer() stand = machine(stand_model, X_) fit!(stand) X = transform(stand, X_) ``` -------------------------------- ### Standardize Target Variable (y) Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/boston.ipynb Applies univariate standardization to the target variable `y_` using MLJ's `UnivariateStandardizer`. This preprocesses the target for model training. ```julia ustand_model = UnivariateStandardizer() ustand = machine(ustand_model, y_) fit!(ustand) y = transform(ustand, y_) ``` -------------------------------- ### Create MLJ Machine for Custom NN Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/boston.ipynb Creates an MLJ `machine` object for the custom neural network model (`nnmodel`) using the preprocessed data (`X`, `y`). ```julia mymach = machine(nnmodel, X, y) ``` -------------------------------- ### Activate and Instantiate Julia Environment Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/composition/notebook.ipynb Sets up the Julia environment by activating the current directory and instantiating the project's dependencies. This is a standard practice for managing Julia packages in a project. ```julia using Pkg Pkg.activate(@__DIR__); Pkg.instantiate(); ``` -------------------------------- ### Update NN Parameter and Refit Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/boston.ipynb Modifies a parameter (`n`) of the neural network model and then refits the machine. This is useful for hyperparameter tuning or re-training with updated configurations. ```julia nnmodel.n = 20 fit!(mach, verbosity=2) ``` -------------------------------- ### Activate and Instantiate Julia Environment Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/composition/notebook.unexecuted.ipynb Sets up the Julia environment by activating the current directory and instantiating the project's dependencies. This is a standard practice for managing Julia packages in a project. ```julia using Pkg Pkg.activate(@__DIR__); Pkg.instantiate(); ``` -------------------------------- ### Basic MLJFlux Imports Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/live_training/notebook.unexecuted.ipynb Imports core libraries required for MLJFlux, including MLJ for machine learning tasks, Flux for neural networks, RDatasets for data loading, and Optimisers for optimization algorithms. ```julia using MLJ using Flux import RDatasets import Optimisers ``` -------------------------------- ### Implement Custom NN with MLJFlux Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/boston.ipynb Creates a `NeuralNetworkRegressor` using the custom `mynn` builder and a specified Flux optimizer. This allows for flexible neural network architecture definition. ```julia optimiser = Flux.Momentum(0.00003) builder = mynn(3, 4) nnmodel = NeuralNetworkRegressor(builder=builder, optimiser=optimiser) ``` -------------------------------- ### Fit Neural Network Model Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/boston.ipynb Fits the MLJ machine, training the neural network model on the provided data. The `verbosity` parameter controls the amount of output during training. ```julia fit!(mach, verbosity=2) ``` -------------------------------- ### Load MLJFlux and Supporting Julia Libraries Source: https://github.com/fluxml/mljflux.jl/blob/dev/examples/boston/notebook.unexecuted.ipynb Loads necessary libraries for machine learning with MLJFlux, including MLJ itself, Flux for neural networks, and Plots for visualization. These are essential for building and evaluating the model. ```julia using MLJ using MLJFlux using Flux using Plots ``` -------------------------------- ### Fit Machine with Pipeline and Verbose Output Source: https://github.com/fluxml/mljflux.jl/blob/dev/examples/boston/notebook.unexecuted.ipynb Creates a machine learning pipeline and fits it to the training data (X, y). Verbosity level 2 is set to display training losses during the fitting process. ```julia mach = machine(pipe, X, y) fit!(mach, verbosity=2) ``` -------------------------------- ### Load MLJFlux and Supporting Julia Libraries Source: https://github.com/fluxml/mljflux.jl/blob/dev/examples/boston/notebook.ipynb Loads necessary libraries for machine learning with MLJFlux, including MLJ itself, Flux for neural networks, and Plots for visualization. These are essential for building and evaluating the model. ```julia using MLJ using MLJFlux using Flux using Plots ``` -------------------------------- ### Basic Julia Imports for MLJFlux Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/live_training/notebook.md Imports core machine learning libraries including MLJ, Flux, RDatasets for data loading, and Optimisers for model optimization. These are fundamental for setting up ML workflows. ```Julia using MLJ using Flux import RDatasets import Optimisers ``` -------------------------------- ### Define Target Data Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/entity_embeddings_demo.ipynb Generates a vector `y` of 10 random floating-point numbers. This vector serves as the target variable for the regression task, corresponding to the input features defined in `x`. ```Julia y = rand(10,) ``` -------------------------------- ### Import CategoricalArrays Library Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/entity_embeddings_demo.ipynb Imports the CategoricalArrays library, enabling efficient handling of categorical data. This is often a prerequisite for preparing datasets with non-numeric features for machine learning models. ```Julia using CategoricalArrays ``` -------------------------------- ### Fit Machine with Pipeline and Verbose Output Source: https://github.com/fluxml/mljflux.jl/blob/dev/examples/boston/notebook.ipynb Creates a machine learning pipeline and fits it to the training data (X, y). Verbosity level 2 is set to display training losses during the fitting process. ```julia mach = machine(pipe, X, y) fit!(mach, verbosity=2) ``` -------------------------------- ### Define Custom Neural Network Builder Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/boston.ipynb Defines a custom neural network builder struct `mynn` that inherits from `MLJFlux.Builder`. It specifies the network architecture by defining its `fit` method. ```julia struct mynn <: MLJFlux.Builder d1 d2 end function MLJFlux.fit(nn::mynn, a, b) return Flux.Chain(Flux.Dense(a, nn.d1), Flux.Dense(nn.d1, nn.d2), Flux.Dense(nn.d2, b)) end ``` -------------------------------- ### Create MLJ Machine for NN Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/boston.ipynb Creates an MLJ `machine` object that links the defined neural network model (`nnmodel`) with the preprocessed input features (`X`) and target variable (`y`). ```julia mach = machine(nnmodel, X, y) ``` -------------------------------- ### Implement MLJFlux Short Neural Network Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/boston.ipynb Configures and creates a `NeuralNetworkRegressor` using MLJFlux's built-in `Short` builder and a Flux optimizer. It specifies an entity embedding choice. ```julia builder = MLJFlux.Short() optimiser = Flux.Momentum(0.003) nnmodel = NeuralNetworkRegressor(builder=builder, optimiser=optimiser, embedding_choice=:entity_embedding) ``` -------------------------------- ### Compare Learning Rates Source: https://github.com/fluxml/mljflux.jl/blob/dev/examples/boston/notebook.ipynb Iterates through a list of learning rates, fitting the model with each rate and plotting the resulting training losses. This helps in selecting an optimal learning rate for the model. ```julia plt = plot() rates = [5e-5, 1e-4, 0.005, 0.001, 0.05] foreach(rates) do η pipe.transformed_target_model_deterministic.model.optimiser.eta = η fit!(mach, force=true, verbosity=0) losses = report(mach).transformed_target_model_deterministic.model.training_losses[3:end] plot!(1:length(losses), losses, label=η) end plt ``` -------------------------------- ### Instantiate Other ML Models Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/comparison/notebook.unexecuted.ipynb Loads and instantiates three other classical machine learning models: BayesianLDA from MultivariateStats, RandomForestClassifier from DecisionTree, and XGBoostClassifier from XGBoost. ```julia BayesianLDA = @load BayesianLDA pkg=MultivariateStats clf2 = BayesianLDA() RandomForestClassifier = @load RandomForestClassifier pkg=DecisionTree clf3 = RandomForestClassifier() XGBoostClassifier = @load XGBoostClassifier pkg=XGBoost clf4 = XGBoostClassifier(); ``` -------------------------------- ### Compare Learning Rates Source: https://github.com/fluxml/mljflux.jl/blob/dev/examples/boston/notebook.unexecuted.ipynb Iterates through a list of learning rates, fitting the model with each rate and plotting the resulting training losses. This helps in selecting an optimal learning rate for the model. ```julia plt = plot() rates = [5e-5, 1e-4, 0.005, 0.001, 0.05] foreach(rates) do η pipe.transformed_target_model_deterministic.model.optimiser.eta = η fit!(mach, force=true, verbosity=0) losses = report(mach).transformed_target_model_deterministic.model.training_losses[3:end] plot!(1:length(losses), losses, label=η) end plt ``` -------------------------------- ### Evaluate Model Performance Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/mnist.ipynb Evaluates the performance of the trained machine using the `evaluate!` function. This typically involves cross-validation or a hold-out set to assess generalization capabilities. ```julia evaluate!(mach) ``` -------------------------------- ### Import MLJ, Flux, RDatasets, DataFrames, Optimisers (Julia) Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/comparison/notebook.md Imports essential Julia libraries for machine learning workflows. Includes MLJ for model management, Flux for neural networks, RDatasets for data loading, DataFrames for data manipulation, and Optimisers for model training. These are foundational for the subsequent steps. ```Julia using MLJ # Has MLJFlux models using Flux # For more flexibility import RDatasets # Dataset source using DataFrames # To visualize hyperparameter search results import Optimisers # native Flux.jl optimisers no longer supported ``` -------------------------------- ### Basic Julia Imports for MLJFlux Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/comparison/notebook.unexecuted.ipynb Imports necessary libraries for machine learning workflows with MLJFlux, including MLJ for models, Flux for flexibility, RDatasets for data, DataFrames for results visualization, and Optimisers for native optimizers. ```julia using MLJ using Flux import RDatasets using DataFrames import Optimisers ``` -------------------------------- ### Access MNIST Image Data Source: https://github.com/fluxml/mljflux.jl/blob/dev/old_examples/mnist.ipynb Demonstrates how to access individual images from the loaded MNIST dataset. This snippet shows retrieving the first image for inspection or preprocessing. ```julia train_imgs[1] ``` -------------------------------- ### Basic Julia Imports for MLJFlux Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/common_workflows/comparison/notebook.ipynb Imports necessary libraries for machine learning workflows with MLJFlux, including MLJ for models, Flux for flexibility, RDatasets for data, DataFrames for results visualization, and Optimisers for native optimizers. ```julia using MLJ using Flux import RDatasets using DataFrames import Optimisers ``` -------------------------------- ### Load MLJ, Flux, and Plotting Libraries Source: https://github.com/fluxml/mljflux.jl/blob/dev/examples/iris/iris.ipynb Loads essential Julia libraries for machine learning (MLJ, Flux), data loading (RDatasets), random number generation, and plotting. Sets up the plotting backend. ```julia using MLJ using Flux import RDatasets using Random Random.seed!(123) MLJ.color_off() using Plots pyplot(size=(600, 300*(sqrt(5)-1))); ``` -------------------------------- ### Restarting Training with Modified Controls Source: https://github.com/fluxml/mljflux.jl/blob/dev/docs/src/extended_examples/MNIST/notebook.unexecuted.ipynb Shows how to restart training by modifying the iteration controls of an existing `IteratedModel`. This example changes the patience criterion and retrains the model. ```julia iterated_clf.controls[2] = Patience(4) fit!(mach, rows=train) plot( epochs, losses, xlab = "epoch", ylab = "cross entropy", label="out-of-sample", ) plot!(epochs, training_losses, label="training") ``` -------------------------------- ### Plot Training Traces (Python) Source: https://github.com/fluxml/mljflux.jl/blob/dev/examples/boston/notebook.unexecuted.ipynb Generates and displays plots of the training and out-of-sample losses against epochs. It uses `scatter!` to overlay the training losses on the out-of-sample losses and saves the plot to 'assets/loss.png'. ```python plot(epochs, losses, xlab = "epoch", ylab = "mean sum of squares error", label="out-of-sample", legend = :topleft); scatter!(twinx(), epochs, training_losses, label="training", color=:red) ``` ```python savefig(joinpath("assets", "loss.png")) ```