def run(self, train, predict):
        if self.check_parameters() == False:
            raise IndexError('Parameters is wrong, check out_class_type')
            return

        ################################################################################
        self.paras.save_folder = self.get_save_directory()
        print('Save Directory: ', self.paras.save_folder)
        self.paras.model_folder = self.get_model_directory()
        print('Model Directory: ', self.paras.model_folder)
        ################################################################################

        LabelColumnName = 'label'

        for index in range(len(self.paras.window_len)):

            data_feature = get_all_stocks_feature_data(
                self.paras, self.paras.window_len[index], LabelColumnName)

            model = None

            if train:
                model = self.train_data(data_feature, LabelColumnName, index)

            if predict:
                self.predict_data(model, data_feature, LabelColumnName, index)
    def run(self, train, predict):
        ################################################################################
        self.paras.save_folder = self.get_save_directory()
        print(' Log  Directory: ', self.paras.save_folder)
        self.paras.model_folder = self.get_model_directory()
        print('Model Directory: ', self.paras.model_folder)
        ################################################################################

        LabelColumnName = 'label'

        data_feature = get_all_stocks_feature_data(self.paras,
                                                   self.paras.window_len,
                                                   LabelColumnName)

        model = None

        if train: model = self.train_data(data_feature, LabelColumnName)

        if predict: self.predict_data(model, data_feature, LabelColumnName)
Exemplo n.º 3
0
    def do_run(self, train, predict, window):
        LabelColumnName = 'label'
        data_file = "data_file_lstm_" + str(window) + ".pkl"

        if os.path.exists(data_file):
            input = open(data_file, 'rb')
            data_feature = pickle.load(input)
            input.close()
        else:
            data_feature = get_all_stocks_feature_data(self.paras, window, LabelColumnName)
            output = open(data_file, 'wb')
            pickle.dump(data_feature, output)
            output.close()

        model = None
            
        if train: model = self.train_data(data_feature, window, LabelColumnName)
            
        if predict: self.predict_data(model, data_feature, window, LabelColumnName)
Exemplo n.º 4
0
    def run(self, train, predict):
        ################################################################################
        self.paras.save_folder = self.get_save_directory()
        print('Save Directory: ', self.paras.save_folder)
        self.paras.model_folder = self.get_model_directory()
        print('Model Directory: ', self.paras.model_folder)
        ################################################################################

        LabelColumnName = 'label'

        for index in range(len(self.paras.window_len)):

            data_feature = get_all_stocks_feature_data(
                self.paras, self.paras.window_len[index], LabelColumnName)

            model = None

            if train:
                model = self.train_data(data_feature, LabelColumnName, index)

            if predict:
                self.predict_data(model, data_feature, LabelColumnName, index)


# style.use("fivethirtyeight")
# pd.set_option('precision', 3)
# pd.set_option('display.width',1000)

#Read the csv file into a DataFrame
# df = pd.read_csv("Tesla_stocks.csv")

#Make two new columns which will be used for making predictions.
# df["HL_Perc"] = (df["High"]-df["Low"]) / df["Low"] * 100
# df["CO_Perc"] = (df["Close"] - df["Open"]) / df["Open"] * 100

#Make array of dates
#Last 30 dates will be used for forecasting.
# dates = np.array(df["Date"])
# dates_check = dates[-30:]
# dates = dates[:-30]

# df = df[["HL_Perc", "CO_Perc", "Adj Close", "Volume"]]

#Define the label column

#Make fetaure and label arrays

#Divide the data set into training data and testing data
# X_train, X_test, y_train, y_test = train_test_split(X,y,test_size = 0.3)

# #Define the prediction model
# model = RandomForestRegressor()

# #Fit the model using training data
# model.fit(X_train, y_train)

# #Calculate the confidence value by applying the model to testing data
# conf = model.score(X_test, y_test)
# print(conf)

# #Fit the model again using the whole data set
# model.fit(X,y)

# #Make predictions
# predictions = model.predict(X_Check)

#Make the final DataFrame containing Dates, ClosePrices, and Forecast values
# actual = pd.DataFrame(dates, columns = ["Date"])
# actual["ClosePrice"] = df["Adj Close"]
# actual["Forecast"] = np.nan
# actual.set_index("Date", inplace = True)
# forecast = pd.DataFrame(dates_check, columns=["Date"])
# forecast["Forecast"] = predictions
# forecast.set_index("Date", inplace = True)
# var = [actual, forecast]
# result = pd.concat(var)  #This is the final DataFrame

# #Plot the results
# result.plot(figsize=(20,10), linewidth=1.5)
# plt.legend(loc=2, prop={'size':20})
# plt.xlabel('Date')
# plt.ylabel('Price')