Python Forum
Keras.Predict into Dataframe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keras.Predict into Dataframe
#1
Hallo.

i'm working with multiple machine learning models.
I want to have all my predictions into a dataframe. The following is working for my other ml scripts(sklearn), expect for this one where i use Kera library.
It return the error: 'Exception: Data must be 1-dimensional'
My DataFrame for all my features is called 'feature_list' and all my targets is 'target_list'
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import statsmodels.api as sm
import keras 
import tensorflow as tf
from keras.models import Sequential
from keras.layers import Dense
from sklearn.metrics import r2_score

period = df['2011-01-01':'2015-01-01']
X = np.array(period[feature_list])
predictions = pd.DataFrame()
for i in target_list:
    y = np.array(period[i])
    split = sm.add_constant(X)
    train_size = int(0.75*y.shape[0])

    train_features = X[:train_size]
    train_targets = y[:train_size]
    test_features = X[train_size:]
    test_targets = y[train_size:]

    model = Sequential()
    model.add(Dense(5,input_dim=train_features.shape[1],activation='relu'))
    model.add(Dense(5,activation='relu'))
    model.add(Dense(1,activation='linear'))
    model.compile(optimizer='adam', loss='mse')
    model.fit(X, y, epochs=5, verbose=0)
    print(i)
    predictions[i] = model.predict(X[train_size:])
if i remove '[i]' in 'predictions[i] = model.predict(X[train_size:])' in return some values, so i think the mistake is in the compiling in some way.

So how do i compile all my predictions into a dataframe for all my targets?

Best regards Fynpyth from Denmark.
Reply


Messages In This Thread
Keras.Predict into Dataframe - by Finpyth - Mar-13-2020, 04:57 PM
RE: Keras.Predict into Dataframe - by jefsummers - Mar-13-2020, 05:25 PM
RE: Keras.Predict into Dataframe - by Finpyth - Mar-13-2020, 05:53 PM
RE: Keras.Predict into Dataframe - by jefsummers - Mar-14-2020, 02:24 AM
RE: Keras.Predict into Dataframe - by Finpyth - Mar-14-2020, 10:39 AM
RE: Keras.Predict into Dataframe - by jefsummers - Mar-14-2020, 11:45 AM
RE: Keras.Predict into Dataframe - by Finpyth - Mar-14-2020, 01:30 PM
RE: Keras.Predict into Dataframe - by jefsummers - Mar-14-2020, 04:22 PM
RE: Keras.Predict into Dataframe - by Finpyth - Mar-15-2020, 12:57 PM
RE: Keras.Predict into Dataframe - by jefsummers - Mar-15-2020, 01:01 PM
RE: Keras.Predict into Dataframe - by Finpyth - Mar-15-2020, 01:39 PM
RE: Keras.Predict into Dataframe - by jefsummers - Mar-15-2020, 04:40 PM
RE: Keras.Predict into Dataframe - by Finpyth - Mar-15-2020, 06:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to use .predict() method Jack90_ 4 769 Nov-03-2023, 08:21 PM
Last Post: Larz60+
  How to predict Total Hours needed with List as Input? caninan 0 789 Jan-27-2023, 04:20 PM
Last Post: caninan
  1st layer tf.keras output shape set at multiple - need help! Afrodizzyjack 0 1,826 Jun-07-2022, 04:53 PM
Last Post: Afrodizzyjack
  issue displaying summary of whole keras CNN model on TensorFlow with python Afrodizzyjack 0 1,657 Oct-27-2021, 04:07 PM
Last Post: Afrodizzyjack
  Which network architecture should be chosen to predict disease severity? AlekseyPython 2 2,004 Aug-21-2021, 07:12 PM
Last Post: jefsummers
  How to predict output in a regression problem? Rezaafz 1 2,506 Apr-03-2021, 04:16 PM
Last Post: jefsummers
  Understanding Keras and TensorFlow and how to use them bytecrunch 1 2,078 Mar-11-2021, 02:40 PM
Last Post: jefsummers
  Problems feeding live input from my microphone into a keras model (SegFault: 11) zeptozetta 1 2,588 Sep-14-2020, 03:08 AM
Last Post: zeptozetta
  Making a Basic Keras Model - Input Shape and Parameters MattKahn13 0 2,120 Aug-16-2020, 04:36 PM
Last Post: MattKahn13
  Analyze, predict the next step in a sequence. Antonio0608 0 2,019 Jul-23-2020, 05:53 PM
Last Post: Antonio0608

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020