/** * Trains an %SVM with optimal parameters * * param samples training samples * param layout See ml::SampleTypes. * param responses vector of responses associated with the training samples. * param kFold Cross-validation parameter. The training set is divided into kFold subsets. One * subset is used to test the model, the others form the train set. So, the %SVM algorithm is * param Cgrid grid for C * param gammaGrid grid for gamma * param pGrid grid for p * balanced cross-validation subsets that is proportions between classes in subsets are close * to such proportion in the whole train dataset. * * The method trains the %SVM model automatically by choosing the optimal parameters C, gamma, p, * nu, coef0, degree. Parameters are considered optimal when the cross-validation * estimate of the test set error is minimal. * * This function only makes use of SVM::getDefaultGrid for parameter optimization and thus only * offers rudimentary parameter options. * * This function works for the classification (SVM::C_SVC or SVM::NU_SVC) as well as for the * regression (SVM::EPS_SVR or SVM::NU_SVR). If it is SVM::ONE_CLASS, no optimization is made and * the usual %SVM with parameters specified in params is executed. * return automatically generated */ public bool trainAuto(Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid, ParamGrid pGrid) { ThrowIfDisposed(); if (samples != null) { samples.ThrowIfDisposed(); } if (responses != null) { responses.ThrowIfDisposed(); } if (Cgrid != null) { Cgrid.ThrowIfDisposed(); } if (gammaGrid != null) { gammaGrid.ThrowIfDisposed(); } if (pGrid != null) { pGrid.ThrowIfDisposed(); } return(ml_SVM_trainAuto_14(nativeObj, samples.nativeObj, layout, responses.nativeObj, kFold, Cgrid.getNativeObjAddr(), gammaGrid.getNativeObjAddr(), pGrid.getNativeObjAddr())); }
//javadoc: SVM::trainAuto(samples, layout, responses, kFold, Cgrid, gammaGrid) public bool trainAuto(Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid) { ThrowIfDisposed(); if (samples != null) { samples.ThrowIfDisposed(); } if (responses != null) { responses.ThrowIfDisposed(); } if (Cgrid != null) { Cgrid.ThrowIfDisposed(); } if (gammaGrid != null) { gammaGrid.ThrowIfDisposed(); } #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER bool retVal = ml_SVM_trainAuto_15(nativeObj, samples.nativeObj, layout, responses.nativeObj, kFold, Cgrid.getNativeObjAddr(), gammaGrid.getNativeObjAddr()); return(retVal); #else return(false); #endif }
// // C++: bool cv::ml::SVM::trainAuto(Mat samples, int layout, Mat responses, int kFold = 10, Ptr_ParamGrid Cgrid = SVM::getDefaultGridPtr(SVM::C), Ptr_ParamGrid gammaGrid = SVM::getDefaultGridPtr(SVM::GAMMA), Ptr_ParamGrid pGrid = SVM::getDefaultGridPtr(SVM::P), Ptr_ParamGrid nuGrid = SVM::getDefaultGridPtr(SVM::NU), Ptr_ParamGrid coeffGrid = SVM::getDefaultGridPtr(SVM::COEF), Ptr_ParamGrid degreeGrid = SVM::getDefaultGridPtr(SVM::DEGREE), bool balanced = false) // //javadoc: SVM::trainAuto(samples, layout, responses, kFold, Cgrid, gammaGrid, pGrid, nuGrid, coeffGrid, degreeGrid, balanced) public bool trainAuto(Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid, ParamGrid pGrid, ParamGrid nuGrid, ParamGrid coeffGrid, ParamGrid degreeGrid, bool balanced) { ThrowIfDisposed(); if (samples != null) { samples.ThrowIfDisposed(); } if (responses != null) { responses.ThrowIfDisposed(); } if (Cgrid != null) { Cgrid.ThrowIfDisposed(); } if (gammaGrid != null) { gammaGrid.ThrowIfDisposed(); } if (pGrid != null) { pGrid.ThrowIfDisposed(); } if (nuGrid != null) { nuGrid.ThrowIfDisposed(); } if (coeffGrid != null) { coeffGrid.ThrowIfDisposed(); } if (degreeGrid != null) { degreeGrid.ThrowIfDisposed(); } #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER bool retVal = ml_SVM_trainAuto_10(nativeObj, samples.nativeObj, layout, responses.nativeObj, kFold, Cgrid.getNativeObjAddr(), gammaGrid.getNativeObjAddr(), pGrid.getNativeObjAddr(), nuGrid.getNativeObjAddr(), coeffGrid.getNativeObjAddr(), degreeGrid.getNativeObjAddr(), balanced); return(retVal); #else return(false); #endif }
// // C++: bool cv::ml::SVM::trainAuto(Mat samples, int layout, Mat responses, int kFold = 10, Ptr_ParamGrid Cgrid = SVM::getDefaultGridPtr(SVM::C), Ptr_ParamGrid gammaGrid = SVM::getDefaultGridPtr(SVM::GAMMA), Ptr_ParamGrid pGrid = SVM::getDefaultGridPtr(SVM::P), Ptr_ParamGrid nuGrid = SVM::getDefaultGridPtr(SVM::NU), Ptr_ParamGrid coeffGrid = SVM::getDefaultGridPtr(SVM::COEF), Ptr_ParamGrid degreeGrid = SVM::getDefaultGridPtr(SVM::DEGREE), bool balanced = false) // /** * Trains an %SVM with optimal parameters * * param samples training samples * param layout See ml::SampleTypes. * param responses vector of responses associated with the training samples. * param kFold Cross-validation parameter. The training set is divided into kFold subsets. One * subset is used to test the model, the others form the train set. So, the %SVM algorithm is * param Cgrid grid for C * param gammaGrid grid for gamma * param pGrid grid for p * param nuGrid grid for nu * param coeffGrid grid for coeff * param degreeGrid grid for degree * param balanced If true and the problem is 2-class classification then the method creates more * balanced cross-validation subsets that is proportions between classes in subsets are close * to such proportion in the whole train dataset. * * The method trains the %SVM model automatically by choosing the optimal parameters C, gamma, p, * nu, coef0, degree. Parameters are considered optimal when the cross-validation * estimate of the test set error is minimal. * * This function only makes use of SVM::getDefaultGrid for parameter optimization and thus only * offers rudimentary parameter options. * * This function works for the classification (SVM::C_SVC or SVM::NU_SVC) as well as for the * regression (SVM::EPS_SVR or SVM::NU_SVR). If it is SVM::ONE_CLASS, no optimization is made and * the usual %SVM with parameters specified in params is executed. * return automatically generated */ public bool trainAuto(Mat samples, int layout, Mat responses, int kFold, ParamGrid Cgrid, ParamGrid gammaGrid, ParamGrid pGrid, ParamGrid nuGrid, ParamGrid coeffGrid, ParamGrid degreeGrid, bool balanced) { ThrowIfDisposed(); if (samples != null) { samples.ThrowIfDisposed(); } if (responses != null) { responses.ThrowIfDisposed(); } if (Cgrid != null) { Cgrid.ThrowIfDisposed(); } if (gammaGrid != null) { gammaGrid.ThrowIfDisposed(); } if (pGrid != null) { pGrid.ThrowIfDisposed(); } if (nuGrid != null) { nuGrid.ThrowIfDisposed(); } if (coeffGrid != null) { coeffGrid.ThrowIfDisposed(); } if (degreeGrid != null) { degreeGrid.ThrowIfDisposed(); } return(ml_SVM_trainAuto_10(nativeObj, samples.nativeObj, layout, responses.nativeObj, kFold, Cgrid.getNativeObjAddr(), gammaGrid.getNativeObjAddr(), pGrid.getNativeObjAddr(), nuGrid.getNativeObjAddr(), coeffGrid.getNativeObjAddr(), degreeGrid.getNativeObjAddr(), balanced)); }