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 plot_results(history, with_acc=False): | |
| loss = history.history['loss'] | |
| val_loss = history.history['val_loss'] | |
| epochs = range(1, len(val_loss) + 1) | |
| plt.plot(epochs, loss, 'bo', label='Training loss') | |
| plt.plot(epochs, val_loss, 'b', label='Validation loss') | |
| plt.title('Training and validation loss') | |
| plt.legend() |
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.preprocessing import StandardScaler | |
| training_sameples = int(total_samples // 2) | |
| scaler = StandardScaler() | |
| unused_col = ['Id'] | |
| scaler.fit(df.drop(columns=unused_col).iloc[:training_sameples]) | |
| normalized_df = scaler.transform(df.drop(columns=unused_col)) |
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
| for col in categorical: | |
| df[col] = df[col].map(lambda x: str(x)) | |
| df = pd.get_dummies(df, drop_first=True) |
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 null_counts(df): | |
| null_counts = df.isnull().sum(axis = 0) / len(df) | |
| null_counts.plot.bar(figsize=(15, 4)) | |
| print(null_counts.sort_values(ascending=False).head(10)) |
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
| model = models.Sequential() | |
| model.add(layers.LSTM(32, return_sequences=True, | |
| input_shape=(num_timesteps, num_features))) | |
| model.add(layers.LSTM(32, return_sequences=True)) | |
| model.add(layers.LSTM(32)) | |
| model.add(layers.Dense(num_classes, activation='sigmoid')) | |
| model.compile(optimizer='rmsprop', loss='binary_crossentropy') |
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
| model = models.Sequential() | |
| model.add(layers.LSTM(32, input_shape=(num_timesteps, num_features))) | |
| model.add(layers.Dense(num_classes, activation='sigmoid')) | |
| model.compile(optimizer='rmsprop', loss='binary_crossentropy') |
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
| model = models.Sequential() | |
| model.add(layers.SeparableConv2D(32, 3, activation='relu', | |
| input_shape=(height, width, channels))) | |
| model.add(layers.SeparableConv2D(64, 3, activation='relu')) | |
| model.add(layers.MaxPooling2D(2)) | |
| model.add(layers.SeparableConv2D(64, 3, activation='relu')) | |
| model.add(layers.SeparableConv2D(128, 3, activation='relu')) | |
| model.add(layers.MaxPooling2D(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
| model = models.Sequential() | |
| model.add(layers.Dense(32, activation='relu', input_shape=(num_input_features,))) | |
| model.add(layers.Dense(32, activation='relu')) | |
| model.add(layers.Dense(num_values)) | |
| model.compile(optimizer='rmsprop', loss='mse') |
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
| model = models.Sequential() | |
| model.add(layers.Dense(32, activation='relu', input_shape=(num_input_features,))) | |
| model.add(layers.Dense(32, activation='relu')) | |
| model.add(layers.Dense(num_classes, activation='sigmoid')) | |
| model.compile(optimizer='rmsprop', loss='binary_crossentropy') | |
| # targets should be k-hot encoded |
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
| model = models.Sequential() | |
| model.add(layers.Dense(32, activation='relu', input_shape=(num_input_features,))) | |
| model.add(layers.Dense(32, activation='relu')) | |
| model.add(layers.Dense(num_classes, activation='softmax')) | |
| model.compile(optimizer='rmsprop', loss='categorical_crossentropy') |