dmlfw (Daniyal Machine Learning Framework)
dmlfw_model_accuracy_score.h File Reference

Regression model evaluation metrics. More...

#include <dmlfw_vector.h>
#include <dmlfw_error.h>
Include dependency graph for dmlfw_model_accuracy_score.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

double dmlfw_get_r2_score (dmlfw_column_vec_double *target_values_vector, dmlfw_column_vec_double *predicted_values_vector)
 Computes the R2 (coefficient of determination) score for regression.
 

Detailed Description

Regression model evaluation metrics.

Version
1.0
Date
2025-09-25

This header provides functions to evaluate the accuracy of regression models using numerical metrics such as the R2 score (coefficient of determination).

Error Handling:

Functions validate inputs, check vector sizes, allocate necessary temporaries, and set errors on failure. After calling, check dmlfw_error() and use dmlfw_get_error_string() and dmlfw_get_debug_string() for diagnostics.

Ownership:

Input vectors are owned by the caller; temporary allocations are freed internally. Returned scores are scalars.

Function Documentation

◆ dmlfw_get_r2_score()

double dmlfw_get_r2_score ( dmlfw_column_vec_double target_values_vector,
dmlfw_column_vec_double predicted_values_vector 
)

Computes the R2 (coefficient of determination) score for regression.

The R2 score is calculated as:

\[
R^2 = 1 - \frac{\sum_i (y_i - \hat{y}_i)^2}{\sum_i (y_i - \bar{y})^2}
\]

Parameters
target_values_vector[in] Pointer to true target value vector (non-NULL).
predicted_values_vector[in] Pointer to predicted value vector (non-NULL).
Returns
R2 score as double. Returns 0.0 and sets an appropriate error if inputs are invalid or computation fails.
Note
Input vectors must be the same size.
Caller retains ownership of input vectors.

Usage:

dmlfw_column_vec_double *target = ...; // Initialized true values
dmlfw_column_vec_double *predicted = ...;// Initialized predictions
double r2 = dmlfw_get_r2_score(target, predicted);
if (dmlfw_error()) {
char err[512], dbg[512];
dmlfw_get_error_string(err, sizeof(err));
dmlfw_get_debug_string(dbg, sizeof(dbg));
printf("Error computing R2 score: %s\nDebug info: %s\n", err, dbg);
}
printf("R2 score: %lf\n", r2);
void dmlfw_get_error_string(char *error_string, uint32_t size)
Copies the last error message into the provided character buffer.
uint8_t dmlfw_error(void)
Checks if the last framework call resulted in an error.
void dmlfw_get_debug_string(char *debug_string, uint32_t size)
Copies detailed debug information about the last error into the provided character buffer.
double dmlfw_get_r2_score(dmlfw_column_vec_double *target_values_vector, dmlfw_column_vec_double *predicted_values_vector)
Computes the R2 (coefficient of determination) score for regression.
struct __dmlfw_column_vec_double dmlfw_column_vec_double
Opaque structure representing a column vector of doubles.
Definition dmlfw_vec_double.h:83
Examples
example_dmlfw_model_accuracy_score.c.