# ---
# 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
# ---

# +
from keras.models import model_from_json
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from keras.models import Sequential
from keras.layers import Dense, Conv2D, Flatten
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Convolution2D, MaxPooling2D

df = pd.read_csv('FinalData.csv')

X = df.drop(['Label'], axis = 1).values
Y = df['Label']

X = StandardScaler().fit_transform(X)

Xnew = []
for i in range(0, len(X), 250):
    Xnew.append(X[i:250+i])
    
Ynew = []
for j in range(0, 934750, 250):
    Ynew.append(0)
    
for k in range(0, 971750, 250):
    Ynew.append(1)
    
from itertools import groupby
print([len(list(group)) for key, group in groupby(Y)])

Xnew = np.array(Xnew)
print(Xnew[0].shape)
print(Xnew.shape)
#X = StandardScaler().fit_transform(Xnew)

X_train, X_test, y_train, y_test = train_test_split(Xnew, Ynew, test_size = 0.30, random_state = 101)

#reshape data to fit model
X_train = X_train.reshape(5338,250,128,1)
X_test = X_test.reshape(2288,250,128,1)

from keras.utils import to_categorical
#one-hot encode target column
y_train = to_categorical(y_train)
y_test = to_categorical(y_test)
y_train[0]

# +
# # later...

from keras.models import model_from_json

# # load json and create model
json_file = open('model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
# load weights into new model
loaded_model.load_weights("model.h5")
print("Loaded model from disk")
 
# # evaluate loaded model on test data
loaded_model.compile(loss='binary_crossentropy', optimizer='rmsprop', metrics=['accuracy'])
score = loaded_model.evaluate(X_test, y_test, verbose=0)
print(score)

StarcoderdataJupyterScriptsDedupFiltered