This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from matplotlib import pyplot as plt | |
import numpy as np | |
import pandas as pd | |
from scipy.stats import skew, kurtosis | |
from sklearn.decomposition import PCA | |
from sklearn.cluster import KMeans | |
def main(): | |
data = read_data() | |
normalized_data = normalize(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.cluster import KMeans | |
# fit K-Means | |
kmeans = KMeans(n_clusters=2) | |
kmeans.fit(extracted_features) | |
predictions = kmeans.predict(extracted_features) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def feature_extraction(signal_df, window_size=100, overlap=50): | |
num_components = signal_df.shape[1] | |
num_samples = signal_df.shape[0] | |
# used to rename columns in the extracted features (mentioning the statistical moment) | |
new_col_names_mean = dict() | |
new_col_names_std = dict() | |
new_col_names_skewness = dict() | |
new_col_names_kurtosis = dict() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def normalize(data): | |
data_norm = data.copy() | |
columns_for_normalization = ['x_acc','y_acc','z_acc', | |
'x_gravity', 'y_gravity', 'z_gravity', | |
'x_gyro', 'y_gyro', 'z_gyro'] | |
for column in columns_for_normalization: | |
data_norm[column] = (data_norm[column] - data_norm[column].mean()) / data_norm[column].std() | |
return data_norm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
def read_data(): | |
accelerometer_data = pd.read_csv('./data/Accelerometer.csv',header=0, names=['time','seconds_elapsed','z_acc','y_acc','x_acc']) | |
gyro_data = pd.read_csv('./data/Gyroscope.csv',header=0, names=['time','seconds_elapsed','z_gyro','y_gyro','x_gyro']) | |
gravity_data = pd.read_csv('./data/Gravity.csv',header=0, names=['time','seconds_elapsed','z_gravity','y_gravity','x_gravity']) | |
# drop columns that are common in all 3 dataframes and keep only the ones from the accelerometer dataframe | |
gyro_data = gyro_data.drop(['time','seconds_elapsed'],axis=1) | |
gravity_data = gravity_data.drop(['time','seconds_elapsed'],axis=1) |
We can make this file beautiful and searchable if this error is corrected: It looks like row 3 should actually have 33 columns, instead of 8 in line 2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
,batch,yeast,hop 1 name,hop 1 weight,hop 1 form,hop 1 phase,hop 1 time,hop 2 name,hop 2 weight,hop 2 form,hop 2 phase,hop 2 time,hop 3 name,hop 3 weight,hop 3 form,hop 3 phase,hop 3 time,hop 4 name,hop 4 weight,hop 4 form,hop 4 phase,hop 4 time,fermentable 1 weight,fermentable 1 name,fermentable 2 weight,fermentable 2 name,fermentable 3 weight,fermentable 3 name,fermentable 4 weight,fermentable 4 name,fermentable 5 weight,fermentable 5 name | |
0,18.309166931525436,White Labs - California Ale Yeast WLP001,Cluster,7.269675936122823,Pellet,First Wort,38.87988377656771,Zeus,17.583570003261514,Leaf/Whole,Dry Hop,13.42101097713062,Tettnanger,166.09849747403285,Pellet,First Wort,4.812608839959528,Northern Brewer,64.48508972798278,Pellet,Boil,4.7735462463325185,3.5972188703805634,American - Pale 2-Row,6.1346832837085135,United Kingdom - Munich,9.54155046053587,Flaked Oats,6.962939560440913,Flaked Oats,-0.0003344600787370782,0 | |
1,66.00718958026789,Escarpment Labs - Vermont Ale,Southern Cross,59.02688552767579,Pellet,Boil, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
discrete_columns = [ | |
'hop 1 form', | |
'hop 2 form', | |
'hop 3 form', | |
'hop 4 form', | |
'hop 1 phase', | |
'hop 2 phase', | |
'hop 3 phase', | |
'hop 4 phase', | |
'hop 1 name', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pick a random index from validation dataset | |
random_index = np.random.choice(range(len(X_val)), size=1) | |
test_serie_X = X_val[random_index[0]] | |
test_serie_Y = y_val[random_index[0]] | |
first_frames = test_serie_X | |
original_frames = test_serie_Y | |
# predict the next 18 fames | |
new_prediction = model.predict(np.expand_dims(first_frames, axis=0)) | |
new_prediction = np.squeeze(new_prediction, axis=0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_model(): | |
model = Sequential() | |
model.add(ConvLSTM2D(filters=64, kernel_size=(7, 7), | |
input_shape=(18,344,315,1), | |
padding='same',activation=LeakyReLU(alpha=0.01), return_sequences=True)) | |
model.add(BatchNormalization()) | |
model.add(ConvLSTM2D(filters=64, kernel_size=(5, 5), | |
padding='same',activation=LeakyReLU(alpha=0.01), return_sequences=True)) | |
model.add(BatchNormalization()) | |
model.add(ConvLSTM2D(filters=64, kernel_size=(3, 3), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_dataset_from_raw(directory_path, resize_to): | |
resize_width = resize_to[0] | |
resize_height = resize_to[1] | |
batch_names = [directory_path + name for name in os.listdir(directory_path) if os.path.isdir(os.path.join(directory_path, name))] | |
dataset = np.zeros(shape=(len(batch_names),36,resize_height,resize_width)) # (samples, filters, rows = height, cols = width) | |
for batch_idx,batch in enumerate(batch_names): | |
files = [x for x in os.listdir(batch) if x != '.DS_Store'] | |
files.sort() | |
crn_batch = np.zeros(shape=(36, resize_height, resize_width)) |
NewerOlder