/// <summary> /// Trains the statistical model. /// </summary> /// <param name="model">The stat model.</param> /// <param name="samples">The training samples.</param> /// <param name="layoutType">Type of the layout.</param> /// <param name="responses">Vector of responses associated with the training samples.</param> /// <returns></returns> public static bool Train(this IStatModel model, IInputArray samples, DataLayoutType layoutType, IInputArray responses) { using (InputArray iaSamples = samples.GetInputArray()) using (InputArray iaResponses = responses.GetInputArray()) { return(MlInvoke.StatModelTrain(model.StatModelPtr, iaSamples, layoutType, iaResponses)); } }
/// <summary> /// Trains the statistical model. /// </summary> /// <param name="model">The stat model.</param> /// <param name="samples">The training samples.</param> /// <param name="layoutType">Type of the layout.</param> /// <param name="responses">Vector of responses associated with the training samples.</param> /// <returns></returns> public static bool Train(this IStatModel model, IInputArray samples, DataLayoutType layoutType, IInputArray responses) { using (InputArray iaSamples = samples.GetInputArray()) using (InputArray iaResponses = responses.GetInputArray()) { return MlInvoke.StatModelTrain(model.StatModelPtr, iaSamples, layoutType, iaResponses); } }
/// <summary> /// Creates training data from in-memory arrays. /// </summary> /// <param name="samples">Matrix of samples. It should have CV_32F type.</param> /// <param name="layoutType">Type of the layout.</param> /// <param name="response">Matrix of responses. If the responses are scalar, they should be stored as a single row or as a single column. The matrix should have type CV_32F or CV_32S (in the former case the responses are considered as ordered by default; in the latter case - as categorical)</param> /// <param name="varIdx">Vector specifying which variables to use for training. It can be an integer vector (CV_32S) containing 0-based variable indices or byte vector (CV_8U) containing a mask of active variables.</param> /// <param name="sampleIdx">Vector specifying which samples to use for training. It can be an integer vector (CV_32S) containing 0-based sample indices or byte vector (CV_8U) containing a mask of training samples.</param> /// <param name="sampleWeight">Optional vector with weights for each sample. It should have CV_32F type.</param> /// <param name="varType">Optional vector of type CV_8U and size <number_of_variables_in_samples> + <number_of_variables_in_responses>, containing types of each input and output variable.</param> public TrainData( IInputArray samples, DataLayoutType layoutType, IInputArray response, IInputArray varIdx = null, IInputArray sampleIdx = null, IInputArray sampleWeight = null, IInputArray varType = null ) { using (InputArray iaSamples = samples.GetInputArray()) using (InputArray iaResponse = response.GetInputArray()) using (InputArray iaVarIdx = varIdx == null ? InputArray.GetEmpty() : varIdx.GetInputArray()) using (InputArray iaSampleIdx = sampleIdx == null ? InputArray.GetEmpty() : sampleIdx.GetInputArray()) using (InputArray iaSampleWeight = sampleWeight == null ? InputArray.GetEmpty() : sampleWeight.GetInputArray()) using (InputArray iaVarType = varType == null ? InputArray.GetEmpty() : varType.GetInputArray()) { _ptr = MlInvoke.cveTrainDataCreate(iaSamples, layoutType, iaResponse, iaVarIdx, iaSampleIdx, iaSampleWeight, iaVarType); } }
internal static extern IntPtr cveTrainDataCreate( IntPtr samples, DataLayoutType layout, IntPtr responses, IntPtr varIdx, IntPtr sampleIdx, IntPtr sampleWeights, IntPtr varType);
internal static extern bool StatModelTrain(IntPtr model, IntPtr samples, DataLayoutType layout, IntPtr responses);