Category: Python
Python Code to Simulate Two Categorical Independent Variables for Linear Regression
This following python code generates a simulated data, which includes two categorical independent variables and one continuous variable. This simulated dataset can be used for linear regression or ANOVA. import pandas as pdimport numpy as np# Set seed for consistencynp.random.seed(42)#...
Read Full Article →
Python Code to Plot F-distribution Density Function
import numpy as npimport matplotlib.pyplot as pltfrom scipy import statsdef plot_f_distribution(df1, df2, alpha=0.05): # Create x values for the plot x = np.linspace(0, 5, 1000) # Calculate F-distribution values y = stats.f.pdf(x, df1, df2) # Calculate critical F-value f_crit =...
Read Full Article →
Create OpenAI Style Illustrations in Python
This tutorial shows how to create OpenAI website style illustrations using Python Turtle graphics. The following includes two examples. Example 1: Parallel Lines The following is the first example of drawing an OpenAI-style figure using Python Turtle. If you run...
Read Full Article →
Calculate p-value in Linear Regression
This tutorial shows how you can calculate p-value for linear regression. It includes formulas and data examples in Python. Formulas for p-value in Linear Regression We can estimate the regression coefficient B using the following formula. Where, Such calculation only...
Read Full Article →
Comparisons of t-distribution and Normal distribution
This tutorial compares t-distribution and normal distribution by explaining the similarities and connections between t-distribution and normal distribution. Similarities between t-distribution and normal distribution There are a few similarities between t-distribution and normal distribution. The following figure shows the t-distribution...
Read Full Article →
Major Python Packages for Hypothesis Testing
The 2 popular Python packages for hypothesis testing are scipy.stats and statsmodels. The following includes a brief introduction to each of them, along with simple examples. Introduction of Scipy.stats Based on scipy.stats official webpage, the module contains a large number...
Read Full Article →
What Is Hypothesis Testing
Definition of Hypothesis Testing Hypothesis Testing is an inferential statistical method using sample data to solve assumptions about population parameters (characteristics that describe a population). For instance, you want to test if people in New York City’s attitudes toward the new iPhone...
Read Full Article →
How to change column names of Pandas DataFrames
There are 2 methods of changing the column names of Pandas Dataframes. The following shows the basic Python code syntax for changing column names of Pandas Dataframes. Method 1: df.rename(columns={‘old_name_1′:’new_name_1’, ‘old_name_2′:’new_name_2’}, inplace=True) Method 2: df = df.rename({‘old_name_1′:’new_name_1’, ‘old_name_2′:’new_name_2’}, axis=1) Example...
Read Full Article →
Combine Lists into an Array in Python
You can use Numpy column_stack() or row_stack() to combine lists into an array. As Columns: np.column_stack((list1, list2,…)) As Rows: np.row_stack((list1, list2,…)) Example 1 of lists to columns The following combines lists into an array using column_stack(). Thus, lists become columns...
Read Full Article →
Check if an item in a Python list
This tutorial shows examples of checking if an item is in a Python list. Method 1: item in list_name Method 2: list_name.index(item) Method 3: list_name.count(item) Example for method 1: Check if an item in a list The following code checks...
Read Full Article →