or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

classification.mdclustering.mddata-handling.mddistance.mdevaluation.mdindex.mdpreprocessing.mdprojection.mdregression.mdwidgets.md

regression.mddocs/

0

# Regression Algorithms

1

2

Orange3 provides comprehensive supervised learning algorithms for continuous prediction tasks. All regressors follow the same pattern as classifiers: create a learner, then call it with training data to produce a trained model.

3

4

## Capabilities

5

6

### Linear Models

7

8

Linear regression algorithms with various regularization techniques.

9

10

```python { .api }

11

class LinearRegressionLearner:

12

"""

13

Ordinary least squares linear regression.

14

15

Args:

16

preprocessors: List of preprocessing steps

17

"""

18

def __init__(self, preprocessors=None): ...

19

20

def __call__(self, data):

21

"""Train and return linear regression model."""

22

23

class RidgeRegressionLearner:

24

"""

25

Ridge regression with L2 regularization.

26

27

Args:

28

alpha: Regularization strength

29

fit_intercept: Whether to fit intercept

30

normalize: Whether to normalize features

31

"""

32

def __init__(self, alpha=1.0, fit_intercept=True, normalize=False): ...

33

34

def __call__(self, data):

35

"""Train and return ridge regression model."""

36

37

class LassoRegressionLearner:

38

"""

39

Lasso regression with L1 regularization.

40

41

Args:

42

alpha: Regularization strength

43

fit_intercept: Whether to fit intercept

44

normalize: Whether to normalize features

45

max_iter: Maximum iterations

46

"""

47

def __init__(self, alpha=1.0, fit_intercept=True, normalize=False, max_iter=1000): ...

48

49

def __call__(self, data):

50

"""Train and return lasso regression model."""

51

52

class ElasticNetLearner:

53

"""

54

Elastic net regression combining L1 and L2 penalties.

55

56

Args:

57

alpha: Regularization strength

58

l1_ratio: Mixing parameter between L1 and L2

59

fit_intercept: Whether to fit intercept

60

normalize: Whether to normalize features

61

"""

62

def __init__(self, alpha=1.0, l1_ratio=0.5, fit_intercept=True, normalize=False): ...

63

64

def __call__(self, data):

65

"""Train and return elastic net model."""

66

```

67

68

### Tree-Based Regression

69

70

Decision tree algorithms for regression tasks.

71

72

```python { .api }

73

class TreeLearner:

74

"""

75

Decision tree regressor.

76

77

Args:

78

criterion: Split criterion ('mse', 'friedman_mse', 'mae')

79

max_depth: Maximum tree depth

80

min_samples_split: Minimum samples required to split

81

min_samples_leaf: Minimum samples in leaf nodes

82

"""

83

def __init__(self, criterion='mse', max_depth=None,

84

min_samples_split=2, min_samples_leaf=1): ...

85

86

def __call__(self, data):

87

"""Train and return decision tree regression model."""

88

89

class SklTreeRegressionLearner:

90

"""Scikit-learn decision tree regressor wrapper."""

91

def __init__(self, criterion='mse', max_depth=None): ...

92

93

def __call__(self, data):

94

"""Train and return sklearn tree regression model."""

95

```

96

97

### Ensemble Methods

98

99

Ensemble algorithms combining multiple regressors.

100

101

```python { .api }

102

class RandomForestRegressionLearner:

103

"""

104

Random Forest regressor.

105

106

Args:

107

n_estimators: Number of trees

108

max_depth: Maximum tree depth

109

max_features: Number of features per tree

110

bootstrap: Use bootstrap sampling

111

random_state: Random seed

112

"""

113

def __init__(self, n_estimators=10, max_depth=None,

114

max_features='auto', bootstrap=True, random_state=None): ...

115

116

def __call__(self, data):

117

"""Train and return random forest regression model."""

118

```

119

120

### Instance-Based Regression

121

122

k-Nearest Neighbors for regression.

123

124

```python { .api }

125

class KNNRegressionLearner:

126

"""

127

k-Nearest Neighbors regressor.

128

129

Args:

130

n_neighbors: Number of neighbors

131

weights: Weight function ('uniform', 'distance')

132

metric: Distance metric

133

"""

134

def __init__(self, n_neighbors=5, weights='uniform', metric='euclidean'): ...

135

136

def __call__(self, data):

137

"""Train and return k-NN regression model."""

138

```

139

140

### Neural Network Regression

141

142

Multi-layer perceptron for regression tasks.

143

144

```python { .api }

145

class NNRegressionLearner:

146

"""

147

Neural network regressor.

148

149

Args:

150

hidden_layer_sizes: Tuple of hidden layer sizes

151

activation: Activation function

152

solver: Optimization solver

153

learning_rate_init: Initial learning rate

154

max_iter: Maximum iterations

155

"""

156

def __init__(self, hidden_layer_sizes=(100,), activation='relu',

157

solver='adam', learning_rate_init=0.001, max_iter=200): ...

158

159

def __call__(self, data):

160

"""Train and return neural network regression model."""

161

```

