/// <summary> /// Splits the current dataset into train and test batch. /// </summary> /// <param name="testSplitSize">Size of the test split. (value between 0.01 and 0.99)</param> /// <returns></returns> /// <exception cref="ArgumentException">Please use test split range between 0.01 and 0.99</exception> public TrainTestFrame SplitTrainTest(double testSplitSize) { if (testSplitSize < 0.01 && testSplitSize > 0.99) { throw new ArgumentException("Please use test split range between 0.01 and 0.99"); } TrainTestFrame result = new TrainTestFrame(); int totalRows = XFrame.Data.Count; int testRows = (int)(totalRows * testSplitSize); int trainRows = totalRows - testRows; result.Train.XFrame.Data = XFrame.Data.Take(trainRows).ToList(); result.Train.XFrame.Columns = XFrame.Columns; result.Test.XFrame.Data = XFrame.Data.Skip(trainRows).Take(testRows).ToList(); result.Test.XFrame.Columns = XFrame.Columns; result.Train.YFrame.Data = YFrame.Data.Take(trainRows).ToList(); result.Train.YFrame.Columns = YFrame.Columns; result.Test.YFrame.Data = YFrame.Data.Skip(trainRows).Take(testRows).ToList(); result.Test.YFrame.Columns = YFrame.Columns; return(result); }
/// <summary> /// Splits the current dataset into train and test batch. /// </summary> /// <param name="testSplitSize">Size of the test split. (value between 0.01 and 0.99)</param> /// <returns></returns> /// <exception cref="ArgumentException">Please use test split range between 0.01 and 0.99</exception> public TrainTestFrame SplitTrainTest(double testSplitSize) { if (testSplitSize < 0.01 && testSplitSize > 0.99) { throw new ArgumentException("Please use test split range between 0.01 and 0.99"); } TrainTestFrame result = new TrainTestFrame(); DataTable dt_x = XFrame.Frame.ToTable(); DataTable dt_y = YFrame.Frame.ToTable(); int totalRows = dt_x.Rows.Count; int testRows = (int)(totalRows * testSplitSize); int trainRows = totalRows - testRows; result.Train.XFrame.Frame = dt_x.Select().Take(trainRows).CopyToDataTable().AsDataView(); result.Test.XFrame.Frame = dt_x.Select().Skip(trainRows).Take(testRows).CopyToDataTable().AsDataView(); result.Train.YFrame.Frame = dt_y.Select().Take(trainRows).CopyToDataTable().AsDataView(); result.Test.YFrame.Frame = dt_y.Select().Skip(trainRows).Take(testRows).CopyToDataTable().AsDataView(); return(result); }