0

I am trying to create an Linear Regression model in python . code is as follow

time_values = np.linspace(1,23,23) # print from 1,2...23
number_of_clients = [] # create empty list that will hold number of clients
for i in range(1,24,1):
    rand_vlaue = random.randint(1,20) # generate number of clients
    number_of_clients.append(rand_vlaue)

print time_values
print number_of_clients

model = LinearRegression()
model.fit(time_values,number_of_clients)
model.predict(24)

I am getting the following error while running

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.
Amarjit Dhillon
  • 2,476
  • 3
  • 22
  • 56
  • 1
    Use `time_values.reshape(-1,1)` inside fit – Bharath Nov 19 '17 at 07:22
  • using time_vlaues.reshape(-1,1) or time_vlaues.reshape(1,-1) did not solved the issue – Amarjit Dhillon Nov 19 '17 at 07:26
  • Well when I ran it worked without errors. It maybe because of your variable name `time_vlaues`. Reshaping (1,-1) should not be done. Read more about reshaping here https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.reshape.html. – Bharath Nov 19 '17 at 07:27
  • it worked, when I used it inside `fit()` but did not work if I use `reshape` before `fit()`. any idea , why? – Amarjit Dhillon Nov 19 '17 at 07:33
  • 1
    You need to assign it time_values = time_values.reshape(-1,1) since its not an inplace operation – Bharath Nov 19 '17 at 07:34

0 Answers0