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
avg_x = np.mean(X) | |
Xt = [] | |
for i, val in enumerate(X, 0): | |
if i==0: | |
Xt.append(val - avg_x) | |
else: | |
Xt.append(Xt[i-1] + (val - avg_x)) |
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
reader.lines().enumerate() | |
.map(|(numb, line)| line.expect(&format!("Impossible to read line number {}", numb))) | |
.map(|row| read_single_line(row)) | |
.collect() |
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
reader.lines().enumerate() | |
.map(|(numb, line)| line.expect(&format!("Impossible to read line number {}", numb))) | |
.map(|row| read_single_line(row)) | |
.collect() |
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 new(v: Vec<&str>) -> HousingDataset { | |
// note we have declared a new vector of &strings, remember borrowship, which will be a struct HousingDatset | |
// as input we are receiving a string from the csv file. | |
// we are going to decode this as a f64 vector using the unwrap function | |
let unwrapped_text: Vec<f64> = v.iter().map(|r| r.parse().unwrap()).collect(); |
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
[lib] | |
name = "read_csv" | |
path = "src/reader.rs" |
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
struct Person { | |
name: String, // NB there's a comma here | |
surname: String, | |
age: u32 | |
} | |
impl Person{ | |
// method to get the person | |
fn who_are_you(&self){ |
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
struct Person { | |
name: String, // NB there's a comma here | |
surname: String, | |
age: u32 | |
} | |
// notice now we are defining impl METHOD for TYPE | |
impl WhoAreYou for Person { | |
fn who_are_you(&self) -> String{ | |
return format!("Person name is {} surname {} and age {}", self.name, self.surname, self.age); |
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
struct Person { | |
name: String, // NB there's a comma here | |
surname: String, | |
age: u32 | |
} | |
// Define a trait with the functionalities we want to use with a Person | |
trait PersonSpec { | |
fn compute_year_of_birth(&self) -> u32; | |
} |
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
fn main() { | |
let myself = Person{ name: "Stefano".to_string(), | |
surname: "Bosisio".to_string(), | |
age: 32 // not yet :P | |
}; | |
println!("I was born in the {}", myself.compute_year_of_birth()); | |
} |
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 = "rust-regression" | |
version = "0.1.0" | |
authors = ["Steboss89"] | |
edition = "2018" | |
[dependencies] | |
# to get the rusty-machine simply go to crates.io and copy the version you want | |
rusty-machine = "0.5.4" |
OlderNewer