Value error array with 0 features in linear regression scikit
$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.
machine-learning scikit-learn linear-regression
$endgroup$
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
$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.
machine-learning scikit-learn linear-regression
$endgroup$
bumped to the homepage by Community♦ yesterday
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
add a comment |
$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.
machine-learning scikit-learn linear-regression
$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
machine-learning scikit-learn linear-regression
asked Jul 11 '18 at 19:25
FabioSpaghettiFabioSpaghetti
1244
1244
bumped to the homepage by Community♦ yesterday
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♦ yesterday
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
add a comment |
$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
add a comment |
1 Answer
1
active
oldest
votes
$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
$endgroup$
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
$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
$endgroup$
add a comment |
$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
$endgroup$
add a comment |
$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
$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
answered Jul 12 '18 at 12:04
Valentin CalommeValentin Calomme
1,315423
1,315423
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
$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