Home>

After running the following code
ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?, K), (k, m?)->(N ?, m?) (Size 5 is different from 1)
Is output. What could be the problem with this?

import numpy as np
from sklearn.linear_model import LinearRegression
lr = LinearRegression ()
x = np.array ([[
              [
               3,5,7,9,10
               ]
              ])
t = np.array ([[
              [1,3,5,7,9]
              ])
lr.fit (x, t)
x = np.array ([[
              [Four]
              ])
lr.predict (x)
  • Answer # 1

    Is it something like this?

    import numpy as np
    from sklearn.linear_model import LinearRegression
    lr = LinearRegression ()
    x = np.array ([[
                  [
                   3,5,7,9,10
                   ]
                  ])
    t = np.array ([[
                  [1,3,5,7,9]
                  ])
    lr.fit (x.T, t.T)
    x2 = np.array ([[
                  [Four]
                  ])
    lr.predict (x2)
    # array ([[1.92682927]])

  • Answer # 2

    x = np.array ([[4]])Please set the number of elements to 5 at. (For example, x = np.array ([[4,2,9,1,7]]))