Matplolib generally requires a lot of code to create aesthetically beautiful plots, so it’s more suitable in cases where we need fast and raw plots that give a sense of the data and its distribution.In this article, we’ve seen an overview of some plots we can create with the three most used Python libraries for graphical representations: Matplotlib, Seaborn, and Plotly.Īlthough there is no absolute right or wrong, we can synthesize their usage like so: # Create an ROC curve using Plotly Express Y_pred_proba = rf_classifier.predict_proba(X_test)įpr, tpr, thresholds = roc_curve(y_test, y_pred_proba)Īuc_score = roc_auc_score(y_test, y_pred_proba) # Get the predicted probabilities for the positive class (class 1) Rf_classifier = RandomForestClassifier(random_state=0) # Fit train set with a Random Forest Classifier X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.2, random_state=0) # Split the data into train and test sets # Scale the features using StandardScaler X, y = make_classification(n_samples=1000, n_features=10, n_informative=5, random_state=0) (Note: the following code is taken from the Seaborn tutorials web page, see here for reference):įrom sklearn.datasets import make_classificationįrom sklearn.model_selection import train_test_splitįrom sklearn.ensemble import RandomForestClassifierįrom sklearn.preprocessing import StandardScalerįrom trics import roc_curve, roc_auc_score The dataset called “Tips” is provided by Seaborn, and it can be used to make practice with it. We can compare the tips at dinner and at lunch, and we can see if the customers were smokers or not. It’s also equipped with some datasets so that we can plot and analyze them, to improve our skills with it.įor example, suppose we want to analyze the data related to the tips left to waiters at the restaurant. The superpowers of Seaborn are related to the fact that is built on top of Matplotlib, so we can achieve beautiful results with low code.Īlso, Seaborn has a vast tutorial section on its website where we can see its superpowers. So, here we can see how a heatmap helps us better visualize the data, giving us the possibility to immediately find the highest values (606 and 622) and to see to which features they are related (1960, July, and August). To create a scatterplot with Matplotlib we can use the method scatter(). One of the very basic graphs we may be interested in when analyzing data is a scatterplot because this may give us a sense of how the data is distributed. Let’s see some plots we can create with Matplotlib, with code examples. In particular, if we’re interested in presenting aesthetically beautiful plots. Also, despite having a low-level interface, Matplotlib is the foundation for other visualization libraries, like Seaborn.Īnyway, although Matplotlib gives us complete control over our charts, its Achilles’ heel is that it may take a lot of code to produce the results we need. It’s an extremely flexible library, allowing us to customize every aspect of our graphs. It provides a wide range of methods for creating plots, giving us the possibility to visualize data ranging from scatterplots to complicated visualizations. Matplotlib is one of the oldest and most widely used data visualization libraries. We’ll explore their characteristics, emphasize their differences, and show practical code examples on how to use them. In this article, we’ll talk about three popular Pythonic data visualization libraries: Matplotlib, Seaborn, and Plotly. When it comes to data analysis, Python is one of the most used programming languages for a simple reason: it’s versatile and has several libraries for creating plots, giving us the possibility to choose the one that best suits our needs. Data visualization plays a fundamental role in understanding and communicating the insights we derive from our data when we analyze them.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |