Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion algorithms/linfa-bayes/examples/winequality_bayes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() -> Result<()> {
// good | 7 | 10
//
// accuracy 0.8805031, MCC 0.45080978
println!("{:?}", cm);
println!("{cm:?}");
println!("accuracy {}, MCC {}", cm.accuracy(), cm.mcc());

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-bayes/examples/winequality_bernouilli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() -> Result<()> {
// good | 17 | 0

// accuracy 0.8930818, MCC
println!("{:?}", cm);
println!("{cm:?}");
println!("accuracy {}, MCC {}", cm.accuracy(), cm.mcc());

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-bayes/examples/winequality_multinomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() -> Result<()> {
// good | 10 | 7

// accuracy 0.5974843, MCC 0.02000631
println!("{:?}", cm);
println!("{cm:?}");
println!("accuracy {}, MCC {}", cm.accuracy(), cm.mcc());

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-clustering/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ space = "0.12"
thiserror = "1.0"
#partitions = "0.2.4" This one will break in a future version of Rust and has no replacement
linfa = { version = "0.7.1", path = "../.." }
linfa-nn = { version = "0.7.1", path = "../linfa-nn" }
linfa-nn = { version = "0.7.2", path = "../linfa-nn" }
noisy_float = "0.2.0"

[dev-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions algorithms/linfa-clustering/benches/k_means.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn k_means_bench(c: &mut Criterion) {
let mut stats = Stats::default();

benchmark.bench_function(
BenchmarkId::new("naive_k_means", format!("{}x{}", n_clusters, cluster_size)),
BenchmarkId::new("naive_k_means", format!("{n_clusters}x{cluster_size}")),
|bencher| {
bencher.iter(|| {
let m = KMeans::params_with_rng(black_box(n_clusters), black_box(rng.clone()))
Expand Down Expand Up @@ -88,7 +88,7 @@ fn k_means_incr_bench(c: &mut Criterion) {
benchmark.bench_function(
BenchmarkId::new(
"incremental_k_means",
format!("{}x{}", n_clusters, cluster_size),
format!("{n_clusters}x{cluster_size}"),
),
|bencher| {
bencher.iter(|| {
Expand Down Expand Up @@ -140,7 +140,7 @@ fn k_means_init_bench(c: &mut Criterion) {
benchmark.bench_function(
BenchmarkId::new(
"k_means_init",
format!("{:?}:{}x{}", init, n_clusters, cluster_size),
format!("{init:?}:{n_clusters}x{cluster_size}"),
),
|bencher| {
bencher.iter(|| {
Expand Down
6 changes: 3 additions & 3 deletions algorithms/linfa-clustering/examples/dbscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ fn main() {
println!("Result: ");
for (label, count) in label_count {
match label {
None => println!(" - {} noise points", count),
Some(i) => println!(" - {} points in cluster {}", count, i),
None => println!(" - {count} noise points"),
Some(i) => println!(" - {count} points in cluster {i}"),
}
}
println!();

let silhouette_score = cluster_memberships.silhouette_score().unwrap();

println!("Silhouette score: {}", silhouette_score);
println!("Silhouette score: {silhouette_score}");

let (records, cluster_memberships) = (cluster_memberships.records, cluster_memberships.targets);

Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-clustering/examples/optics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn main() {
println!();
println!("Result: ");
for sample in analysis.iter() {
println!("{:?}", sample);
println!("{sample:?}");
}
println!();

Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-elasticnet/examples/elasticnet_cv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() -> Result<()> {
dataset.cross_validate_single(5, &models, |prediction, truth| prediction.r2(&truth))?;

for (ratio, r2) in ratios.iter().zip(r2_values.iter()) {
println!("L1 ratio: {}, r2 score: {}", ratio, r2);
println!("L1 ratio: {ratio}, r2 score: {r2}");
}

Ok(())
Expand Down
8 changes: 4 additions & 4 deletions algorithms/linfa-ensemble/examples/bagging_iris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ fn main() {

// Return highest ranking predictions
let final_predictions_ensemble = model.predict(&test);
println!("Final Predictions: \n{:?}", final_predictions_ensemble);
println!("Final Predictions: \n{final_predictions_ensemble:?}");

let cm = final_predictions_ensemble.confusion_matrix(&test).unwrap();

println!("{:?}", cm);
println!("Test accuracy: {} \n with default Decision Tree params, \n Ensemble Size: {},\n Bootstrap Proportion: {}",
100.0 * cm.accuracy(), ensemble_size, bootstrap_proportion);
println!("{cm:?}");
println!("Test accuracy: {} \n with default Decision Tree params, \n Ensemble Size: {ensemble_size},\n Bootstrap Proportion: {bootstrap_proportion}",
100.0 * cm.accuracy());
}
6 changes: 3 additions & 3 deletions algorithms/linfa-ftrl/benches/ftrl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn fit_without_prior_model(c: &mut Criterion) {
for (nfeatures, nrows) in sizes.iter() {
let dataset = get_dataset(&mut rng, *nrows, *nfeatures);
group.bench_function(
BenchmarkId::new("training on ", format!("dataset {}x{}", nfeatures, nrows)),
BenchmarkId::new("training on ", format!("dataset {nfeatures}x{nrows}")),
|bencher| {
bencher.iter(|| {
params.fit_with(None, black_box(&dataset)).unwrap();
Expand All @@ -46,7 +46,7 @@ fn fit_with_prior_model(c: &mut Criterion) {
let model = Ftrl::new(valid_params.clone(), *nfeatures);
let dataset = get_dataset(&mut rng, *nrows, *nfeatures);
group.bench_function(
BenchmarkId::new("training on ", format!("dataset {}x{}", nfeatures, nrows)),
BenchmarkId::new("training on ", format!("dataset {nfeatures}x{nrows}")),
|bencher| {
bencher.iter(|| {
let _ = params
Expand All @@ -72,7 +72,7 @@ fn predict(c: &mut Criterion) {
let model = Ftrl::new(valid_params.clone(), *nfeatures);
let dataset = get_dataset(&mut rng, *nrows, *nfeatures);
group.bench_function(
BenchmarkId::new("predicting on ", format!("dataset {}x{}", nfeatures, nrows)),
BenchmarkId::new("predicting on ", format!("dataset {nfeatures}x{nrows}")),
|bencher| {
bencher.iter(|| {
model.predict(black_box(&dataset));
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-hierarchical/examples/irisflower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() -> Result<(), Box<dyn Error>> {
_ => unreachable!(),
};

print!("({} {}) ", id, name);
print!("({id} {name}) ");
}
println!();

Expand Down
6 changes: 2 additions & 4 deletions algorithms/linfa-ica/src/fast_ica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
// the number of rows and columns
if ncomponents > nsamples.min(nfeatures) {
return Err(FastIcaError::InvalidValue(format!(
"ncomponents cannot be greater than the min({}, {}), got {}",
nsamples, nfeatures, ncomponents
"ncomponents cannot be greater than the min({nsamples}, {nfeatures}), got {ncomponents}"

Check warning on line 53 in algorithms/linfa-ica/src/fast_ica.rs

View check run for this annotation

Codecov / codecov/patch

algorithms/linfa-ica/src/fast_ica.rs#L53

Added line #L53 was not covered by tests
)));
}

Expand Down Expand Up @@ -252,8 +251,7 @@
//if alpha < 1.0 || alpha > 2.0 {
if !(1.0..=2.0).contains(&alpha) {
return Err(FastIcaError::InvalidValue(format!(
"alpha must be between 1 and 2 inclusive, got {}",
alpha
"alpha must be between 1 and 2 inclusive, got {alpha}"

Check warning on line 254 in algorithms/linfa-ica/src/fast_ica.rs

View check run for this annotation

Codecov / codecov/patch

algorithms/linfa-ica/src/fast_ica.rs#L254

Added line #L254 was not covered by tests
)));
}
let alpha = A::cast(alpha);
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ num-traits = "0.2"
sprs = { version = "=0.11.1", default-features = false }

linfa = { version = "0.7.1", path = "../.." }
linfa-nn = { version = "0.7.1", path = "../linfa-nn" }
linfa-nn = { version = "0.7.2", path = "../linfa-nn" }
2 changes: 1 addition & 1 deletion algorithms/linfa-linear/benches/ols_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn bench(c: &mut Criterion) {
let glm_id = "GLM-".to_string();

for (size, num_feat) in params {
let suffix = format!("{}Feats", num_feat);
let suffix = format!("{num_feat}Feats");
let mut func_name = ols_id.clone();
func_name.push_str(&suffix);

Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-linear/examples/glm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn main() -> Result<(), f64> {
.mapv(|x| x.abs())
.mean();

println!("{:?}", loss);
println!("{loss:?}");

Ok(())
}
2 changes: 1 addition & 1 deletion algorithms/linfa-logistic/examples/logistic_cv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn main() -> Result<()> {

// display the accuracy of the models along with their regularization coefficient
for (alpha, accuracy) in alphas.iter().zip(accuracies.iter()) {
println!("Alpha: {}, accuracy: {} ", alpha, accuracy);
println!("Alpha: {alpha}, accuracy: {accuracy} ");
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-logistic/examples/winequality_logistic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() -> Result<(), Box<dyn Error>> {
// Print the confusion matrix, this will print a table with four entries. On the diagonal are
// the number of true-positive and true-negative predictions, off the diagonal are
// false-positive and false-negative
println!("{:?}", cm);
println!("{cm:?}");

// Calculate the accuracy and Matthew Correlation Coefficient (cross-correlation between
// predicted and targets)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() -> Result<(), Box<dyn Error>> {
// Print the confusion matrix, this will print a table with four entries. On the diagonal are
// the number of true-positive and true-negative predictions, off the diagonal are
// false-positive and false-negative
println!("{:?}", cm);
println!("{cm:?}");

// Calculate the accuracy and Matthew Correlation Coefficient (cross-correlation between
// predicted and targets)
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-nn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "linfa-nn"
version = "0.7.1"
version = "0.7.2"
authors = ["YuhanLiin <yuhanliin+github@protonmail.com>"]
edition = "2018"
description = "A collection of nearest neighbour algorithms"
Expand Down
6 changes: 3 additions & 3 deletions algorithms/linfa-nn/benches/nn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn nn_build_bench(c: &mut Criterion) {

for (alg, name) in algorithms {
benchmark.bench_with_input(
BenchmarkId::new(*name, format!("{}", n_points)),
BenchmarkId::new(*name, format!("{n_points}")),
&points_arr,
|bencher, points_arr| {
let points = points_arr.view();
Expand Down Expand Up @@ -56,7 +56,7 @@ fn k_nearest_bench(c: &mut Criterion) {
for (alg, name) in algorithms {
let nn = alg.from_batch(&points, L2Dist).unwrap();
benchmark.bench_with_input(
BenchmarkId::new(*name, format!("{}-{}", n_points, k)),
BenchmarkId::new(*name, format!("{n_points}-{k}")),
&k,
|bencher, &k| {
bencher.iter(|| {
Expand Down Expand Up @@ -91,7 +91,7 @@ fn within_range_bench(c: &mut Criterion) {
for (alg, name) in algorithms {
let nn = alg.from_batch(&points, L2Dist).unwrap();
benchmark.bench_with_input(
BenchmarkId::new(*name, format!("{}-{}", n_points, range)),
BenchmarkId::new(*name, format!("{n_points}-{range}")),
&range,
|bencher, &range| {
bencher.iter(|| {
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-pls/benches/pls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn bench(c: &mut Criterion) {
pls_cca_id.push_str(name);

for (size, num_feat) in params {
let suffix = format!("{}Feats", num_feat);
let suffix = format!("{num_feat}Feats");
let mut func_name = pls_regression_id.clone();
func_name.push_str(&suffix);
let dataset = make_dataset(size, num_feat, 1, feat_distr, target_distr);
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-pls/examples/pls_regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn main() -> Result<()> {
.fit(&ds)?;

println!("True B (such that: Y = XB + noise)");
println!("{:?}", b);
println!("{b:?}");

// PLS regression coefficients is an estimation of B
println!("Estimated B");
Expand Down
9 changes: 5 additions & 4 deletions algorithms/linfa-preprocessing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ features = ["std", "derive"]
linfa-datasets = { version = "0.7.1", path = "../../datasets", features = [
"diabetes",
"winequality",
"generate"
"generate",
] }
linfa-bayes = { version = "0.7.1", path = "../linfa-bayes" }
iai = "0.1"
Expand All @@ -56,9 +56,10 @@ linfa = { version = "0.7.1", path = "../..", features = ["benchmarks"] }
criterion = "0.4.0"
statrs = "0.16.0"

[[bench]]
name = "vectorizer_bench"
harness = false
# FIXME: Disabled as dataset link is broken
# [[bench]]
# name = "vectorizer_bench"
# harness = false

[[bench]]
name = "linear_scaler_bench"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn bench(c: &mut Criterion) {
for nfeatures in (10..100).step_by(10) {
let dataset = make_dataset(size, nfeatures, 1, feat_distr, target_distr);
benchmark.bench_function(
BenchmarkId::new(fn_name, format!("{}x{}", nfeatures, size)),
BenchmarkId::new(fn_name, format!("{nfeatures}x{size}")),
|bencher| {
bencher.iter(|| {
liner_scaler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn bench(c: &mut Criterion) {
for nfeatures in (10..100).step_by(10) {
let dataset = make_dataset(size, nfeatures, 1, feat_distr, target_distr);
benchmark.bench_function(
BenchmarkId::new(fn_name, format!("{}x{}", nfeatures, size)),
BenchmarkId::new(fn_name, format!("{nfeatures}x{size}")),
|bencher| {
bencher.iter(|| {
scaler.transform(black_box(dataset.view()));
Expand Down
2 changes: 1 addition & 1 deletion algorithms/linfa-preprocessing/benches/whitening_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn bench(c: &mut Criterion) {
for nfeatures in (10..100).step_by(10) {
let dataset = make_dataset(size, nfeatures, 1, feat_distr, target_distr);
benchmark.bench_function(
BenchmarkId::new(fn_name, format!("{}x{}", nfeatures, size)),
BenchmarkId::new(fn_name, format!("{nfeatures}x{size}")),
|bencher| {
bencher.iter(|| {
whitener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fn main() {
.unwrap();
// 0.9944
let accuracy = cm.f1_score();
println!("The fitted model has a training f1 score of {}", accuracy);
println!("The fitted model has a training f1 score of {accuracy}");

// --- Test set

Expand All @@ -174,7 +174,7 @@ fn main() {
let cm = test_prediction.confusion_matrix(&test_dataset).unwrap();
// 0.9523
let accuracy = cm.f1_score();
println!("The model has a test f1 score of {}", accuracy);
println!("The model has a test f1 score of {accuracy}");

delete_20news_bydate();
}
7 changes: 2 additions & 5 deletions algorithms/linfa-preprocessing/examples/scaling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ fn main() {
.accuracy();
let cm = model.predict(&valid).confusion_matrix(&valid).unwrap();
let valid_acc = cm.accuracy();
println!(
"Scaled model training and validation accuracies: {} - {}",
train_acc, valid_acc
);
println!("{:?}", cm);
println!("Scaled model training and validation accuracies: {train_acc} - {valid_acc}");
println!("{cm:?}",);
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ fn main() {
.unwrap();
// 0.9994
let accuracy = cm.f1_score();
println!("The fitted model has a training f1 score of {}", accuracy);
println!("The fitted model has a training f1 score of {accuracy}",);

// --- Test set

Expand All @@ -157,9 +157,8 @@ fn main() {
let (test_filenames, test_targets, ntargets) = load_test_set(&desired_targets).unwrap();

println!(
"The test set is comprised of {} documents with {} different targets",
"The test set is comprised of {} documents with {ntargets} different targets",
test_filenames.len(),
ntargets
);
let test_records = vectorizer
.transform_files(&test_filenames, ISO_8859_1, Strict)
Expand All @@ -171,7 +170,7 @@ fn main() {
let cm = test_prediction.confusion_matrix(&test_dataset).unwrap();
// 0.8402
let accuracy = cm.f1_score();
println!("The model has a test f1 score of {}", accuracy);
println!("The model has a test f1 score of {accuracy}");

delete_20news_bydate();
}
7 changes: 2 additions & 5 deletions algorithms/linfa-preprocessing/examples/whitening.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ fn main() {
.accuracy();
let cm = model.predict(&valid).confusion_matrix(&valid).unwrap();
let valid_acc = cm.accuracy();
println!(
"Whitened model training and validation accuracies: {} - {}",
train_acc, valid_acc
);
println!("{:?}", cm);
println!("Whitened model training and validation accuracies: {train_acc} - {valid_acc}");
println!("{cm:?}",);
}
Loading
Loading