This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import rusty_machine for linear regression | |
// as well as rust_machine Matrix and Vector as we need them for input | |
use rusty_machine; | |
use rusty_machine::linalg::Matrix; // surprise, Matrix is in linear algebra | |
use rusty_machine::linalg::BaseMatrix; // implement traits for matrix | |
use rusty_machine::linalg::Vector; | |
use rusty_machine::learning::lin_reg::LinRegressor; | |
use rusty_machine::learning::SupModel; // this is extremelly important | |
// as this implement the traits to user predict and train | |
//use smartcore::metrics::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Read input data | |
let ifile = "FULLPATHTODATASET"; | |
let mut input_data = read_housing_csv(&ifile); | |
// data preprocessing: train test split | |
// define the length of the test data | |
let test_chunk_size: f64 = input_data.len() as f64 * 0.3; // we are taking the 30% as test data | |
// as cast between types | |
let test_chunk_size = test_chunk_size.round() as usize; | |
// split |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MODEL! | |
let mut linearRegression = LinRegressor::default(); | |
// train | |
linearRegression.train(&x_train_matrix, &y_train_vector); | |
// predictions | |
let preds = linearRegression.predict(&x_test_matrix).unwrap(); | |
// convert to matrix both preds and y_test | |
let preds_matrix = Matrix::new(test_size, 1, preds); | |
let y_preds_matrix = Matrix::new(test_size, 1, y_test); | |
// compute the mse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::vec::Vec; | |
use std::env::args; | |
mod linear_regression; | |
fn main() { | |
println!("Hello, world!"); | |
linear_regression::run(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn read_housing_csv(filename: impl AsRef<Path>) -> Vec<HousingDataset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_space(): | |
r""" Function to create the search space""" | |
nodes = [8, 16, 32, 64, 128, 256, 512] | |
activations = ['relu', 'softmax', 'softplus', 'tanh', 'selu', 'sigmoid'] | |
# build models | |
known_models = [tf.keras.layers.LSTM, | |
tf.keras.layer.GRU, | |
tf.keras.layer.Bidirectional] | |
for i in range(len(nodes)): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search_strategy(): | |
r""" Function to combine search space bits together | |
and create a new model""" | |
# retrieve the output from search space | |
space_output = search_space() | |
# from here use a suitable technique to retrieve new models | |
models = MonteCarloSearchTree(space_output) | |
# alternatively we could build something like | |
model = Sequential() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "polars_learning" | |
version = "0.1.0" | |
authors = ["Steboss89"] | |
edition = "2018" | |
[dependencies] | |
polars = "0.14.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use polars::prelude::*;//{CsvReader, DataType, Field, Result as PolarResult, Schema, DataFrame,}; | |
use polars::prelude::{Result as PolarResult}; | |
use polars::frame::DataFrame; | |
use std::fs::File; | |
use std::path::{Path}; | |
// an eye on traits: | |
use polars::prelude::SerReader; | |
// If we don't import this one we might get the error CsvReader::new(file) new function not found in CsvReader | |
pub fn read_csv<P: AsRef<Path>>(path: P) -> PolarResult<DataFrame> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn deal_with_shape<P: AsRef<Path>>(path: P) -> () { | |
/* Example function to retrieve shape info from a dataframe */ | |
let df = read_csv(&path).unwrap(); | |
// shape | |
// reming {:#?} otherwise error ^^^^^ `(usize, usize)` cannot be formatted with the default formatter | |
let shape = df.shape(); | |
println!("{:#?}", shape); | |
// schema | |
println!("{:#?}", df.schema()); | |
// dtypes |