Category Archives: Python

Stacking Classifier Sklearn Python Example

Stacking classifier python example

In this blog post, we will be going over a very simple example of how to train a stacking classifier machine learning model in Python using the Sklearn library and learn the concepts of stacking classifier. A stacking classifier is an ensemble learning method that combines multiple classification models to create one “super” model. This can often lead to improved performance, since the combined model can learn from the strengths of each individual model. What are Stacking Classifiers? Stacking is a machine learning ensemble technique that combines multiple models to form a single powerful model. The individual models are trained on different subsets of the data using some type of …

Continue reading

Posted in Data Science, Machine Learning, Python. Tagged with , , .

Decision Tree Hyperparameter Tuning Grid Search Example

decision tree grid search hyperparameter tuning example

The output prints out grid search across different values of hyperparameters, the model score with best hyperparameters and the most optimal hyperparameters value. In the above code, the decision tree model is train and evaluate our for each value combination and choose the combination that results in the best performance. In this case, “best performance” could be defined as either accuracy or AUC (area under the curve). Once we’ve found the best performing combination of hyperparameters, we can then train our final model using those values and deploy it to production. Conclusion In this blog post, we explored how to use grid search to tune the hyperparameters of a Decision …

Continue reading

Posted in Data Science, Machine Learning, Python. Tagged with , , .

Generalized Linear Models Explained with Examples

Generalized linear models (GLMs) are a powerful tool for data scientists, providing a flexible way to model data. In this post, you will learn about the concepts of generalized linear models (GLM) with the help of Python examples.  It is very important for data scientists to understand the concepts of generalized linear models and how are they different from general linear models such as regression or ANOVA models.  What are Generalized Linear Models? Generalized linear models (GLM) are a type of statistical models that can be used to model data that is not normally distributed. It is a flexible general framework that can be used to build many types of regression models, including …

Continue reading

Posted in Data Science, Machine Learning, Python. Tagged with , .

Generate Random Numbers & Normal Distribution Plots

Generate random numbers from normal distribution

In this blog post, we’ll be discussing how to generate random numbers samples from normal distribution and create normal distribution plots in Python. We’ll go over the different techniques for random number generation from normal distribution available in the Python standard library such as SciPy, Numpy and Matplotlib. We’ll also create normal distribution plots from these numbers generated. Generate random numbers using Numpy random.randn Numpy is a Python library that contains built-in functions for generating random numbers. The numpy.random.randn function generates random numbers from a normal distribution. This function takes size N as in number of numbers to be generated as an input and returns an array of N random …

Continue reading

Posted in Data Science, Python, statistics. Tagged with , , .

Pandas: Creating Multiindex Dataframe from Product or Tuples

Create multiindex from product

MultiIndex is a powerful tool that enables us to work with higher dimensional data, but it can be tricky to create MultiIndex Dataframes using the from_tuples and from_product function in Pandas. In this blog post, we will be discussing how to create a MultiIndex dataframe using MultiIndex from_tuples and from_product function in Pandas.  What is a MultiIndex? MultiIndex is an advanced Pandas function that allows users to create MultiIndexed DataFrames – i.e., dataframes with multiple levels of indexing. MultiIndex can be useful when you have data that can be naturally grouped by more than one category. For example, you might have data on individual employees that can be grouped by …

Continue reading

Posted in Data Science, Python. Tagged with , .

Top Python Statistical Analysis Packages

python statistical packages

As a data scientist, you know that one of the most important aspects of your job is statistical analysis. After all, without accurate data, it would be impossible to make sound decisions about your company’s direction. Thankfully, there are a number of excellent Python statistical analysis packages available that can make your job much easier. In this blog post, we’ll take a look at some of the most popular ones. SciPy SciPy is a Python-based ecosystem of open-source software for mathematics, science, and engineering. SciPy contains modules for statistics, optimization, linear algebra, integration, interpolation, special functions, Fourier transforms (FFT), signal and image processing, and other tasks common in science and …

Continue reading

Posted in Data Science, Python, statistics. Tagged with , , .

Covariance vs. Correlation vs. Variance: Python Examples

expanded correlation formula

In the field of data science, it’s important to have a strong understanding of statistics and know the difference between related concepts. This is especially true when it comes to the concepts of covariance, correlation, and variance. Whether you’re a data scientist, statistician, or simply someone who wants to better understand the relationships between different variables, it’s important to know the difference between covariance, correlation, and variance. While these concepts may seem similar at first glance, they each have unique applications and serve different purposes. In this blog post, we’ll explore each of these concepts in more detail and provide concrete examples of how to calculate them using Python.  What …

Continue reading

Posted in Data Science, Python, statistics. Tagged with , , .

Import or Upload Local File to Google Colab

How to read CSV file in Google Colab

Google Colab is a powerful tool that allows you to run Python code in the cloud. This can be useful for a variety of tasks, including data analysis and machine learning. One of the lesser known features of Google Colab is that you can also import or upload files stored on your local drive. In this article, we will show you how to read a file from your local drive in Google Colab using a quick code sample. There are a few reasons why you as a data scientist might need to learn how to read files from your local drive in Google Colab. One reason is that you may …

Continue reading

Posted in AI, Data Science, Machine Learning, Python. Tagged with , , .

Ridge Classification Concepts & Python Examples

Ridge classifier python example

