Documentation
¶
Overview ¶
Package linear provides linear regression models.
Index ¶
- type Lasso
- func (l *Lasso) Coef() []float64
- func (l *Lasso) Fit(X *dataframe.DataFrame, y *seriesPkg.Series[any]) error
- func (l *Lasso) Intercept() float64
- func (l *Lasso) NIter() int
- func (l *Lasso) Predict(X *dataframe.DataFrame) (*seriesPkg.Series[any], error)
- func (l *Lasso) Score(X *dataframe.DataFrame, y *seriesPkg.Series[any]) (float64, error)
- type LinearRegression
- func (lr *LinearRegression) Coef() []float64
- func (lr *LinearRegression) Fit(X *dataframe.DataFrame, y *seriesPkg.Series[any]) error
- func (lr *LinearRegression) Intercept() float64
- func (lr *LinearRegression) Predict(X *dataframe.DataFrame) (*seriesPkg.Series[any], error)
- func (lr *LinearRegression) Score(X *dataframe.DataFrame, y *seriesPkg.Series[any]) (float64, error)
- type LogisticRegression
- func (lr *LogisticRegression) Classes() []string
- func (lr *LogisticRegression) Coef() []float64
- func (lr *LogisticRegression) Fit(X *dataframe.DataFrame, y *seriesPkg.Series[any]) error
- func (lr *LogisticRegression) Intercept() float64
- func (lr *LogisticRegression) NIter() int
- func (lr *LogisticRegression) Predict(X *dataframe.DataFrame) (*seriesPkg.Series[any], error)
- func (lr *LogisticRegression) PredictProba(X *dataframe.DataFrame) (*dataframe.DataFrame, error)
- type Ridge
- func (r *Ridge) Coef() []float64
- func (r *Ridge) Fit(X *dataframe.DataFrame, y *seriesPkg.Series[any]) error
- func (r *Ridge) Intercept() float64
- func (r *Ridge) Predict(X *dataframe.DataFrame) (*seriesPkg.Series[any], error)
- func (r *Ridge) Score(X *dataframe.DataFrame, y *seriesPkg.Series[any]) (float64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Lasso ¶
type Lasso struct {
// Alpha is the regularization strength.
// Larger values specify stronger regularization.
Alpha float64
// MaxIter is the maximum number of iterations.
MaxIter int
// Tol is the tolerance for convergence.
Tol float64
// FitIntercept determines whether to calculate the intercept.
FitIntercept bool
// contains filtered or unexported fields
}
Lasso implements Lasso Regression with L1 regularization. Lasso adds a penalty term α * ||w||₁ to the loss function, which encourages sparsity (some coefficients become exactly zero). Uses coordinate descent algorithm for optimization.
type LinearRegression ¶
type LinearRegression struct {
// FitIntercept determines whether to calculate the intercept.
// If false, the data is expected to be centered.
FitIntercept bool
// contains filtered or unexported fields
}
LinearRegression implements Ordinary Least Squares (OLS) regression. Fits a linear model with coefficients w = (w_1, ..., w_p) to minimize the residual sum of squares between the observed targets and the targets predicted by the linear approximation.
func NewLinearRegression ¶
func NewLinearRegression(fitIntercept bool) *LinearRegression
NewLinearRegression creates a new LinearRegression model.
func (*LinearRegression) Coef ¶
func (lr *LinearRegression) Coef() []float64
Coef returns the coefficients of the model.
func (*LinearRegression) Fit ¶
Fit trains the linear regression model on data X with target y. Solves the normal equation: β = (X^T X)^-1 X^T y
func (*LinearRegression) Intercept ¶
func (lr *LinearRegression) Intercept() float64
Intercept returns the intercept of the model.
type LogisticRegression ¶
type LogisticRegression struct {
// Penalty specifies the regularization type: "l1", "l2", or "none"
Penalty string
// C is the inverse of regularization strength (smaller values = stronger regularization)
C float64
// MaxIter is the maximum number of iterations for gradient descent
MaxIter int
// Tol is the tolerance for convergence
Tol float64
// FitIntercept determines whether to calculate the intercept
FitIntercept bool
// LearningRate for gradient descent
LearningRate float64
// contains filtered or unexported fields
}
LogisticRegression implements logistic regression for binary classification. Uses gradient descent with logistic loss function. Supports L1, L2, or no regularization.
func NewLogisticRegression ¶
func NewLogisticRegression(penalty string, C float64, maxIter int) *LogisticRegression
NewLogisticRegression creates a new logistic regression model.
func (*LogisticRegression) Classes ¶
func (lr *LogisticRegression) Classes() []string
Classes returns the class labels.
func (*LogisticRegression) Coef ¶
func (lr *LogisticRegression) Coef() []float64
Coef returns the coefficients.
func (*LogisticRegression) Intercept ¶
func (lr *LogisticRegression) Intercept() float64
Intercept returns the intercept.
func (*LogisticRegression) NIter ¶
func (lr *LogisticRegression) NIter() int
NIter returns the number of iterations performed.
func (*LogisticRegression) PredictProba ¶
PredictProba returns probability estimates for each class.
type Ridge ¶
type Ridge struct {
// Alpha is the regularization strength (λ or α).
// Larger values specify stronger regularization.
// Alpha must be >= 0. When alpha = 0, Ridge is equivalent to LinearRegression.
Alpha float64
// FitIntercept determines whether to calculate the intercept.
FitIntercept bool
// contains filtered or unexported fields
}
Ridge implements Ridge Regression with L2 regularization. Ridge regression adds a penalty term α * ||w||² to the loss function, which helps prevent overfitting by shrinking coefficients. Solves: β = (X^T X + α I)^-1 X^T y