MappedRandomForestModel<T>
Models & Types · AiDotNet.TransferLearning.Algorithms
Wrapper model that applies feature mapping before prediction.
Inheritance: ModelWrapperBase<T, Matrix<T>, Vector<T>> → MappedRandomForestModel<T>
For Beginners
This wrapper adapts a Random Forest trained on one set of features to work with a different set of features. It automatically maps the input features from the target domain to match what the source model expects, then runs the prediction. This is how transfer learning works with tree-based models.
Example
// Create a mapped random forest that adapts source features to target domain.
// The base model is a random forest already fitted on the source domain.
var baseModel = new RandomForestRegression<double>(new RandomForestRegressionOptions());
var mapper = new LinearFeatureMapper<double>();
var mappedModel = new MappedRandomForestModel<double>(baseModel, mapper, targetFeatures: 5);
var targetFeatures = new Matrix<double>(new double[,]
{
{ 1.0, 2.0, 3.0, 4.0, 5.0 }, { 2.0, 3.0, 4.0, 5.0, 6.0 }, { 3.0, 4.0, 5.0, 6.0, 7.0 }
});
var targetLabels = new Vector<double>(new double[] { 1.0, 2.0, 3.0 });
var result = new AiModelBuilder<double, Matrix<double>, Vector<double>>()
.ConfigureModel(mappedModel)
.Build(targetFeatures, targetLabels);
// Predict on target domain data using feature mapping
var prediction = result.Predict(targetFeatures);
Constructors
| Constructor | Summary |
|---|---|
MappedRandomForestModel(IFullModel<T, Matrix<T>, Vector<T>> baseModel, IFeatureMapper<T> mapper, int targetFeatures) |
Properties
| Property | Summary |
|---|---|
bool SupportsParameterInitialization { get; } |
Methods
| Method | Summary |
|---|---|
Dictionary<string, T> GetFeatureImportance() |
|
IEnumerable<int> GetActiveFeatureIndices() |
|
IFullModel<T, Matrix<T>, Vector<T>> WithParameters(Vector<T> parameters) |
|
Vector<T> Predict(Matrix<T> input) |
|
bool IsFeatureUsed(int featureIndex) |
|
void LoadModel(string filePath) |
|
void LoadState(Stream stream) |
Loads the mapped Random Forest model’s state from a stream. |
void SaveModel(string filePath) |
|
void SaveState(Stream stream) |
Saves the mapped Random Forest model’s current state to a stream. |