In machine learning, ridge classification is a technique used to analyze linear discriminant models. It is a form of regularization that penalizes model coefficients to prevent overfitting. Overfitting is a common issue in machine learning that occurs when a model is too complex and captures noise in the data instead of the underlying signal. This can lead to poor generalization performance on new data. Ridge classification addresses this problem by adding a penalty term to the cost function that discourage complexity. This results in a model that is better able to generalize to new data. In this post, you will learn about Ridge classifier in detail with the help of …

Continue reading

Posted in Data Science, Machine Learning, Python. Tagged with , , .

Pandas Dataframe loc, iloc & brackets examples

pandas-dataframe-example-loc-iloc-examples-rows-columns

Pandas is a powerful data analysis tool in Python that can be used for tasks such as data cleaning, exploratory data analysis, feature engineering, and predictive modeling. In this article, we will focus on how to use Pandas’ loc and iloc functions on Dataframe, as well as brackets with Dataframe, with examples. As a data scientist or data analyst, it is very important to understand how these functions work and when to use them. In this post, we will work with the following Pandas data frame. Use loc and iloc functions to get Rows of Dataframe The loc function is used to get a particular row in a Dataframe by …

Continue reading

Posted in Data Science, Python. Tagged with , , .

Pandas: How to Create a Dataframe – Examples

Create Pandas Dataframe using Sample Data

One of the most popular modules for working with data in Python is the Pandas library. Pandas provides data structures and operations for working with structured data. A key concept in Pandas is the Dataframe. Learning how to create and use dataframes is an important skill for anyone including data analysts and data scientists working with data in Python. In this post, you will learn about how to create a Pandas dataframe with some sample data. What is Pandas Dataframe? A Pandas dataframe is a two-dimensional data structure, like a table in a spreadsheet, with columns of data and rows of data. Dataframe is analogous to a table in SQL …

Continue reading

Posted in Data Science, Python. Tagged with , .

Statistics – Random Variables, Types & Python Examples

probability-distribution-plot-of-discrete-random-variable

Random variables are one of the most important concepts in statistics. In this blog post, we will discuss what they are, their different types, and how they are related to the probability distribution. We will also provide examples so that you can better understand this concept. As a data scientist, it is of utmost importance that you have a strong understanding of random variables and how to work with them. What is a random variable and what are some examples? A random variable is a variable that can take on random values. The key difference between a variable and a random variable is that the value of the random variable …

Continue reading

Posted in Data Science, Python, statistics. Tagged with , , .

Machine Learning Sklearn Pipeline – Python Example

Machine-learning-pipeline-Sklearn

In this post, you will learning about concepts about machine learning (ML) pipeline and how to build ML pipeline using Python Sklearn Pipeline (sklearn.pipeline) package. Getting to know how to use Sklearn.pipeline effectively for training/testing machine learning models will help automate various different activities such as feature scaling, feature selection / extraction and training/testing the models. It is recommended for data scientists (Python) to get a good understanding of Sklearn.pipeline.  Introduction to Machine Learning Pipeline & Sklearn.pipeline Machine Learning (ML) pipeline, theoretically, represents different steps including data transformation and prediction through which data passes. The outcome of the pipeline is the trained model which can be used for making the predictions. …

Continue reading

Posted in Data Science, Machine Learning, Python. Tagged with , , , .

Sample Dataset for Regression & Classification: Python

Sample-data-set-plot-for-regression

A lot of beginners in the field of data science / machine learning are intimidated by the prospect of doing data analysis and building regression (linear) & classification models in Python. But with an ability to create sample dataset using Python packages, you can practice your skills and build your confidence over a period of time. The technique demonstrated in this blog post to create and visualize / plot the sample dataset includes datasets that can be used for regression models such as linear regression and classification models such as logistic regression, random forest, SVM etc. You can use this technique to explore different methods for solving the same problem. …

Continue reading

Posted in Data Science, Machine Learning, Python. Tagged with , , .

Sklearn SimpleImputer Example – Impute Missing Data

In this post, you will learn about how to use Python’s Sklearn SimpleImputer for imputing / replacing numerical & categorical missing data using different strategies. In one of the related article posted sometime back, the usage of fillna method of Pandas DataFrame is discussed. Handling missing values is key part of data preprocessing and hence, it is of utmost importance for data scientists / machine learning Engineers to learn different techniques in relation imputing / replacing numerical or categorical missing values with appropriate value based on appropriate strategies. SimpleImputer Python Code Example SimpleImputer is a class in the sklearn.impute module that can be used to replace missing values in a dataset, using a …

Continue reading

Posted in Data Science, Machine Learning, Python. Tagged with , , , .

Pandas dropna: Drop Rows & Columns with Missing Values

pandas dropna method code sample

In this blog post, we will be discussing Pandas’ dropna method. This method is used for dropping rows and columns that have missing values. Pandas is a powerful data analysis library for Python, and the dropna function is one of its most useful features. As data scientists, it is important to be able to handle missing data, and Pandas’ dropna function makes this easy. Pandas dropna Method Pandas’ dropna function allows us to drop rows or columns with missing values in our dataframe. Find the documentation of Pandas dropna method on this page: pandas.DataFrame.dropna. The dropna method looks like the following: DataFrame.dropna(axis=0, how=’any’, thresh=None, subset=None, inplace=False) Given the above method and parameters, the following …

Continue reading

Posted in Data Science, Machine Learning, Python. Tagged with , , .