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 simple_LSTM(): | |
np.random.seed(7) | |
model = Sequential(name = 'simple_LSTM') | |
model.add(LSTM(512, input_shape=(None, 6), recurrent_dropout=0.5)) | |
model.add(Dense(len(activities), activation='softmax')) | |
model.compile(loss='categorical_crossentropy', optimizer=Adam(lr=1e-4), metrics=['accuracy']) | |
print(model.summary()) | |
return model |
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
# Importing the Callbacks | |
from keras.callbacks import EarlyStopping | |
from keras.callbacks import TensorBoard | |
from keras.callbacks import ModelCheckpoint | |
# Saving logs | |
LOG_DIR = os.path.join(os.getcwd(), 'logs') | |
tb = TensorBoard(LOG_DIR) | |
# Saving weights | |
weights_dir = 'weights/' + model.name + \ | |
'-{epoch:02d}-{loss:.2f}.hdf5' |
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 categorical_summarized(dataframe, x=None, y=None, hue=None, palette='Set1', verbose=True): | |
''' | |
Helper function that gives a quick summary of a given column of categorical data | |
Arguments | |
========= | |
dataframe: pandas dataframe | |
x: str. horizontal axis to plot the labels of categorical data, y would be the count | |
y: str. vertical axis to plot the labels of categorical data, x would be the count | |
hue: str. if you want to compare it another variable (usually the target variable) |
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
# Target Variable: Survival | |
c_palette = ['tab:blue', 'tab:orange'] | |
categorical_summarized(train_df, y = 'Survived', palette=c_palette) |
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
# Feature Variable: Gender | |
categorical_summarized(train_df, y = 'Sex', hue='Survived', palette=c_palette) |
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 quantitative_summarized(dataframe, x=None, y=None, hue=None, palette='Set1', ax=None, verbose=True, swarm=False): | |
''' | |
Helper function that gives a quick summary of quantattive data | |
Arguments | |
========= | |
dataframe: pandas dataframe | |
x: str. horizontal axis to plot the labels of categorical data (usually the target variable) | |
y: str. vertical axis to plot the quantitative data | |
hue: str. if you want to compare it another categorical variable (usually the target variable if x is another variable) |
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
# univariate analysis | |
quantitative_summarized(dataframe= train_df, y = 'Age', palette=c_palette, verbose=False, swarm=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
# bivariate analysis with target variable | |
quantitative_summarized(dataframe= train_df, y = 'Age', x = 'Survived', palette=c_palette, verbose=False, swarm=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
# multivariate analysis with Embarked variable and Pclass variable | |
quantitative_summarized(dataframe= train_df, y = 'Age', x = 'Embarked', hue = 'Pclass', palette=c_palette3, verbose=False, swarm=False) |
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.ensemble import RandomForestClassifier | |
rf_clf = RandomForestClassifier(n_estimators = 500, max_depth=12) | |
rf_clf.fit(X_train, y_train) | |
rf_y_pred = rf_clf.predict(X_val) | |
pd.Series(rf_clf.feature_importances_, index = X_train.columns).nlargest(12).plot(kind = 'barh', | |
figsize = (10, 10), | |
title = 'Feature importance from RandomForest').invert_yaxis(); |
OlderNewer