Mar-13-2020, 04:57 PM
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'
So how do i compile all my predictions into a dataframe for all my targets?
Best regards Fynpyth from Denmark.
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.