plt.fill_between may be used to add shaded areas to charts. By using the alpha (transparency) argument shaded areas may overlap.
import matplotlib.pyplot as plt y1 = [60, 65, 65, 70, 75] y1_max = [70, 73, 70, 78, 82] y1_min = [55, 58, 61, 62, 68] y2 = [45, 50, 55, 55, 55] y2_max = [53, 55, 63, 60, 62] y2_min = [35, 45, 52, 52, 50] plt.plot(x, y1) plt.plot(x, y2, linestyle ='dashed') # alpha adjusts transparency, higher alpha --> darker grey # Or color could be set to, for example '0.2', but using transparency allows # overlapping shaded areas plt.fill_between(x, y1_min, y1_max, color = 'k', alpha = 0.1) plt.fill_between(x, y2_min, y2_max, color = 'k', alpha = 0.1) plt.show()
NumPy has an extensive list of methods to generate random arrays and single numbers, or to randomly shuffle arrays. Continue reading “74. Using NumPy to generate random numbers, or shuffle arrays”
The last of our machine learning methods that we will look at in this introduction is neural networks.
Neural networks power much of modern image and voice recongition. They can cope with highly complex data, but often take large amounts of data to train well. There are many parameters that can be changes, so fine-tuning a neural net can require extensive work. We will not go into all the ways they may be fine-tuned here, but just look at a simple example. Continue reading “73. Machine learning: neural networks”
Random forest is a versatile machine learning method based on decision trees. One useful feature of random forests is that it is easy to obtain the relative importance of features. This may be used to help better understand what drives classification, and may also be used to reduce the feature set used with minimal reduction in accuracy.
Once again we will re-use our logistic regression model, and replace the model function wit the following three lines:
from sklearn.ensemble import
RandomForestClassifier model = RandomForestClassifier(n_estimators=10000, random_state=0, n_jobs=-1)
model.fit (X,y) Continue reading “72. Machine Learning: Random Forests”