Pylint fixes for gamestonk_terminal/prediction_techniques/knn.py and neural_networks.py

This commit is contained in:
Artem Veremey
2021-03-02 20:05:22 -08:00
parent 66f4b2f50a
commit 3df20efc03
2 changed files with 38 additions and 32 deletions

View File

@@ -1,21 +1,23 @@
import argparse
import numpy as np
from gamestonk_terminal.helper_funcs import *
import pandas as pd
import matplotlib.pyplot as plt
import pandas as pd
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
from sklearn import neighbors
from TimeSeriesCrossValidation import splitTrain
from gamestonk_terminal.helper_funcs import check_positive, get_next_stock_market_days
register_matplotlib_converters()
# ----------------------------------------------------- kNN -----------------------------------------------------
# pylint: disable=unused-argument
def k_nearest_neighbors(l_args, s_ticker, s_interval, df_stock):
parser = argparse.ArgumentParser(
prog="knn",
description=""" K nearest neighbors is a simple algorithm that stores all
available cases and predict the numerical target based on a similarity measure
(e.g. distance functions). """,
description="""
K nearest neighbors is a simple algorithm that stores all
available cases and predict the numerical target based on a similarity measure
(e.g. distance functions).
""",
)
parser.add_argument(
@@ -108,7 +110,7 @@ def k_nearest_neighbors(l_args, s_ticker, s_interval, df_stock):
plt.axvspan(
df_stock.index[-1], df_pred.index[-1], facecolor="tab:orange", alpha=0.2
)
xmin, xmax, ymin, ymax = plt.axis()
_, _, ymin, ymax = plt.axis()
plt.vlines(
df_stock.index[-1], ymin, ymax, linewidth=1, linestyle="--", color="k"
)
@@ -120,5 +122,6 @@ def k_nearest_neighbors(l_args, s_ticker, s_interval, df_stock):
print(df_pred.to_string())
print("")
except:
except Exception as e:
print(e)
print("")

View File

@@ -1,14 +1,11 @@
import argparse
from gamestonk_terminal.helper_funcs import *
import pandas as pd
import os
from warnings import simplefilter
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
from TimeSeriesCrossValidation import splitTrain
from sklearn.preprocessing import MinMaxScaler, StandardScaler
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import (
@@ -16,19 +13,19 @@ from tensorflow.keras.layers import (
SimpleRNN,
Dense,
Dropout,
Activation,
RepeatVector,
TimeDistributed,
# Activation,
# RepeatVector,
# TimeDistributed,
)
from gamestonk_terminal.helper_funcs import check_positive, get_next_stock_market_days
from gamestonk_terminal import config_neural_network_models as cfg_nn_models
import os
register_matplotlib_converters()
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
from warnings import simplefilter
simplefilter(action="ignore", category=FutureWarning)
@@ -38,7 +35,7 @@ def build_neural_network_model(Recurrent_Neural_Network, n_inputs, n_days):
for idx_layer, d_layer in enumerate(Recurrent_Neural_Network):
# Recurrent Neural Network
if str(*d_layer) is "SimpleRNN":
if str(*d_layer) == "SimpleRNN":
# Is this the input layer? If so, define input_shape
if idx_layer == 0:
model.add(SimpleRNN(**d_layer["SimpleRNN"], input_shape=(n_inputs, 1)))
@@ -49,7 +46,7 @@ def build_neural_network_model(Recurrent_Neural_Network, n_inputs, n_days):
model.add(SimpleRNN(**d_layer["SimpleRNN"]))
# Long-Short Term-Memory
elif str(*d_layer) is "LSTM":
elif str(*d_layer) == "LSTM":
# Is this the input layer? If so, define input_shape
if idx_layer == 0:
model.add(LSTM(**d_layer["LSTM"], input_shape=(n_inputs, 1)))
@@ -60,7 +57,7 @@ def build_neural_network_model(Recurrent_Neural_Network, n_inputs, n_days):
model.add(LSTM(**d_layer["LSTM"]))
# Dense (Simple Neuron)
elif str(*d_layer) is "Dense":
elif str(*d_layer) == "Dense":
# Is this the input layer? If so, define input_shape
if idx_layer == 0:
model.add(Dense(**d_layer["Dense"], input_dim=n_inputs))
@@ -71,7 +68,7 @@ def build_neural_network_model(Recurrent_Neural_Network, n_inputs, n_days):
model.add(Dense(**d_layer["Dense"]))
# Dropout (Regularization)
elif str(*d_layer) is "Dropout":
elif str(*d_layer) == "Dropout":
model.add(Dropout(**d_layer["Dropout"]))
else:
@@ -81,6 +78,7 @@ def build_neural_network_model(Recurrent_Neural_Network, n_inputs, n_days):
# -------------------------------------------------- MLP --------------------------------------------------
# pylint: disable=unused-argument
def mlp(l_args, s_ticker, s_interval, df_stock):
parser = argparse.ArgumentParser(
prog="mlp", description="""Multilayer Perceptron. """
@@ -250,7 +248,7 @@ def mlp(l_args, s_ticker, s_interval, df_stock):
plt.axvspan(
df_stock.index[-1], df_pred.index[-1], facecolor="tab:orange", alpha=0.2
)
xmin, xmax, ymin, ymax = plt.axis()
_, _, ymin, ymax = plt.axis()
plt.vlines(
df_stock.index[-1],
ymin,
@@ -268,11 +266,13 @@ def mlp(l_args, s_ticker, s_interval, df_stock):
print(df_pred.to_string())
print("")
except:
except Exception as e:
print(e)
print("")
# -------------------------------------------------- RNN --------------------------------------------------
# pylint: disable=unused-argument
def rnn(l_args, s_ticker, s_interval, df_stock):
parser = argparse.ArgumentParser(
prog="rnn", description="""Recurrent Neural Network. """
@@ -442,7 +442,7 @@ def rnn(l_args, s_ticker, s_interval, df_stock):
plt.axvspan(
df_stock.index[-1], df_pred.index[-1], facecolor="tab:orange", alpha=0.2
)
xmin, xmax, ymin, ymax = plt.axis()
_, _, ymin, ymax = plt.axis()
plt.vlines(
df_stock.index[-1],
ymin,
@@ -460,11 +460,13 @@ def rnn(l_args, s_ticker, s_interval, df_stock):
print(df_pred.to_string())
print("")
except:
except Exception as e:
print(e)
print("")
# -------------------------------------------------- LSTM --------------------------------------------------
# pylint: disable=unused-argument
def lstm(l_args, s_ticker, s_interval, df_stock):
parser = argparse.ArgumentParser(
prog="lstm", description="""Long-Short Term Memory. """
@@ -634,7 +636,7 @@ def lstm(l_args, s_ticker, s_interval, df_stock):
plt.axvspan(
df_stock.index[-1], df_pred.index[-1], facecolor="tab:orange", alpha=0.2
)
xmin, xmax, ymin, ymax = plt.axis()
_, _, ymin, ymax = plt.axis()
plt.vlines(
df_stock.index[-1],
ymin,
@@ -652,5 +654,6 @@ def lstm(l_args, s_ticker, s_interval, df_stock):
print(df_pred.to_string())
print("")
except:
except Exception as e:
print(e)
print("")