Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python verifies what is the difference between multiple sets of data

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces what is the difference between multiple groups of data verified by python. It is very detailed and has a certain reference value. Friends who are interested must read it!

1. Analysis of variance 1. Single factor analysis of variance

Through the box chart, we can see that the order quantity of 10 groups looks similar. In order to compare the order quantity of 10 groups more scientifically, we can use the analysis of variance.

From statsmodels.formula.api import olsfrom statsmodels.stats.anova import anova_lmmodel = ols ('orders~C (label)', data=need_data). Fit () anova_table = anova_lm (model, typ = 2) print (anova_table)

The results show that the p value of 0.62 is greater than 0.05, so the original hypothesis can not be rejected, so there is no significant difference in order distribution among the 10 groups.

2. Chi-square test

If it is to compare the discontinuous value indicators between multiple groups, is there any difference?

For example, check whether there is a significant difference in the male-to-female ratio of the above 10 groups.

The observation frequency of each group was calculated.

Data2=data1.melt (id_vars= ['gender'], value_name=' observation frequency') data2.head ()

Calculate the overall male to female ratio:

Rate= (data2.groupby (['gender']) ['observation frequency'] .sum () / data2.groupby (['gender']) ['observation frequency'] .sum (). Sum (). Reset_index () rate.columns= ['gender', 'rate'] rate

Calculate the total number of users in each group:

Group_sum=data2.groupby (['group']) ['observation frequency'] .sum () .reset_index () group_sum.columns= ['group', 'number of users in the group'] group_sum

Calculate the card value:

Import mathdata3=pd.merge (data2,group_sum,on= ['group'], how='left') data3=pd.merge (data3,rate,on= ['gender'], how='left') data3 ['expected frequency'] = data3 ['number of users in the group'] * data3 ['rate'] data3 [' chi-square'] = data3.apply (lambda x: math.pow ((x. Expected frequency-x. Observation frequency), 2) / x. Expected frequency, axis=1) data3.head ()

The degree of freedom of this case is (10-1) * (2-1) = 9, the significance level is 0.05, and the critical value of chi-square distribution table is 18.31.

Because 7.01

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report