Oct-27-2017, 07:52 PM
(This post was last modified: Oct-27-2017, 07:52 PM by BlackHeart.)
(Oct-27-2017, 04:45 PM)Larz60+ Wrote: what is the name of your program?
The error was generated in validation.py, line 433, but what caused it will be the last line mentioned with your program name on it.
Well I've been making a new file and renaming it each time I make a change the code, so that if something doesn't work I can always regress back to where I was. I keep changing the name ann1a,ann1b,ann1c,ann1-keras1a, etc, etc. I have it all stored in the same project folder.
I actually think I may have gotten it to work last night! I changed header from header=none to header=1 and it seemed to realize that 'Close' was a part of the column headers.
before:
# load dataset dataframe = pandas.read_csv("PTNprice.csv", delim_whitespace=True, header=none, usecols=[1,2,3,4]) dataset = dataframe.values # split into input (X) and output (Y) variables X = dataset[:,0:4] Y = dataset[:,1]after:
# load dataset dataframe = pandas.read_csv("PTNprice.csv", delim_whitespace=True, header=1, usecols=[1,2,3,4]) dataset = dataframe.values # split into input (X) and output (Y) variables X = dataset[:,0:4] Y = dataset[:,1]I'm starting to reach my limits with this code though, since I've only been coding with python for a few days now. I don't think I'm getting the output to come out correctly, and I don't understand it enough to fix it. I think its returning a 0.00% accuracy and I don't understand its predictions. I'm trying to get it to crunch 4 columns Open,High,Low,Close and then predict the next Close number.
output:
Larger: 0.00 (0.00) MSE [ 0.78021598 0.79241288 0.81000006 ..., 3.64232779 3.59621549 3.79605269]Here's my code in its entirety:
import numpy import pandas from keras.models import Sequential from keras.layers import Dense from keras.wrappers.scikit_learn import KerasRegressor from sklearn.model_selection import cross_val_score from sklearn.model_selection import KFold from sklearn.preprocessing import StandardScaler from sklearn.pipeline import Pipeline # load dataset dataframe = pandas.read_csv("PTNprice.csv", delim_whitespace=True, header=1, usecols=[1,2,3,4]) dataset = dataframe.values # split into input (X) and output (Y) variables X = dataset[:,0:4] Y = dataset[:,1] # define the model def larger_model(): # create model model = Sequential() model.add(Dense(100, input_dim=4, kernel_initializer='normal', activation='relu')) model.add(Dense(50, kernel_initializer='normal', activation='relu')) model.add(Dense(1, kernel_initializer='normal')) # Compile model model.compile(loss='mean_squared_error', optimizer='sgd') return model # fix random seed for reproducibility seed = 7 numpy.random.seed(seed) numpy.random.seed(seed) estimators = [] estimators.append(('standardize', StandardScaler())) estimators.append(('mlp', KerasRegressor(build_fn=larger_model, epochs=100, batch_size=5, verbose=0))) pipeline = Pipeline(estimators) kfold = KFold(n_splits=10, random_state=seed) results = cross_val_score(pipeline, X, Y, cv=kfold) print("Larger: %.2f (%.2f) MSE" % (results.mean(), results.std())) pipeline.fit(X, Y) prediction = pipeline.predict(X) print predictionquick edit:
Maybe the prediction is suppose to be for Y instead of X right because Y is the output layer?
pipeline.fit(X, Y) prediction = pipeline.predict(X) print prediction
pipeline.fit(X, Y) prediction = pipeline.predict(Y) print prediction