Here is my scenarion.
data = [[25593.14, 39426.66],
[98411.00, 81869.75],
[71498.80, 62495.80],
[38068.00, 54774.00],
[58188.00, 43453.65],
[10220.00, 18465.25]]
About data is my data model.
x-cordinates refers "Salary" y-cordinates refers "Expenses"
I want to predict the expense when I give "Salary" i.e., X-coordinate.
Here is my sample code. Please help me out.
from sklearn.linear_model import LinearRegression
data = [[25593.14, 39426.66],
[98411.00, 81869.75],
[71498.80, 62495.80],
[38068.00, 54774.00],
[58188.00, 43453.65],
[10220.00, 18465.25]]
salary=[]
expenses=[]
for dataset in data:
# import pdb; pdb.set_trace()
salary.append(dataset[0])
expenses.append(dataset[1])
model = LinearRegression()
model.fit(salary, expenses)
prediction = model.predict([10200.00])
print(prediction)
Error which I got:
ValueError: Expected 2D array, got 1D array instead:
array=[ 25593.14 98411. 71498.8 38068. 58188. 10220. ].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample
.
model.fit(salary, expenses)is where the error is occurring, it expects a matrix of training data for the first argument, "X". This may help