| <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="The rusty-machine crate."><meta name="keywords" content="rust, rustlang, rust-lang, rusty_machine"><title>rusty_machine - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../normalize.css"><link rel="stylesheet" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../ayu.css" disabled><link rel="stylesheet" href="../dark.css" disabled><link rel="stylesheet" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="../crates.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="sidebar-logo" href="../rusty_machine/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../rusty_machine/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Crate rusty_machine</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 0.5.4</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#modules">Modules</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Crate <a class="mod" href="#">rusty_machine</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/rusty_machine/lib.rs.html#1-233">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><h2 id="the-rusty-machine-crate"><a href="#the-rusty-machine-crate">The rusty-machine crate.</a></h2> |
| <p>A crate built for machine learning that works out-of-the-box.</p> |
| <hr /> |
| <h3 id="structure"><a href="#structure">Structure</a></h3> |
| <p>The crate is made up of two primary modules: learning and linalg.</p> |
| <h4 id="learning"><a href="#learning">learning</a></h4> |
| <p>The learning module contains all of the machine learning modules. |
| This means the algorithms, models and related tools.</p> |
| <p>The currently supported techniques are:</p> |
| <ul> |
| <li>Linear Regression</li> |
| <li>Logistic Regression</li> |
| <li>Generalized Linear Models</li> |
| <li>K-Means Clustering</li> |
| <li>Neural Networks</li> |
| <li>Gaussian Process Regression</li> |
| <li>Support Vector Machines</li> |
| <li>Gaussian Mixture Models</li> |
| <li>Naive Bayes Classifiers</li> |
| <li>DBSCAN</li> |
| <li>k-Nearest Neighbor Classifiers</li> |
| <li>Principal Component Analysis</li> |
| </ul> |
| <h4 id="linalg"><a href="#linalg">linalg</a></h4> |
| <p>The linalg module reexports some structs and traits from the |
| <a href="https://crates.io/crates/rulinalg">rulinalg</a> crate. This is to provide |
| easy access to common linear algebra tools within this library.</p> |
| <hr /> |
| <h3 id="usage"><a href="#usage">Usage</a></h3> |
| <p>Specific usage of modules is described within the modules themselves. This section |
| will focus on the general workflow for this library.</p> |
| <p>The models contained within the learning module should implement either |
| <code>SupModel</code> or <code>UnSupModel</code>. These both provide a <code>train</code> and a <code>predict</code> |
| function which provide an interface to the model.</p> |
| <p>You should instantiate the model, with your chosen options and then train using |
| the training data. Followed by predicting with your test data. <em>For now</em> |
| cross-validation, data handling, and many other things are left explicitly |
| to the user.</p> |
| <p>Here is an example usage for Gaussian Process Regression:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rusty_machine::linalg::Matrix; |
| <span class="kw">use </span>rusty_machine::linalg::Vector; |
| <span class="kw">use </span>rusty_machine::learning::gp::GaussianProcess; |
| <span class="kw">use </span>rusty_machine::learning::gp::ConstMean; |
| <span class="kw">use </span>rusty_machine::learning::toolkit::kernel; |
| <span class="kw">use </span>rusty_machine::learning::SupModel; |
| |
| <span class="comment">// First we'll get some data. |
| |
| // Some example training data. |
| </span><span class="kw">let </span>inputs = Matrix::new(<span class="number">3</span>,<span class="number">3</span>,<span class="macro">vec!</span>[<span class="number">1.</span>,<span class="number">1.</span>,<span class="number">1.</span>,<span class="number">2.</span>,<span class="number">2.</span>,<span class="number">2.</span>,<span class="number">3.</span>,<span class="number">3.</span>,<span class="number">3.</span>]); |
| <span class="kw">let </span>targets = Vector::new(<span class="macro">vec!</span>[<span class="number">0.</span>,<span class="number">1.</span>,<span class="number">0.</span>]); |
| |
| <span class="comment">// Some example test data. |
| </span><span class="kw">let </span>test_inputs = Matrix::new(<span class="number">2</span>,<span class="number">3</span>, <span class="macro">vec!</span>[<span class="number">1.5</span>,<span class="number">1.5</span>,<span class="number">1.5</span>,<span class="number">2.5</span>,<span class="number">2.5</span>,<span class="number">2.5</span>]); |
| |
| <span class="comment">// Now we'll set up our model. |
| // This is close to the most complicated a model in rusty-machine gets! |
| |
| // A squared exponential kernel with lengthscale 2, and amplitude 1. |
| </span><span class="kw">let </span>ker = kernel::SquaredExp::new(<span class="number">2.</span>, <span class="number">1.</span>); |
| |
| <span class="comment">// The zero function |
| </span><span class="kw">let </span>zero_mean = ConstMean::default(); |
| |
| <span class="comment">// Construct a GP with the specified kernel, mean, and a noise of 0.5. |
| </span><span class="kw">let </span><span class="kw-2">mut </span>gp = GaussianProcess::new(ker, zero_mean, <span class="number">0.5</span>); |
| |
| |
| <span class="comment">// Now we can train and predict from the model. |
| |
| // Train the model! |
| </span>gp.train(<span class="kw-2">&</span>inputs, <span class="kw-2">&</span>targets).unwrap(); |
| |
| <span class="comment">// Predict the output from test data. |
| </span><span class="kw">let </span>outputs = gp.predict(<span class="kw-2">&</span>test_inputs).unwrap();</code></pre></div> |
| <p>This code could have been a lot simpler if we had simply adopted |
| <code>let mut gp = GaussianProcess::default();</code>. Conversely, you could also implement |
| your own kernels and mean functions by using the appropriate traits.</p> |
| <p>Additionally you’ll notice there’s quite a few <code>use</code> statements at the top of this code. |
| We can remove some of these by utilizing the <code>prelude</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rusty_machine::prelude::<span class="kw-2">*</span>; |
| |
| <span class="kw">let _ </span>= Matrix::new(<span class="number">2</span>,<span class="number">2</span>,<span class="macro">vec!</span>[<span class="number">2.0</span>;<span class="number">4</span>]);</code></pre></div> |
| </div></details><h2 id="modules" class="small-section-header"><a href="#modules">Modules</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="mod" href="analysis/index.html" title="rusty_machine::analysis mod">analysis</a></div><div class="item-right docblock-short">Module for evaluating models.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="data/index.html" title="rusty_machine::data mod">data</a></div><div class="item-right docblock-short">Module for data handling</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="learning/index.html" title="rusty_machine::learning mod">learning</a></div><div class="item-right docblock-short">Module for machine learning.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="linalg/index.html" title="rusty_machine::linalg mod">linalg</a></div><div class="item-right docblock-short">The linear algebra module</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="prelude/index.html" title="rusty_machine::prelude mod">prelude</a></div><div class="item-right docblock-short">The rusty-machine prelude.</div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="rusty_machine" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html> |