My input and output data are written in an 6xn row-column excel file,thatI read them using pandas

using this code :

from sklearn import linear_model
import os
import pandas as pd
import numpy as np
import openpyxl as pyx
import numpy as np
import matplotlib.pyplot as plt

path = r"E:\"
os.chdir( path )

data1 = pd.read_excel("input.xlsx", header=None,index=False)
data2 = pd.read_excel("target.xlsx", header=None,index=False)

# print df.head()

le= 20;lg=len(data1)
for i in range(le):    
    x_t = data1.iloc[i,:]
    y_t = data2.iloc[i,:]
    if i > le :
        x_ts = data1.iloc[lg-i,:]
        y_ts = data2.iloc[lg-i,:]

ols = linear_model.LinearRegression()
model = ols.fit(x_train, y_train)

print (model.predict(x_test)[0:5]) 

I get this error :

File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile execfile(filename, namespace)

File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "E:/Scikit-Learn.py", line 46, in print (model.predict(x_test)[0:5])

File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\linear_model\base.py", line 268, in predict return self._decision_function(X)

File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\linear_model\base.py", line 251, in _decision_function X = check_array(X, accept_sparse=['csr', 'csc', 'coo'])

File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 424, in check_array context))

ValueError: Found array with 0 feature(s) (shape=(1, 0)) while a minimum of 1 is required.

  • $\begingroup$ You should spend more time reading your error messages and do some more debugging work by printing out the values of your variables for instance, because this is an error you should be able to catch by yourself. $\endgroup$ Jul 12, 2018 at 12:05
  • $\begingroup$ I actually did it, that's a pity I didn't delete the question before your negative vote $\endgroup$ Jul 12, 2018 at 12:06

1 Answer 1


The error says that the array you feed into predict has shape=(1,0) meaning that it must be an empty iterable.

And by looking at your code, it's easy to see why. x_test starts of as empty, and in your code, the only way to add things to it is if i > le. But since your loop is defined as for i in range(le), by definition i will never be greater than le since the last value of range is le-1


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.