/// <summary> /// SVMを最適なパラメータで学習する /// </summary> /// <param name="train_data"></param> /// <param name="responses"></param> /// <param name="var_idx"></param> /// <param name="sample_idx"></param> /// <param name="params"></param> /// <param name="k_fold">交差検定(Cross-validation)パラメータ.学習集合は,k_foldの部分集合に分割され,一つの部分集合がモデルの学習に用いられ,その他の部分集合はテスト集合となる.つまり,SVM アルゴリズムは,k_fold回実行される.</param> /// <param name="C_grid"></param> /// <param name="gamma_grid"></param> /// <param name="p_grid"></param> /// <param name="nu_grid"></param> /// <param name="coef_grid"></param> /// <param name="degree_grid"></param> /// <returns></returns> #else /// <summary> /// Trains SVM with optimal parameters /// </summary> /// <param name="trainData"></param> /// <param name="responses"></param> /// <param name="varIdx"></param> /// <param name="sampleIdx"></param> /// <param name="params"></param> /// <param name="kFold">Cross-validation parameter. The training set is divided into k_fold subsets, one subset being used to train the model, the others forming the test set. So, the SVM algorithm is executed k_fold times. </param> /// <param name="cGrid"></param> /// <param name="gammaGrid"></param> /// <param name="pGrid"></param> /// <param name="nuGrid"></param> /// <param name="coefGrid"></param> /// <param name="degreeGrid"></param> /// <returns></returns> #endif public virtual bool TrainAuto(CvMat trainData, CvMat responses, CvMat varIdx, CvMat sampleIdx, CvSVMParams @params, int kFold, CvParamGrid cGrid, CvParamGrid gammaGrid, CvParamGrid pGrid, CvParamGrid nuGrid, CvParamGrid coefGrid, CvParamGrid degreeGrid) { if (trainData == null) throw new ArgumentNullException("trainData"); if (responses == null) throw new ArgumentNullException("responses"); if(@params == null) @params = new CvSVMParams(); IntPtr varIdxPtr = (varIdx == null) ? IntPtr.Zero : varIdx.CvPtr; IntPtr sampleIdxPtr = (sampleIdx == null) ? IntPtr.Zero : sampleIdx.CvPtr; return MLInvoke.CvSVM_train_auto( ptr, trainData.CvPtr, responses.CvPtr, varIdxPtr, sampleIdxPtr, @params.NativeStruct, kFold, cGrid, gammaGrid, pGrid, nuGrid, coefGrid, degreeGrid ); }
/// <summary> /// SVM パラメータのためのグリッドを生成する /// </summary> /// <param name="param_id"></param> /// <returns></returns> #else /// <summary> /// Generates a grid for SVM parameters /// </summary> /// <param name="paramId"></param> /// <returns></returns> #endif public static CvParamGrid GetDefaultGrid(SVMParamType paramId) { CvParamGrid grid = new CvParamGrid(); MLInvoke.CvSVM_get_default_grid(ref grid, (int)paramId); return grid; }
public static extern bool CvParamGrid_check(CvParamGrid grid);
public static extern bool CvSVM_train_auto(IntPtr model, IntPtr _train_data, IntPtr _responses, IntPtr _var_idx, IntPtr _sample_idx, WCvSVMParams _params, int k_fold, CvParamGrid C_grid, CvParamGrid gamma_grid, CvParamGrid p_grid, CvParamGrid nu_grid, CvParamGrid coef_grid, CvParamGrid degree_grid);
public static extern void CvSVM_get_default_grid(ref CvParamGrid grid, int param_id);