Value error array with 0 features in linear regression scikit The 2019 Stack Overflow Developer Survey Results Are InDifference between OLS(statsmodel) and Scikit Linear RegressionSklearn Linear Regression examplesGeneralization error for simple linear regressionTensorflow regression predicting 1 for all inputsValueError while using linear regressionRemoving Categorial Features in Linear RegressionOrange Linear Regression and scikit-learn linear regression gives different resultsPredict the accuracy of Linear RegressionLinear Regression Error

It's possible to achieve negative score?

Inline version of a function returns different value then non-inline version

I looked up a future colleague on linkedin before I started a job. I told my colleague about it and he seemed surprised. Should I apologize?

aging parents with no investments

Why isn't airport relocation done gradually?

Patience, young "Padovan"

I see my dog run

Lethal sonic weapons

How to create dashed lines/arrows in Illustrator

How to deal with fear of taking dependencies

Why Did Howard Stark Use All The Vibranium They Had On A Prototype Shield?

Why do UK politicians seemingly ignore opinion polls on Brexit?

Time travel alters history but people keep saying nothing's changed

What do hard-Brexiteers want with respect to the Irish border?

JSON.serialize: is it possible to suppress null values of a map?

Is three citations per paragraph excessive for undergraduate research paper?

description of papers that have not been submitted to a venue?

Are there any other methods to apply to solving simultaneous equations?

On the insanity of kings as an argument against Monarchy

What is this 4-propeller plane?

Unbreakable Formation vs. Cry of the Carnarium

What are the advantages and disadvantages of running one shots compared to campaigns?

Access elements in std::string where positon of string is greater than its size

How was Skylab's orbit inclination chosen?



Value error array with 0 features in linear regression scikit



The 2019 Stack Overflow Developer Survey Results Are InDifference between OLS(statsmodel) and Scikit Linear RegressionSklearn Linear Regression examplesGeneralization error for simple linear regressionTensorflow regression predicting 1 for all inputsValueError while using linear regressionRemoving Categorial Features in Linear RegressionOrange Linear Regression and scikit-learn linear regression gives different resultsPredict the accuracy of Linear RegressionLinear Regression Error










1












$begingroup$


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)
x_train=[];x_t=[];y_train=[];y_t=[];x_test=[];x_ts=[];y_test=[];y_ts=[];
for i in range(le):
x_t = data1.iloc[i,:]
x_train.append(x_t)
y_t = data2.iloc[i,:]
y_train.append(y_t)
if i > le :
x_ts = data1.iloc[lg-i,:]
x_test.append(x_ts)
y_ts = data2.iloc[lg-i,:]
y_test.append(y_ts)



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

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


I get this error :




File
"C:ProgramDataAnaconda3libsite-packagesspyderutilssitesitecustomize.py",
line 880, in runfile
execfile(filename, namespace)



File
"C:ProgramDataAnaconda3libsite-packagesspyderutilssitesitecustomize.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:ProgramDataAnaconda3libsite-packagessklearnlinear_modelbase.py",
line 268, in predict
return self._decision_function(X)



File
"C:ProgramDataAnaconda3libsite-packagessklearnlinear_modelbase.py",
line 251, in _decision_function
X = check_array(X, accept_sparse=['csr', 'csc', 'coo'])



File
"C:ProgramDataAnaconda3libsite-packagessklearnutilsvalidation.py",
line 424, in check_array
context))



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











share|improve this question









$endgroup$




bumped to the homepage by Community 10 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • $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$
    – Valentin Calomme
    Jul 12 '18 at 12:05










  • $begingroup$
    I actually did it, that's a pity I didn't delete the question before your negative vote
    $endgroup$
    – FabioSpaghetti
    Jul 12 '18 at 12:06















1












$begingroup$


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)
x_train=[];x_t=[];y_train=[];y_t=[];x_test=[];x_ts=[];y_test=[];y_ts=[];
for i in range(le):
x_t = data1.iloc[i,:]
x_train.append(x_t)
y_t = data2.iloc[i,:]
y_train.append(y_t)
if i > le :
x_ts = data1.iloc[lg-i,:]
x_test.append(x_ts)
y_ts = data2.iloc[lg-i,:]
y_test.append(y_ts)



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

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


I get this error :




File
"C:ProgramDataAnaconda3libsite-packagesspyderutilssitesitecustomize.py",
line 880, in runfile
execfile(filename, namespace)



File
"C:ProgramDataAnaconda3libsite-packagesspyderutilssitesitecustomize.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:ProgramDataAnaconda3libsite-packagessklearnlinear_modelbase.py",
line 268, in predict
return self._decision_function(X)



File
"C:ProgramDataAnaconda3libsite-packagessklearnlinear_modelbase.py",
line 251, in _decision_function
X = check_array(X, accept_sparse=['csr', 'csc', 'coo'])



File
"C:ProgramDataAnaconda3libsite-packagessklearnutilsvalidation.py",
line 424, in check_array
context))



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











share|improve this question









$endgroup$




bumped to the homepage by Community 10 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • $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$
    – Valentin Calomme
    Jul 12 '18 at 12:05










  • $begingroup$
    I actually did it, that's a pity I didn't delete the question before your negative vote
    $endgroup$
    – FabioSpaghetti
    Jul 12 '18 at 12:06













1












1








1





$begingroup$


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)
x_train=[];x_t=[];y_train=[];y_t=[];x_test=[];x_ts=[];y_test=[];y_ts=[];
for i in range(le):
x_t = data1.iloc[i,:]
x_train.append(x_t)
y_t = data2.iloc[i,:]
y_train.append(y_t)
if i > le :
x_ts = data1.iloc[lg-i,:]
x_test.append(x_ts)
y_ts = data2.iloc[lg-i,:]
y_test.append(y_ts)



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

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


