Linear Regression

Linear regression is a method to model the connection between a dependent variable, which can be a vector, and one or more explanatory variables. This is done by fitting the linear equations to the observed data.

Operation

Computational methods

Programming Interface

Training

norm_eq

train(…)

train_input

train_result

Inference

norm_eq

infer(…)

infer_input

infer_result

Partial Training

norm_eq

partial_train(…)

partial_train_input

partial_train_result

Finalize Training

norm_eq

finalize_train(…)

partial_train_result

train_result

Mathematical Formulation

Refer to Developer Guide: Linear Regression.

Programming Interface

All types and functions from this section are declared in the oneapi::dal::linear_regression namespace and available by including the oneapi/dal/algo/linear_regression.hpp header file.

Descriptor

template<typename Float = float, typename Method = method::by_default, typename Task = task::by_default>
class descriptor
Template Parameters
  • Float – The floating-point type that the algorithm uses for intermediate computations. Can be float or double.

  • Method – Tag-type that specifies an implementation of algorithm. Can be method::norm_eq.

  • Task – Tag-type that specifies type of the problem to solve. Can be task::regression.

Constructors

descriptor(bool compute_intercept)

Creates a new instance of the class with the given compute_intercept.

descriptor()

Creates a new instance of the class with default parameters.

descriptor(bool compute_intercept, double alpha)
descriptor(double alpha)

Properties

result_option_id result_options

Choose which results should be computed and returned.

Getter & Setter
result_option_id get_result_options() const
auto & set_result_options(const result_option_id &value)
bool compute_intercept

Defines should intercept be taken into consideration.

Getter & Setter
bool get_compute_intercept() const
auto & set_compute_intercept(bool compute_intercept) const
double alpha

Defines regularization term alpha used in Ridge Regression.

Getter & Setter
double get_alpha() const
auto & set_alpha(double value)

Method Tags

struct norm_eq

Tag-type that denotes normal eqution computational method.

using by_default = norm_eq

Task Tags

struct regression

Tag-type that parameterizes entities used for solving regression problem.

using by_default = regression

Alias tag-type for regression task.

Training

Input

template<typename Task = task::by_default>
class train_input
Template Parameters

Task – Tag-type that specifies type of the problem to solve. Can be task::regression.

Constructors

train_input()
train_input(const table &data, const table &responses)

Creates a new instance of the class with the given data and responses property values.

train_input(const table &data)

Properties

const table &data

The training set X. Default value: table{}.

Getter & Setter
const table & get_data() const
auto & set_data(const table &data)
const table &responses

Vector of responses y for the training set X. Default value: table{}.

Getter & Setter
const table & get_responses() const
auto & set_responses(const table &responses)

Result and Finalize Result

template<typename Task = task::by_default>
class train_result
Template Parameters

Task – Tag-type that specifies type of the problem to solve. Can be task::classification or task::search.

Constructors

train_result()

Creates a new instance of the class with the default property values.

Properties

const table &intercept

Table of Linear regression intercept.

Getter & Setter
const table & get_intercept() const
auto & set_intercept(const table &value)
const table &packed_coefficients

Table of Linear regression coefficients with intercept.

Getter & Setter
const table & get_packed_coefficients() const
auto & set_packed_coefficients(const table &value)
const model<Task> &model

The trained Linear Regression model. Default value: model<Task>{}.

Getter & Setter
const model< Task > & get_model() const
auto & set_model(const model< Task > &value)
const result_option_id &result_options

Result options that indicates availability of the properties.

Getter & Setter
const result_option_id & get_result_options() const
auto & set_result_options(const result_option_id &value)
const table &coefficients

Table of Linear regression coefficients.

Getter & Setter
const table & get_coefficients() const
auto & set_coefficients(const table &value)

Partial Training

Partial Input

template<typename Task = task::by_default>
class partial_train_input

Constructors

partial_train_input()
partial_train_input(const table &data)
partial_train_input(const table &data, const table &responses)
partial_train_input(const partial_train_result<Task> &prev, const table &data)
partial_train_input(const partial_train_result<Task> &prev, const table &data, const table &responses)
partial_train_input(const partial_train_result<Task> &prev, const partial_train_input<Task> &input)

Properties

const table &data
Getter & Setter
const table & get_data() const
auto & set_data(const table &value)
const table &responses

Vector of responses y for the training set X. Default value: table{}.

Getter & Setter
const table & get_responses() const
auto & set_responses(const table &responses)
const partial_train_result<Task> &prev
Getter & Setter
const partial_train_result< Task > & get_prev() const
auto & set_prev(const partial_train_result< Task > &value)

Partial Result and Finalize Input

template<typename Task = task::by_default>
class partial_train_result

Constructors

partial_train_result()

Properties

const table &partial_xty

The partial_xty matrix. Default value: table{}.

Getter & Setter
const table & get_partial_xty() const
auto & set_partial_xty(const table &value)
const table &partial_xtx

The partial_xtx matrix. Default value: table{}.

Getter & Setter
const table & get_partial_xtx() const
auto & set_partial_xtx(const table &value)

Finalize Training

Inference

Input

template<typename Task = task::by_default>
class infer_input
Template Parameters

Task – Tag-type that specifies type of the problem to solve. Can be task::classification or task::search.

Constructors

infer_input(const table &data, const model<Task> &model)

Creates a new instance of the class with the given model and data property values.

Properties

const model<Task> &model

The trained k-NN model. Default value: model<Task>{}.

Getter & Setter
const model< Task > & get_model() const
auto & set_model(const model< Task > &m)
const table &data

The dataset for inference \(X'\). Default value: table{}.

Getter & Setter
const table & get_data() const
auto & set_data(const table &data)

Result

template<typename Task = task::by_default>
class infer_result
Template Parameters

Task – Tag-type that specifies type of the problem to solve. Can be task::regression.

Constructors

infer_result()

Creates a new instance of the class with the default property values.

Properties

const table &responses

The predicted responses. Default value: table{}.

Getter & Setter
const table & get_responses() const
auto & set_responses(const table &value)