Skip to content

Instantly share code, notes, and snippets.

View Mec-iS's full-sized avatar

Lorenzo Mec-iS

View GitHub Profile
@Steboss89
Steboss89 / linear_regression.rs
Created June 30, 2021 14:56
Linear regression in smartcore
// train split
let (x_train, x_test, y_train, y_test) = train_test_split(&xmatrix.unwrap(), &y, 0.3, true);
// model
let linear_regression = LinearRegression::fit(&x_train, &y_train, Default::default()).unwrap();
// predictions
let preds = linear_regression.predict(&x_test).unwrap();
// metrics
let mse = mean_squared_error(&y_test, &preds);
println!("MSE: {:?}", mse);
let target_array = target.unwrap().to_ndarray::<Float64Type>().unwrap();
// create a vec type and populate with y values
let mut y: Vec<f64> = Vec::new();
for val in target_array.iter(){
y.push(*val);
}
@Steboss89
Steboss89 / array_to_vec.rs
Created June 30, 2021 14:53
Convert an array to a vector
let target_array = target.unwrap().to_ndarray::<Float64Type>().unwrap();
// create a vec type and populate with y values
let mut y: Vec<f64> = Vec::new();
for val in target_array.iter(){
y.push(*val);
}
@Steboss89
Steboss89 / df_to_dm.rs
Created June 30, 2021 14:47
Convert a DataFrame to a DenseMatrix
pub fn convert_features_to_matrix(in_df: &DataFrame) -> Result<DenseMatrix<f64>>{
/* function to convert feature dataframe to a DenseMatrix, readable by smartcore*/
let nrows = in_df.height();
let ncols = in_df.width();
// convert to array
let features_res = in_df.to_ndarray::<Float64Type>().unwrap();
// create a zero matrix and populate with features
let mut Xmatrix: DenseMatrix<f64> = BaseMatrix::zeros(nrows, ncols);
// populate the matrix
@stain
stain / vocabulary-jsonld.json
Last active October 10, 2022 10:54
Example of how a simple OWL ontology / RDFS vocabulary could be defined with JSON-LD, defining the meaning of properties and classes. The second file shows the RDF triples of the vocabulary by using the JSON-LD sandbox. As a visualization - see http://www.essepuntato.it/lode/owlapi/https://gist.github.com/stain/7690362/raw/114f836a64291a3f894c44…
{ "@context": {
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"owl": "http://www.w3.org/2002/07/owl#",
"express": "http://example.com/express#",
"defines": {
"@reverse": "rdfs:isDefinedBy"
},
"propertyOf": {
"@id": "rdfs:domain",
@sloria
sloria / bobp-python.md
Last active May 1, 2024 08:37
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@deltheil
deltheil / msgpack.c
Last active June 7, 2022 21:03
Pack / unpack some structs with C msgpack - see http://stackoverflow.com/a/15405794/1688185
#include <stdio.h>
#include <assert.h>
#include <msgpack.h>
typedef struct some_struct {
uint32_t a;
uint32_t b;
float c;
} some_struct;