I get this error :




File
"C:ProgramDataAnaconda3libsite-packagesspyderutilssitesitecustomize.py",
line 880, in runfile
execfile(filename, namespace)



File
"C:ProgramDataAnaconda3libsite-packagesspyderutilssitesitecustomize.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:ProgramDataAnaconda3libsite-packagessklearnlinear_modelbase.py",
line 268, in predict
return self._decision_function(X)



File
"C:ProgramDataAnaconda3libsite-packagessklearnlinear_modelbase.py",
line 251, in _decision_function
X = check_array(X, accept_sparse=['csr', 'csc', 'coo'])



File
"C:ProgramDataAnaconda3libsite-packagessklearnutilsvalidation.py",
line 424, in check_array
context))



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











share|improve this question









$endgroup$




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)
x_train=[];x_t=[];y_train=[];y_t=[];x_test=[];x_ts=[];y_test=[];y_ts=[];
for i in range(le):
x_t = data1.iloc[i,:]
x_train.append(x_t)
y_t = data2.iloc[i,:]
y_train.append(y_t)
if i > le :
x_ts = data1.iloc[lg-i,:]
x_test.append(x_ts)
y_ts = data2.iloc[lg-i,:]
y_test.append(y_ts)



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

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


I get this error :




File
"C:ProgramDataAnaconda3libsite-packagesspyderutilssitesitecustomize.py",
line 880, in runfile
execfile(filename, namespace)



File
"C:ProgramDataAnaconda3libsite-packagesspyderutilssitesitecustomize.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:ProgramDataAnaconda3libsite-packagessklearnlinear_modelbase.py",
line 268, in predict
return self._decision_function(X)



File
"C:ProgramDataAnaconda3libsite-packagessklearnlinear_modelbase.py",
line 251, in _decision_function
X = check_array(X, accept_sparse=['csr', 'csc', 'coo'])



File
"C:ProgramDataAnaconda3libsite-packagessklearnutilsvalidation.py",
line 424, in check_array
context))



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








machine-learning scikit-learn linear-regression






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jul 11 '18 at 19:25









FabioSpaghettiFabioSpaghetti

1244




1244





bumped to the homepage by Community 10 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 10 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.













  • $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$
    – Valentin Calomme
    Jul 12 '18 at 12:05










  • $begingroup$
    I actually did it, that's a pity I didn't delete the question before your negative vote
    $endgroup$
    – FabioSpaghetti
    Jul 12 '18 at 12:06
















  • $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$
    – Valentin Calomme
    Jul 12 '18 at 12:05










  • $begingroup$
    I actually did it, that's a pity I didn't delete the question before your negative vote
    $endgroup$
    – FabioSpaghetti
    Jul 12 '18 at 12:06















$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$
– Valentin Calomme
Jul 12 '18 at 12:05




$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$
– Valentin Calomme
Jul 12 '18 at 12:05












$begingroup$
I actually did it, that's a pity I didn't delete the question before your negative vote
$endgroup$
– FabioSpaghetti
Jul 12 '18 at 12:06




$begingroup$
I actually did it, that's a pity I didn't delete the question before your negative vote
$endgroup$
– FabioSpaghetti
Jul 12 '18 at 12:06










1 Answer
1






active

oldest

votes


















1












$begingroup$

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






share|improve this answer









$endgroup$













    Your Answer





    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "557"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f34325%2fvalue-error-array-with-0-features-in-linear-regression-scikit%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1












    $begingroup$

    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






    share|improve this answer









    $endgroup$

















      1












      $begingroup$

      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






      share|improve this answer









      $endgroup$















        1












        1








        1





        $begingroup$

        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






        share|improve this answer









        $endgroup$



        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jul 12 '18 at 12:04









        Valentin CalommeValentin Calomme

        1,305423




        1,305423



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Data Science Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f34325%2fvalue-error-array-with-0-features-in-linear-regression-scikit%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Ружовы пелікан Змест Знешні выгляд | Пашырэнне | Асаблівасці біялогіі | Літаратура | НавігацыяДагледжаная версіяправерана1 зменаДагледжаная версіяправерана1 змена/ 22697590 Сістэматыкана ВіківідахВыявына Вікісховішчы174693363011049382

            ValueError: Error when checking input: expected conv2d_13_input to have shape (3, 150, 150) but got array with shape (150, 150, 3)2019 Community Moderator ElectionError when checking : expected dense_1_input to have shape (None, 5) but got array with shape (200, 1)Error 'Expected 2D array, got 1D array instead:'ValueError: Error when checking input: expected lstm_41_input to have 3 dimensions, but got array with shape (40000,100)ValueError: Error when checking target: expected dense_1 to have shape (7,) but got array with shape (1,)ValueError: Error when checking target: expected dense_2 to have shape (1,) but got array with shape (0,)Keras exception: ValueError: Error when checking input: expected conv2d_1_input to have shape (150, 150, 3) but got array with shape (256, 256, 3)Steps taking too long to completewhen checking input: expected dense_1_input to have shape (13328,) but got array with shape (317,)ValueError: Error when checking target: expected dense_3 to have shape (None, 1) but got array with shape (7715, 40000)Keras exception: Error when checking input: expected dense_input to have shape (2,) but got array with shape (1,)

            Illegal assignment from SObject to ContactFetching String, Id from Map - Illegal Assignment Id to Field / ObjectError: Compile Error: Illegal assignment from String to BooleanError: List has no rows for assignment to SObjectError on Test Class - System.QueryException: List has no rows for assignment to SObjectRemote action problemDML requires SObject or SObject list type error“Illegal assignment from List to List”Test Class Fail: Batch Class: System.QueryException: List has no rows for assignment to SObjectMapping to a user'List has no rows for assignment to SObject' Mystery