array_merge(): Expected parameter 1 to be an array, null given code example

Example 1: array_merge(): Expected parameter 1 to be an array, null given at vendor/phpunit/phpunit/phpunit:61

// PHPUnit uses the constructor for initialization of the base TestCase.
// You shouldn't use the constructor, because it's used by phpunit and any
// change to the signature etc can break things. You can use the special
// setUp and setUpBeforeClass methods which phpunit will call for you.

class XTest extends TestCase
{
    function static setUpBeforeClass()
    { 
       // Called once just like normal constructor
       // You can create database connections here etc
    }

    function setUp()
    {
      //Initialize the test case
      //Called for every defined test
    }

    function testX()
    {
        $this->assertTrue(true);
    }

    // Clean up the test case, called for every defined test
    public function tearDown() { }

    // Clean up the whole test class
    public static function tearDownAfterClass() { }
}

Example 2: valueerror: expected 2d array, got 1d array instead:

You are just supposed to provide the predict method with the same 2D array, but with one value that you want to process (or more). In short, you can just replace

[0.58,0.76]
With

[[0.58,0.76]]
And it should work.

EDIT: This answer became popular so I thought I'd add a little more explanation about ML. The short version: we can only use predict on data that is of the same dimensionality as the training data (X) was.

In the example in question, we give the computer a bunch of rows in X (with 2 values each) and we show it the correct responses in y. When we want to predict using new values, our program expects the same - a bunch of rows. Even if we want to do it to just one row (with two values), that row has to be part of another array

Tags:

Php Example