python – Is it possible to predict using a single variable in multiple regression?


In linear regression created using more than one training data, I have to predict using only one variable.

One possible scenario results as follows:

import numpy as np
from sklearn.linear_model import LinearRegression

x = ((0, 1), (5, 1), (15, 2), (25, 5), (35, 11), (45, 15), (55, 34), (60, 35))
y = (4, 5, 20, 14, 32, 22, 38, 43)
x, y = np.array(x), np.array(y)

model = LinearRegression().fit(x, y)

test_x = np.array((5, 20, 14, 32, 22, 38))
model.predict(test_x.reshape(-1,1))
ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 2 is different from 1)

Is there any way to achieve this?