<jupyter_start><jupyter_text>US STOCK PREDICTION--By : Yehezk34We try to create a model to predict those stocks that in buy-worthy or not buy-worthy<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sbn
dataframe1 = pd.read_csv("2014_Financial_Data.csv")
dataframe2 = pd.read_csv("2015_Financial_Data.csv")
dataframe3 = pd.read_csv("2016_Financial_Data.csv")
dataframe4 = pd.read_csv("2017_Financial_Data.csv")
dataframe5 = pd.read_csv("2018_Financial_Data.csv")
# Concat all dataset!
dataFrame = pd.concat([dataframe1,dataframe2,dataframe3,dataframe4,dataframe5], axis=0)
dataFrame.describe()
dataFrame.head()
cols = list(dataFrame)
new_columns = (dataFrame.columns.drop("Class").tolist()) + ["Class"]
dataFrame = dataFrame[new_columns]

dataFrame.corr()["Class"].sort_values()
dataFrame.isnull().sum()
dataFrame = dataFrame.fillna(dataFrame.mean())
dataFrame.isnull().sum()
# Count the Sector!
sector = dataFrame['Sector'].value_counts()
sbn.barplot(np.arange(len(sector)), sector)
plt.xticks(np.arange(len(sector)), sector.index.values.tolist(), rotation=90)
plt.title('SECTORS COUNT', fontsize=15)
plt.show()
from sklearn.preprocessing import LabelEncoder

categorical_cols = ["Corporation","Sector"] 
le = LabelEncoder()
dataFrame[categorical_cols] = dataFrame[categorical_cols].apply(lambda col: le.fit_transform(col))
dataFrame.head()
# Now split them!
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler # For feature scaling!

X = dataFrame.iloc[:, :-1].values
y = dataFrame.iloc[:, -1].values
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
X_train
X_test
y_train
y_test
# Now create the model!
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Activation, Dropout
from tensorflow.keras.callbacks import EarlyStopping

model = Sequential()

model.add(Dense(units=70,activation = "relu"))
model.add(Dropout(0.6))
model.add(Dense(units=60,activation = "relu"))
model.add(Dropout(0.6))
model.add(Dense(units=50,activation = "relu"))
model.add(Dropout(0.6))
model.add(Dense(units=1,activation = "sigmoid"))

model.compile(loss="binary_crossentropy",optimizer = "adam")
earlyStopping = EarlyStopping(monitor="val_loss",mode="min",verbose=1,patience=25)
model.fit(x=X_train, y=y_train, epochs = 170, validation_data = (X_test,y_test), verbose = 1, callbacks=[earlyStopping])
loss = pd.DataFrame(model.history.history)
loss.plot()
# Predict your model!
from sklearn.metrics import classification_report, confusion_matrix,accuracy_score
y_pred = model.predict_classes(X_test)
y_pred = y_pred.reshape(len(y_test),)
cm = confusion_matrix(y_test,y_pred)
print(classification_report(y_test,y_pred))
print(confusion_matrix(y_test,y_pred))
print("Test accuracy :",accuracy_score(y_test, y_pred))
# Done<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13355371900826446, 'fraction_numerical': 0.020826446280991735, 'mean_word_length': 8.141993957703928, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '627451', 'license': 'Apache-2.0', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1060, 'n_words': 201, 'path': 'US_Stock_Prediction/US_Stock_Pediction_TF.ipynb', 'repo_name': 'Nub-Team/Simple_Production', 'size': '3025'}