162

163

### Gradient Descent Regression

164

165

Stochastic gradient descent for regression.

166

167

```python { .api }

168

class SGDRegressionLearner:

169

"""

170

Stochastic Gradient Descent regressor.

171

172

Args:

173

loss: Loss function ('squared_loss', 'huber', 'epsilon_insensitive')

174

penalty: Regularization ('l1', 'l2', 'elasticnet')

175

alpha: Regularization strength

176

learning_rate: Learning rate schedule

177

"""

178

def __init__(self, loss='squared_loss', penalty='l2', alpha=0.0001,

179

learning_rate='invscaling'): ...

180

181

def __call__(self, data):

182

"""Train and return SGD regression model."""

183

```

184

185

### Partial Least Squares

186

187

PLS regression for high-dimensional data.

188

189

```python { .api }

190

class PLSRegressionLearner:

191

"""

192

Partial Least Squares regression.

193

194

Args:

195

n_components: Number of components

196

scale: Whether to scale data

197

max_iter: Maximum iterations

198

"""

199

def __init__(self, n_components=2, scale=True, max_iter=500): ...

200

201

def __call__(self, data):

202

"""Train and return PLS regression model."""

203

```

204

205

### Baseline Regressors

206

207

Simple baseline algorithms for comparison.

208

209

```python { .api }

210

class MeanLearner:

211

"""

212

Always predicts the mean target value.

213

"""

214

def __call__(self, data):

215

"""Train and return mean prediction model."""

216

```

217

218

### Gradient Boosting (Optional)

219

220

Advanced ensemble methods (requires additional dependencies).

221

222

```python { .api }

223

class XGBRegressor:

224

"""

225

XGBoost regressor (requires xgboost package).

226

227

Args:

228

n_estimators: Number of boosting rounds

229

max_depth: Maximum tree depth

230

learning_rate: Boosting learning rate

231

subsample: Subsample ratio

232

"""

233

def __init__(self, n_estimators=100, max_depth=6, learning_rate=0.3, subsample=1): ...

234

235

def __call__(self, data):

236

"""Train and return XGBoost regression model."""

237

238

class XGBRFRegressor:

239

"""XGBoost Random Forest regressor."""

240

def __init__(self, n_estimators=100, max_depth=6, learning_rate=1, subsample=0.8): ...

241

242

def __call__(self, data):

243

"""Train and return XGBoost RF regression model."""

244

```

245

246

### Usage Examples

247

248

```python

249

# Basic regression workflow

250

from Orange.data import Table

251

from Orange.regression import LinearRegressionLearner, TreeLearner, RandomForestRegressionLearner

252

from Orange.evaluation import CrossValidation, MSE, RMSE, MAE, R2

253

254

# Load regression dataset

255

data = Table("housing") # or any regression dataset

256

257

# Create learners

258

learners = [

259

LinearRegressionLearner(),

260

TreeLearner(max_depth=10),

261

RandomForestRegressionLearner(n_estimators=50)

262

]

263

264

# Cross-validation evaluation

265

results = CrossValidation(data, learners, k=10)

266

267

# Calculate regression metrics

268

mse_scores = MSE(results)

269

rmse_scores = RMSE(results)

270

mae_scores = MAE(results)

271

r2_scores = R2(results)

272

273

print("Regression Results:")

274

for i, learner in enumerate(learners):

275

print(f"{learner.__class__.__name__}:")

276

print(f" MSE: {mse_scores[i]:.3f}")

277

print(f" RMSE: {rmse_scores[i]:.3f}")

278

print(f" MAE: {mae_scores[i]:.3f}")

279

print(f" R²: {r2_scores[i]:.3f}")

280

281

# Train individual models

282

linear_model = LinearRegressionLearner()(data)

283

tree_model = TreeLearner(max_depth=5)(data)

284

285

# Make predictions

286

predictions_linear = linear_model(data[:10])

287

predictions_tree = tree_model(data[:10])

288

289

print(f"Linear predictions: {predictions_linear}")

290

print(f"Tree predictions: {predictions_tree}")

291

292

# Regularized linear models

293

from Orange.regression import RidgeRegressionLearner, LassoRegressionLearner, ElasticNetLearner

294

295

ridge = RidgeRegressionLearner(alpha=1.0)

296

lasso = LassoRegressionLearner(alpha=0.1)

297

elastic = ElasticNetLearner(alpha=0.1, l1_ratio=0.5)

298

299

ridge_model = ridge(data)

300

lasso_model = lasso(data)

301

elastic_model = elastic(data)

302

303

# Neural network regression

304

from Orange.regression import NNRegressionLearner

305

nn = NNRegressionLearner(hidden_layer_sizes=(100, 50), max_iter=500)

306

nn_model = nn(data)

307

308

# k-NN regression

309

from Orange.regression import KNNRegressionLearner

310

knn = KNNRegressionLearner(n_neighbors=5, weights='distance')

311

knn_model = knn(data)

312

```