


How to calculate the P value of two sets of data based on python
We need to use p_value when doing A/B test evaluation. This article records how to use python to calculate the significance of two sets of data.
1. Code
# TTest.py # -*- coding: utf-8 -*- ''' # Created on 2020-05-20 20:36 # TTest.py # @author: huiwenhua ''' ## Import the packages import numpy as np from scipy import stats def get_p_value(arrA, arrB): a = np.array(arrA) b = np.array(arrB) t, p = stats.ttest_ind(a,b) return p if __name__ == "__main__": get_p_value([1, 2, 3, 5, ], [6, 7, 8, 9, 10])
2. T-test: two-sample T-test
The two-sample t test is to compare whether there is a significant difference between the two population means represented by the two samples. In addition to requiring that the samples come from a normal distribution, it also requires that the population variances of the two samples are equal, which is "homogeneity of variances."
Test the null hypothesis: there is no difference in sample means (μ=μ0)
Python command stats.ttest_ind(data1,data2)
When it is uncertain whether the variances of the two populations are equal , you should first use the levene test to test whether the two populations have homogeneity of variances stats.levene(data1,data2). If the p-value of the returned result is much greater than 0.05, then we think that the two populations have homogeneity of variances. If the two populations do not have homogeneous variances, you need to add the parameter equal_val and set it to False, as follows.
stats.ttest_ind(data1,data2,equal_var=False) // The default in TTest is homogeneity of variance
3. Interpretation of results
When the p value is less than a certain significance level α (such as 0.05), it is considered that there is a significant difference in the sample means. The specific analysis depends on whether the bilateral hypothesis or the unilateral hypothesis is chosen. (It is divided into less than and greater than) Note that stats.ttest_ind performs a two-sided test.
When the t value is greater than 0, there is ((1-p) * 100)% confidence that the first set of data is better than the second set of data. For example, p=0.05, then we are 95% confident that the first set of data is better than the second set of data.
Related learning recommendations: python video tutorial
The above is the detailed content of How to calculate the P value of two sets of data based on python. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to download DeepSeek Xiaomi? Search for "DeepSeek" in the Xiaomi App Store. If it is not found, continue to step 2. Identify your needs (search files, data analysis), and find the corresponding tools (such as file managers, data analysis software) that include DeepSeek functions.

The key to using DeepSeek effectively is to ask questions clearly: express the questions directly and specifically. Provide specific details and background information. For complex inquiries, multiple angles and refute opinions are included. Focus on specific aspects, such as performance bottlenecks in code. Keep a critical thinking about the answers you get and make judgments based on your expertise.

Just use the search function that comes with DeepSeek. Its powerful semantic analysis algorithm can accurately understand the search intention and provide relevant information. However, for searches that are unpopular, latest information or problems that need to be considered, it is necessary to adjust keywords or use more specific descriptions, combine them with other real-time information sources, and understand that DeepSeek is just a tool that requires active, clear and refined search strategies.

DeepSeek is not a programming language, but a deep search concept. Implementing DeepSeek requires selection based on existing languages. For different application scenarios, it is necessary to choose the appropriate language and algorithms, and combine machine learning technology. Code quality, maintainability, and testing are crucial. Only by choosing the right programming language, algorithms and tools according to your needs and writing high-quality code can DeepSeek be successfully implemented.

Question: Is DeepSeek available for accounting? Answer: No, it is a data mining and analysis tool that can be used to analyze financial data, but it does not have the accounting record and report generation functions of accounting software. Using DeepSeek to analyze financial data requires writing code to process data with knowledge of data structures, algorithms, and DeepSeek APIs to consider potential problems (e.g. programming knowledge, learning curves, data quality)

Detailed explanation of DeepSeekAPI access and call: Quick Start Guide This article will guide you in detail how to access and call DeepSeekAPI, helping you easily use powerful AI models. Step 1: Get the API key to access the DeepSeek official website and click on the "Open Platform" in the upper right corner. You will get a certain number of free tokens (used to measure API usage). In the menu on the left, click "APIKeys" and then click "Create APIkey". Name your APIkey (for example, "test") and copy the generated key right away. Be sure to save this key properly, as it will only be displayed once

PiNetwork is about to launch PiBank, a revolutionary mobile banking platform! PiNetwork today released a major update on Elmahrosa (Face) PIMISRBank, referred to as PiBank, which perfectly integrates traditional banking services with PiNetwork cryptocurrency functions to realize the atomic exchange of fiat currencies and cryptocurrencies (supports the swap between fiat currencies such as the US dollar, euro, and Indonesian rupiah with cryptocurrencies such as PiCoin, USDT, and USDC). What is the charm of PiBank? Let's find out! PiBank's main functions: One-stop management of bank accounts and cryptocurrency assets. Support real-time transactions and adopt biospecies

Here are some popular AI slicing tools: TensorFlow DataSetPyTorch DataLoaderDaskCuPyscikit-imageOpenCVKeras ImageDataGenerator
