[jvm-packages] Deprecate constructors with implicit missing value. (#7225)
This commit is contained in:
parent
0ed979b096
commit
9f63d6fead
@ -124,7 +124,11 @@ public class DMatrix {
|
|||||||
* @param nrow number of rows
|
* @param nrow number of rows
|
||||||
* @param ncol number of columns
|
* @param ncol number of columns
|
||||||
* @throws XGBoostError native error
|
* @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 {
|
public DMatrix(float[] data, int nrow, int ncol) throws XGBoostError {
|
||||||
long[] out = new long[1];
|
long[] out = new long[1];
|
||||||
XGBoostJNI.checkCall(XGBoostJNI.XGDMatrixCreateFromMat(data, nrow, ncol, 0.0f, out));
|
XGBoostJNI.checkCall(XGBoostJNI.XGDMatrixCreateFromMat(data, nrow, ncol, 0.0f, out));
|
||||||
|
|||||||
@ -79,6 +79,7 @@ class DMatrix private[scala](private[scala] val jDMatrix: JDMatrix) {
|
|||||||
* @param nrow number of rows
|
* @param nrow number of rows
|
||||||
* @param ncol number of columns
|
* @param ncol number of columns
|
||||||
*/
|
*/
|
||||||
|
@deprecated("Please specify the missing value explicitly", "XGBoost 1.5")
|
||||||
@throws(classOf[XGBoostError])
|
@throws(classOf[XGBoostError])
|
||||||
def this(data: Array[Float], nrow: Int, ncol: Int) {
|
def this(data: Array[Float], nrow: Int, ncol: Int) {
|
||||||
this(new JDMatrix(data, nrow, ncol))
|
this(new JDMatrix(data, nrow, ncol))
|
||||||
|
|||||||
@ -212,7 +212,7 @@ public class DMatrixTest {
|
|||||||
label0[i] = random.nextFloat();
|
label0[i] = random.nextFloat();
|
||||||
}
|
}
|
||||||
|
|
||||||
DMatrix dmat0 = new DMatrix(data0, nrow, ncol);
|
DMatrix dmat0 = new DMatrix(data0, nrow, ncol, Float.NaN);
|
||||||
dmat0.setLabel(label0);
|
dmat0.setLabel(label0);
|
||||||
|
|
||||||
//check
|
//check
|
||||||
@ -281,7 +281,7 @@ public class DMatrixTest {
|
|||||||
label0[i] = random.nextFloat();
|
label0[i] = random.nextFloat();
|
||||||
}
|
}
|
||||||
|
|
||||||
dmat0 = new DMatrix(data0);
|
dmat0 = new DMatrix(data0, Float.NaN);
|
||||||
dmat0.setLabel(label0);
|
dmat0.setLabel(label0);
|
||||||
|
|
||||||
//check
|
//check
|
||||||
@ -318,7 +318,7 @@ public class DMatrixTest {
|
|||||||
for (int j = 0; j < data0.ncol; j++)
|
for (int j = 0; j < data0.ncol; j++)
|
||||||
data0.set(i, j, data[i][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});
|
trainMat.setLabel(new float[]{1f, 2f, 3f});
|
||||||
|
|
||||||
HashMap<String, Object> params = new HashMap<>();
|
HashMap<String, Object> params = new HashMap<>();
|
||||||
@ -338,7 +338,7 @@ public class DMatrixTest {
|
|||||||
// (3,1) -> 2
|
// (3,1) -> 2
|
||||||
// (2,3) -> 3
|
// (2,3) -> 3
|
||||||
for (int i = 0; i < 3; i++) {
|
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);
|
assertEquals(1, preds.length);
|
||||||
assertArrayEquals(new float[]{(float) (i + 1)}, preds[0], 1e-2f);
|
assertArrayEquals(new float[]{(float) (i + 1)}, preds[0], 1e-2f);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -130,7 +130,7 @@ class DMatrixSuite extends FunSuite {
|
|||||||
for (i <- label0.indices) {
|
for (i <- label0.indices) {
|
||||||
label0(i) = Random.nextFloat()
|
label0(i) = Random.nextFloat()
|
||||||
}
|
}
|
||||||
val dmat0 = new DMatrix(data0, nrow, ncol)
|
val dmat0 = new DMatrix(data0, nrow, ncol, Float.NaN)
|
||||||
dmat0.setLabel(label0)
|
dmat0.setLabel(label0)
|
||||||
// check
|
// check
|
||||||
assert(dmat0.rowNum === 10)
|
assert(dmat0.rowNum === 10)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user