TransferRandomForest<T>
Models & Types ยท AiDotNet.TransferLearning.Algorithms
Implements transfer learning for Random Forest models.
Inheritance: TransferLearningBase<T, Matrix<T>, Vector<T>> โ TransferRandomForest<T>
For Beginners
This class enables Random Forest models to transfer knowledge from one domain to another. Random Forests are ensembles of decision trees, and this class can adapt them when the source and target domains have different feature spaces.
Example
// The model already fitted on the source domain, and the target domain's own data.
var sourceModel = new SimpleRegression<double>();
var sourceData = new Matrix<double>(new double[,] { { 0.9, 1.9 }, { 2.9, 3.9 }, { 4.9, 5.9 } });
var targetData = new Matrix<double>(new double[,] { { 1.0, 2.0 }, { 3.0, 4.0 }, { 5.0, 6.0 } });
var targetLabels = new Vector<double>(new double[] { 1.0, 2.0, 3.0 });
// Transfer a Random Forest from source domain to target domain
var options = new RandomForestRegressionOptions { NumberOfTrees = 100, MaxDepth = 10 };
var transferRF = new TransferRandomForest<double>(options);
IFullModel<double, Matrix<double>, Vector<double>> adaptedModel =
transferRF.Transfer(sourceModel, sourceData, targetData, targetLabels);
var result = new AiModelBuilder<double, Matrix<double>, Vector<double>>()
.ConfigureModel(adaptedModel)
.Build(targetData, targetLabels);
var newData = new Matrix<double>(new double[,] { { 7.0, 8.0 } });
Vector<double> predictions = result.Predict(newData);
Constructors
| Constructor | Summary |
|---|---|
TransferRandomForest() |
Initializes a new instance with default settings. |
TransferRandomForest(RandomForestRegressionOptions options, IRegularization<T, Matrix<T>, Vector<T>> regularization) |
Initializes a new instance of the TransferRandomForest class. |
Methods
| Method | Summary |
|---|---|
IFullModel<T, Matrix<T>, Vector<T>> Transfer(IFullModel<T, Matrix<T>, Vector<T>> sourceModel, Matrix<T> sourceData, Matrix<T> targetData, Vector<T> targetLabels) |
Transfers a Random Forest model to a target domain with proper source data. |