I am a college student who has just started learning Python and doesn't have a lot of coding experience and have been experimenting with TensorFlow out of curiosity. I know that I should become more fluent in learning python before attempting such an ambitious project, but I really want to learn about this experimentally.
So my goal is to take a pre-formatted CSV that has the RSI, RS, MACD, and signal of a stock, and then also if the price of that stock increase the next day (in relation to the prvious day). Wether or not it increased is represented by a 1 or a 0 (1 being an increase, 0 being no change or decrease) so everything is an integer. What I am trying to find is what combination of these indicators leads to the increase. The increase or not is indicated by the class.
So far I have trained the model and tested my test set and gotten it to be 89% accurate, but what I am trying to do is print the combination of values that it found led to the increase. So how might I print the Spy_features that result in Spy_label(class) =1, from the already trained model that has been calculated?
If anymore information is needed, I will gladly provide it, I just feel like I've hit a wall with this aspect of my first project. Most of all I really would like to learn more about Python and machine learning, so a more explanation of how to go about something like this would be greatly appreciated.
import tensorflow as tf
import numpy as np
import pandas as pd
from tensorflow.keras import layers
from tensorflow.keras.layers.experimental import preprocessing
import matplotlib.pyplot as plt
from IPython.display import clear_output
from six.moves import urllib
#Data files
SPY_Training = pd.read_csv(r'C:UsersmatthDownloadsSpy_training(noheader).csv',names=["RSI","RS","MACD","signal","Class"])
SPY_Test = pd.read_csv(r'C:UsersmatthDownloadsSpy_test(noheader).csv',names=["RSI","RS","MACD","signal","Class"])
SPY_Test.shape[0], SPY_Training.shape[0]
SPY_Training.head()
SpyTest_features = SPY_Test.copy()
SpyTest_labels = SpyTest_features.pop('Class')
Spy_features = SPY_Training.copy()
Spy_labels = Spy_features.pop('Class')
Spy_features = np.array(Spy_features)
Spy_features
print(Spy_features)
Spy_model = tf.keras.Sequential([
layers.Dense(64),
layers.Dense(1)
])
Spy_model.compile(loss = tf.losses.MeanSquaredError(),
optimizer= tf.optimizers.Adam(), metrics=['accuracy'])
Spy_model.fit(Spy_features, Spy_labels, epochs=10)
test_loss, test_acc = Spy_model.evaluate(SpyTest_features, SpyTest_labels, verbose=2)
print('Test accuracy:', test_acc)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…