[jvm-packages] Deprecate constructors with implicit missing value. (#7225)

This commit is contained in:
Jiaming Yuan 2021-09-17 04:35:04 +08:00 committed by GitHub
parent 0ed979b096
commit 9f63d6fead
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 5 deletions

View File

@ -124,7 +124,11 @@ public class DMatrix {
* @param nrow number of rows
* @param ncol number of columns
* @throws XGBoostError native error
*
* @deprecated Please specify the missing value explicitly using
* {@link DMatrix(float[], int, int, float)}
*/
@Deprecated
public DMatrix(float[] data, int nrow, int ncol) throws XGBoostError {
long[] out = new long[1];
XGBoostJNI.checkCall(XGBoostJNI.XGDMatrixCreateFromMat(data, nrow, ncol, 0.0f, out));

View File

@ -79,6 +79,7 @@ class DMatrix private[scala](private[scala] val jDMatrix: JDMatrix) {
* @param nrow number of rows
* @param ncol number of columns
*/
@deprecated("Please specify the missing value explicitly", "XGBoost 1.5")
@throws(classOf[XGBoostError])
def this(data: Array[Float], nrow: Int, ncol: Int) {
this(new JDMatrix(data, nrow, ncol))

View File

@ -212,7 +212,7 @@ public class DMatrixTest {
label0[i] = random.nextFloat();
}
DMatrix dmat0 = new DMatrix(data0, nrow, ncol);
DMatrix dmat0 = new DMatrix(data0, nrow, ncol, Float.NaN);
dmat0.setLabel(label0);
//check
@ -281,7 +281,7 @@ public class DMatrixTest {
label0[i] = random.nextFloat();
}
dmat0 = new DMatrix(data0);
dmat0 = new DMatrix(data0, Float.NaN);
dmat0.setLabel(label0);
//check
@ -318,7 +318,7 @@ public class DMatrixTest {
for (int j = 0; j < data0.ncol; j++)
data0.set(i, j, data[i][j]);
trainMat = new DMatrix(data0);
trainMat = new DMatrix(data0, Float.NaN);
trainMat.setLabel(new float[]{1f, 2f, 3f});
HashMap<String, Object> params = new HashMap<>();
@ -338,7 +338,7 @@ public class DMatrixTest {
// (3,1) -> 2
// (2,3) -> 3
for (int i = 0; i < 3; i++) {
float[][] preds = booster.predict(new DMatrix(data[i], 1, 2));
float[][] preds = booster.predict(new DMatrix(data[i], 1, 2, Float.NaN));
assertEquals(1, preds.length);
assertArrayEquals(new float[]{(float) (i + 1)}, preds[0], 1e-2f);
}

View File

@ -130,7 +130,7 @@ class DMatrixSuite extends FunSuite {
for (i <- label0.indices) {
label0(i) = Random.nextFloat()
}
val dmat0 = new DMatrix(data0, nrow, ncol)
val dmat0 = new DMatrix(data0, nrow, ncol, Float.NaN)
dmat0.setLabel(label0)
// check
assert(dmat0.rowNum === 10)