Class ModelHelper<T, TInput, TOutput>
Provides helper methods for model-related operations.
public static class ModelHelper<T, TInput, TOutput>
Type Parameters
TTInputTOutput
- Inheritance
-
ModelHelper<T, TInput, TOutput>
- Inherited Members
Remarks
For Beginners: This helper class contains methods for creating and working with different types of machine learning models. It makes it easier to initialize models, handle different data types, and perform common operations needed when working with models.
Methods
CreateDefaultModel()
Creates a default implementation of IFullModel based on the input and output types.
public static IFullModel<T, TInput, TOutput> CreateDefaultModel()
Returns
- IFullModel<T, TInput, TOutput>
A default implementation of IFullModel.
Remarks
This method creates an appropriate default model based on the input and output types. It supports creating VectorModel for linear models with matrix input and vector output, and NeuralNetworkModel for models with tensor input and output.
For Beginners: This method helps create a starting point model based on your data types.
- For simple linear models (like regression), it creates a VectorModel.
- For more complex models (like neural networks), it creates a NeuralNetworkModel.
- If your data types don't match these patterns, it will throw an error to let you know.
This is useful when you need a basic model to start with, which you can then customize or optimize.
CreateDefaultModelData()
Creates default empty model data for initialization purposes.
public static (TInput X, TOutput Y, TOutput Predictions) CreateDefaultModelData()
Returns
- (TInput X, TOutput Y, TOutput Predictions)
A tuple containing default empty X, Y, and Predictions data structures.
Remarks
For Beginners: This method creates empty placeholders for your data and predictions. Think of it like creating empty containers that you'll fill later with your actual data. This is useful when you need to set up a model structure before you have the real data.
Exceptions
- InvalidOperationException
Thrown when TInput and TOutput are unsupported types.
CreateRandomModelWithFeatures(int[], int, bool, int)
Creates a random model that emphasizes specific features.
public static IFullModel<T, TInput, TOutput> CreateRandomModelWithFeatures(int[] activeFeatures, int totalFeatures, bool useExpressionTrees = false, int maxExpressionTreeDepth = 3)
Parameters
activeFeaturesint[]The indices of features to emphasize in the model.
totalFeaturesintThe total number of available features.
useExpressionTreesboolWhether to use expression trees instead of vector models.
maxExpressionTreeDepthintThe maximum depth for expression trees if used.
Returns
- IFullModel<T, TInput, TOutput>
A randomly initialized model appropriate for the input/output types.
Remarks
This method creates a model that focuses on the specified active features while ignoring or de-emphasizing others. It automatically selects an appropriate model type based on the input and output generic parameters.
For Beginners: This method creates a model that focuses on specific features.
For example, if you have data with features like age, income, education, etc.:
- You can specify that the model should focus on just [age, education]
- The model will be configured to use those features more significantly
- Other features will be given minimal weight or ignored completely
This approach helps build more focused models that can perform better by concentrating on the most relevant features.
GetColumnVectors(TInput, int[])
public static List<Vector<T>> GetColumnVectors(TInput input, int[] indices)
Parameters
inputTInputindicesint[]
Returns
- List<Vector<T>>