double[] PredictForMat <T>(T[,] data, LGBMPredictType predictType, int numIteration) where T : struct { var ttype = typeof(T); if (!(ttype == typeof(double) || ttype == typeof(float))) { throw new ArgumentException("data must be float or double"); } int numClasses = GetNumClasses(); var dataType = Constants.TypeLgbmTypeMap[ttype]; var numRows = data.GetRowsCount(); var numCols = data.GetColsCount(); int outNumPreds; var numPredict = CalcNumPredict(numRows, predictType, numIteration); var result = new double[numPredict]; Array dataArr = (Array)data; IntPtr dataPtr = dataArr.GetPointer(); SafeCall(LGBM_BoosterPredictForMat(_handle, dataPtr, dataType, numRows, numCols, 1, predictType, numIteration, "", out outNumPreds, result)); if (outNumPreds != numPredict) { throw new Exception("Wrong number of predict results"); } return(result); }
/// <summary> /// Get size of prediction result. /// </summary> int CalcNumPredict(int numRow, LGBMPredictType predictType, int numIteration) { // Python ima long za outLen int outLen; SafeCall(LGBM_BoosterCalcNumPredict(_handle, numRow, predictType, numIteration, out outLen)); return(outLen); }
public double[] Predict(string fileName, bool dataHasHeader = false, LGBMPredictType predictType = LGBMPredictType.PredictNormal, int numIterations = -1) { if (!File.Exists(fileName)) { throw new FileNotFoundException($"File {fileName} does not exist"); } var tempFile = Path.GetTempFileName(); Utils.SafeCall(LGBM_BoosterPredictForFile(_handle, fileName, dataHasHeader, predictType, numIterations, _parameters, tempFile)); var lines = File.ReadAllLines(tempFile); throw new Exception("TODO : What's in lines ?"); return(null); }
public static extern int LGBM_BoosterPredictForMat(BoosterHandle handle, IntPtr data, LGBMDataType data_type, int numRows, int numCols, int is_row_major, LGBMPredictType predict_type, int num_iteration, [In][MarshalAs(UnmanagedType.LPStr)] string parameter, out int out_len, IntPtr out_result);
public static extern int LGBM_BoosterCalcNumPredict(BoosterHandle handle, int num_row, LGBMPredictType predict_type, int num_iteration, out int out_len);
public static extern int LGBM_BoosterPredictForFile(BoosterHandle handle, [In][MarshalAs(UnmanagedType.LPStr)] string data_filename, [MarshalAs(UnmanagedType.I4)] bool data_has_header, LGBMPredictType predict_type, int num_iteration, [In][MarshalAs(UnmanagedType.LPStr)] string parameter, [In][MarshalAs(UnmanagedType.LPStr)] string result_filename);
public static extern int LGBM_BoosterPredictForFile(BoosterHandle handle, [In][MarshalAs(UnmanagedType.LPStr)] string data_filename, //[MarshalAs(UnmanagedType.I4)] [MarshalAs(UnmanagedType.U1)] //20200323 水田変更 UnmanagedType.I4 だとC#の bool型をマーシャリングできない。(表現合ってる?).NetFrameWorkのバージョン違いによるもの? bool data_has_header, LGBMPredictType predict_type, int num_iteration, [In][MarshalAs(UnmanagedType.LPStr)] string parameter, [In][MarshalAs(UnmanagedType.LPStr)] string result_filename);
public double[] Predict(double[,] data, LGBMPredictType predictType = LGBMPredictType.PredictNormal, int numIterations = -1) { return(PredictForMat(data, predictType, numIterations)); }