# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# !pip install numpy

# +
import matplotlib.pyplot as plt
import pandas as pd


#import data
price_data = pd.read_csv('Input Data/Day Data/day_data_csv.csv')
price_data.dtypes

# +
#split into x and y 
X = price_data.drop("to buy", axis=1)
y = price_data["to buy"]

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=1/3, random_state=0)

# +
from sklearn.preprocessing import StandardScaler

# Create a StandardScater model and fit it to the training data
X_scaler = StandardScaler().fit(X_train)

X_train_scaled = X_scaler.transform(X_train)
X_test_scaled = X_scaler.transform(X_test)

# +
from keras.utils import to_categorical

# One-hot encoding
y_train_categorical = to_categorical(y_train)
y_test_categorical = to_categorical(y_test)

# +
from keras.models import Sequential
from keras.optimizers import SGD

model = Sequential()

from keras.layers import Dense
number_inputs = 15
number_hidden_nodes = 50
model.add(Dense(units=number_hidden_nodes,
                activation='relu', input_dim=number_inputs))

number_classes = 2

model.add(Dense(units=number_classes, activation='tanh'))

model.summary()
opt = SGD(lr=.01, momentum=.9)

model.compile(optimizer=opt,
              loss='squared_hinge',
              metrics=['accuracy'])
# -

model.fit(
    X_train_scaled,
    y_train_categorical,
    epochs=100,
    shuffle=True,
    verbose=2
)

# +
model_loss, model_accuracy = model.evaluate(
    X_test_scaled, y_test_categorical, verbose=2)
print(f"Loss: {model_loss}, Accuracy: {model_accuracy}")



# +
from sklearn.metrics import confusion_matrix
y_pred_test = model.predict_classes(X_test_scaled)
y_pred_train = model.predict_classes(X_train_scaled)

from sklearn.metrics import confusion_matrix, classification_report

test_cm = confusion_matrix(y_test, y_pred_test)
train_cm = confusion_matrix(y_train, y_pred_train)
print(test_cm)
print(train_cm)

test_cr = classification_report(y_test, y_pred_test)
train_cr = classification_report(y_train, y_pred_train)
print(test_cr)
print(train_cr)
# -



StarcoderdataJupyterScriptsDedupFiltered