How to do add and subtraction in between three inputs for predict the value using python
$begingroup$
This question is related to this unsupported operand type(s) for -: 'list' and 'list' using python
I want to predict value according to the three inputs(X1,X2,X3) . for prediction value,
three inputs
X1-X2+X3 = predict value
according to this algorithm value will be predicted using LSTM neural network. I wrote the code but it gives me so many errors. Can anyone suggest me to solve this error?
here is my code:
data.columns = ['X1', 'X2', 'X3','Y']
data = data.dropna ()
y =data['Y'].astype(int)
cols=['X1', 'X2', 'X3']
x=data[cols].astype(int)
scaler_x = preprocessing.MinMaxScaler(feature_range =(-1, 1))
x = np.array(x).reshape ((len(x),3 ))
x = scaler_x.fit_transform(x)
scaler_y = preprocessing.MinMaxScaler(feature_range =(-1, 1))
y = np.array(y).reshape ((len(y), 1))
y = scaler_y.fit_transform(y)
n = data.shape[0]
p = data.shape[1]
data = data.values
a =
for i in range(0,len(data)):
X1 = data[i][0]
a.append([X1])
b =
for i in range(0,len(data)):
X2 = data[i][1]
b.append([X2])
c =
for i in range(0,len(data)):
X3 = data[i][2]
c.append([X3])
train_start = 0
train_end = int(np.floor(0.8*n))
test_start = train_end+1
test_end = n
x_train = x[np.arange(train_start, train_end), :]
x_test = x[np.arange(test_start, test_end), :]
y_train = y[np.arange(train_start, train_end), :]
y_test = y[np.arange(test_start, test_end), :]
x_train=x_train.reshape(x_train.shape +(1,))
x_test=x_test.reshape(x_test.shape + (1,))
for i in range(len(x_train)):
x_train.append([a[i] ,b[i], c[i]])
x.append((a[i][0] - b[i][0] + c[i][0]))
x_train =np.array(x_train)
x = np.array(x)
seed = 20
np.random.seed(seed)
fit1 = Sequential ()
fit1.add(LSTM(
output_dim = 5,
activation='relu',
input_shape =(3,1)))
fit1.add(Dense(output_dim =1))
fit1.add(Activation(linear))
batchsize = 1
fit1.compile(loss="mean_squared_error",optimizer="adam")
#train the model
fit1.fit(x_train , y_train , batch_size = batchsize, nb_epoch =1, shuffle=True)
score_train = fit1.evaluate(x_train ,y_train ,batch_size =batchsize)
score_test = fit1.evaluate(x_test , y_test ,batch_size =batchsize)
#Make prediction
pred1=fit1.predict(x_test)
#data=pd.DataFrame(fit1.predict(x_test))
pred1 = scaler_y.inverse_transform(np.array(pred1).reshape ((len(pred1), 1)))
real_test = scaler_y.inverse_transform(np.array(y_test).reshape ((len(y_test)))
Here is my csv file;
python lstm
$endgroup$
add a comment |
$begingroup$
This question is related to this unsupported operand type(s) for -: 'list' and 'list' using python
I want to predict value according to the three inputs(X1,X2,X3) . for prediction value,
three inputs
X1-X2+X3 = predict value
according to this algorithm value will be predicted using LSTM neural network. I wrote the code but it gives me so many errors. Can anyone suggest me to solve this error?
here is my code:
data.columns = ['X1', 'X2', 'X3','Y']
data = data.dropna ()
y =data['Y'].astype(int)
cols=['X1', 'X2', 'X3']
x=data[cols].astype(int)
scaler_x = preprocessing.MinMaxScaler(feature_range =(-1, 1))
x = np.array(x).reshape ((len(x),3 ))
x = scaler_x.fit_transform(x)
scaler_y = preprocessing.MinMaxScaler(feature_range =(-1, 1))
y = np.array(y).reshape ((len(y), 1))
y = scaler_y.fit_transform(y)
n = data.shape[0]
p = data.shape[1]
data = data.values
a =
for i in range(0,len(data)):
X1 = data[i][0]
a.append([X1])
b =
for i in range(0,len(data)):
X2 = data[i][1]
b.append([X2])
c =
for i in range(0,len(data)):
X3 = data[i][2]
c.append([X3])
train_start = 0
train_end = int(np.floor(0.8*n))
test_start = train_end+1
test_end = n
x_train = x[np.arange(train_start, train_end), :]
x_test = x[np.arange(test_start, test_end), :]
y_train = y[np.arange(train_start, train_end), :]
y_test = y[np.arange(test_start, test_end), :]
x_train=x_train.reshape(x_train.shape +(1,))
x_test=x_test.reshape(x_test.shape + (1,))
for i in range(len(x_train)):
x_train.append([a[i] ,b[i], c[i]])
x.append((a[i][0] - b[i][0] + c[i][0]))
x_train =np.array(x_train)
x = np.array(x)
seed = 20
np.random.seed(seed)
fit1 = Sequential ()
fit1.add(LSTM(
output_dim = 5,
activation='relu',
input_shape =(3,1)))
fit1.add(Dense(output_dim =1))
fit1.add(Activation(linear))
batchsize = 1
fit1.compile(loss="mean_squared_error",optimizer="adam")
#train the model
fit1.fit(x_train , y_train , batch_size = batchsize, nb_epoch =1, shuffle=True)
score_train = fit1.evaluate(x_train ,y_train ,batch_size =batchsize)
score_test = fit1.evaluate(x_test , y_test ,batch_size =batchsize)
#Make prediction
pred1=fit1.predict(x_test)
#data=pd.DataFrame(fit1.predict(x_test))
pred1 = scaler_y.inverse_transform(np.array(pred1).reshape ((len(pred1), 1)))
real_test = scaler_y.inverse_transform(np.array(y_test).reshape ((len(y_test)))
Here is my csv file;
python lstm
$endgroup$
add a comment |
$begingroup$
This question is related to this unsupported operand type(s) for -: 'list' and 'list' using python
I want to predict value according to the three inputs(X1,X2,X3) . for prediction value,
three inputs
X1-X2+X3 = predict value
according to this algorithm value will be predicted using LSTM neural network. I wrote the code but it gives me so many errors. Can anyone suggest me to solve this error?
here is my code:
data.columns = ['X1', 'X2', 'X3','Y']
data = data.dropna ()
y =data['Y'].astype(int)
cols=['X1', 'X2', 'X3']
x=data[cols].astype(int)
scaler_x = preprocessing.MinMaxScaler(feature_range =(-1, 1))
x = np.array(x).reshape ((len(x),3 ))
x = scaler_x.fit_transform(x)
scaler_y = preprocessing.MinMaxScaler(feature_range =(-1, 1))
y = np.array(y).reshape ((len(y), 1))
y = scaler_y.fit_transform(y)
n = data.shape[0]
p = data.shape[1]
data = data.values
a =
for i in range(0,len(data)):
X1 = data[i][0]
a.append([X1])
b =
for i in range(0,len(data)):
X2 = data[i][1]
b.append([X2])
c =
for i in range(0,len(data)):
X3 = data[i][2]
c.append([X3])
train_start = 0
train_end = int(np.floor(0.8*n))
test_start = train_end+1
test_end = n
x_train = x[np.arange(train_start, train_end), :]
x_test = x[np.arange(test_start, test_end), :]
y_train = y[np.arange(train_start, train_end), :]
y_test = y[np.arange(test_start, test_end), :]
x_train=x_train.reshape(x_train.shape +(1,))
x_test=x_test.reshape(x_test.shape + (1,))
for i in range(len(x_train)):
x_train.append([a[i] ,b[i], c[i]])
x.append((a[i][0] - b[i][0] + c[i][0]))
x_train =np.array(x_train)
x = np.array(x)
seed = 20
np.random.seed(seed)
fit1 = Sequential ()
fit1.add(LSTM(
output_dim = 5,
activation='relu',
input_shape =(3,1)))
fit1.add(Dense(output_dim =1))
fit1.add(Activation(linear))
batchsize = 1
fit1.compile(loss="mean_squared_error",optimizer="adam")
#train the model
fit1.fit(x_train , y_train , batch_size = batchsize, nb_epoch =1, shuffle=True)
score_train = fit1.evaluate(x_train ,y_train ,batch_size =batchsize)
score_test = fit1.evaluate(x_test , y_test ,batch_size =batchsize)
#Make prediction
pred1=fit1.predict(x_test)
#data=pd.DataFrame(fit1.predict(x_test))
pred1 = scaler_y.inverse_transform(np.array(pred1).reshape ((len(pred1), 1)))
real_test = scaler_y.inverse_transform(np.array(y_test).reshape ((len(y_test)))
Here is my csv file;
python lstm
$endgroup$
This question is related to this unsupported operand type(s) for -: 'list' and 'list' using python
I want to predict value according to the three inputs(X1,X2,X3) . for prediction value,
three inputs
X1-X2+X3 = predict value
according to this algorithm value will be predicted using LSTM neural network. I wrote the code but it gives me so many errors. Can anyone suggest me to solve this error?
here is my code:
data.columns = ['X1', 'X2', 'X3','Y']
data = data.dropna ()
y =data['Y'].astype(int)
cols=['X1', 'X2', 'X3']
x=data[cols].astype(int)
scaler_x = preprocessing.MinMaxScaler(feature_range =(-1, 1))
x = np.array(x).reshape ((len(x),3 ))
x = scaler_x.fit_transform(x)
scaler_y = preprocessing.MinMaxScaler(feature_range =(-1, 1))
y = np.array(y).reshape ((len(y), 1))
y = scaler_y.fit_transform(y)
n = data.shape[0]
p = data.shape[1]
data = data.values
a =
for i in range(0,len(data)):
X1 = data[i][0]
a.append([X1])
b =
for i in range(0,len(data)):
X2 = data[i][1]
b.append([X2])
c =
for i in range(0,len(data)):
X3 = data[i][2]
c.append([X3])
train_start = 0
train_end = int(np.floor(0.8*n))
test_start = train_end+1
test_end = n
x_train = x[np.arange(train_start, train_end), :]
x_test = x[np.arange(test_start, test_end), :]
y_train = y[np.arange(train_start, train_end), :]
y_test = y[np.arange(test_start, test_end), :]
x_train=x_train.reshape(x_train.shape +(1,))
x_test=x_test.reshape(x_test.shape + (1,))
for i in range(len(x_train)):
x_train.append([a[i] ,b[i], c[i]])
x.append((a[i][0] - b[i][0] + c[i][0]))
x_train =np.array(x_train)
x = np.array(x)
seed = 20
np.random.seed(seed)
fit1 = Sequential ()
fit1.add(LSTM(
output_dim = 5,
activation='relu',
input_shape =(3,1)))
fit1.add(Dense(output_dim =1))
fit1.add(Activation(linear))
batchsize = 1
fit1.compile(loss="mean_squared_error",optimizer="adam")
#train the model
fit1.fit(x_train , y_train , batch_size = batchsize, nb_epoch =1, shuffle=True)
score_train = fit1.evaluate(x_train ,y_train ,batch_size =batchsize)
score_test = fit1.evaluate(x_test , y_test ,batch_size =batchsize)
#Make prediction
pred1=fit1.predict(x_test)
#data=pd.DataFrame(fit1.predict(x_test))
pred1 = scaler_y.inverse_transform(np.array(pred1).reshape ((len(pred1), 1)))
real_test = scaler_y.inverse_transform(np.array(y_test).reshape ((len(y_test)))
Here is my csv file;
python lstm
python lstm
asked 8 mins ago
kaskas
477
477
add a comment |
add a comment |
0
active
oldest
votes
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%2f45244%2fhow-to-do-add-and-subtraction-in-between-three-inputs-for-predict-the-value-usin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f45244%2fhow-to-do-add-and-subtraction-in-between-three-inputs-for-predict-the-value-usin%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