Compiled from machine learning notes and handwritten notebooks in Bitbucket.
from keras.utils.visualize_util import plotAPI update
|
Merge is a layer. Merge takes layers as input.Merge is usually used with Sequential models,merge is a function.merge takes tensors as input.merge is a wrapper around Merge. merge is used in Functional API. Using Merge:
left = Sequential() |
from keras.engine import merge -> from keras.layers import merge
- E tensorflow/stream_executor/cuda/cuda_blas.cc:444] failed to create cublas handle: CUBLAS_STATUS_NOT_INITIALIZED
This is probably an out-of-memory issue. Check with
nvidia-smiornvidia-smi -l 1, then stop the relevant process.
- Save the whole model (architecture, weights, and optimizer state) or only the weights
|
|
- Variable-Size Images as Input
- Disable scientific notation in NumPy
np.set_printoptions(suppress=True)
- How do I get the input sequence length in Keras?
sequence_length = model.input.shape[1].value
- How do I get the most common value in an array?
|
What are
val_lossandval_acc? What is the difference betweenaccandval_acc?val_lossandval_accmeasure the model’s loss and accuracy on the validation dataset.How do I determine which Keras model is better? Should I use
accfrom the training data orval_accfrom the validation data?
Model1: |
If you want to estimate the ability of your model to generalize to new data (which is probably what you want to do), then you look at the validation accuracy, because the validation split contains only data that the model never sees during the training and therefor cannot just memorize.
If your training data accuracy (“acc”) keeps improving while your validation data accuracy (“val_acc”) gets worse, you are likely in an overfitting situation, i.e. your model starts to basically just memorize the data.
Difference between
fitandfit_transformRandom Forest equals Decision Tree plus Bagging, what is Bagging?
Bagging works by randomly selecting m subsets of size n with replacement as new training sets. Train classification/regression algorithms on these m training sets to get m models, then use averaging, majority voting, etc. to get the final Bagging result.
Why pruning? What’s the difference between pre-pruning and post-pruning?
Pre-pruning is top-down and fast, post-pruning is bottom-up and more accurate. Pre-pruning estimates before splitting each node - if the split doesn’t improve generalization, stop and make it a leaf node. Post-pruning first builds a complete decision tree from the training set, then examines non-leaf nodes bottom-up - if replacing a subtree with a leaf node doesn’t hurt generalization, replace it.
Pros and cons of Random Forest
Pros:
- Highly parallelizable
- Randomly selects features for decision tree node splits, can efficiently train models even with high feature dimensionality
- Feature selection capability, trees inherently select features
- Random sampling makes model variance low and generalization strong
- Simpler than Boosting
- Not sensitive to partial feature missing though honestly feels like it is
Cons:
- Easily overfits on noisy samples
- Features with more split values tend to have bigger influence on RF decisions, affecting the fitted model’s performance