首页 > 技术文章 > 多因子分析

pupilheart 2019-02-11 22:52 原文

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import pandas as pd
import numpy as np
import scipy.stats as ss
 
 
### 正态分布
norm_dist = ss.norm.rvs(size=20)
Normal = ss.normaltest(norm_dist)
Normal,Pvalue = ss.normaltest(norm_dist)
print(ss.normaltest(norm_dist))
print(Pvalue)
 
### 卡方分布
testarray = np.array([[10,10,20],[20,20,20]])
ss.chi2_contingency(testarray)  ## chi2_contingency(矩阵)
 
### t 分布
a = [3,5,4,6,5,5,4,5,3,6,7,8,7,6,7,8,8,9,9,8,7,7,6,7,8]
b = [7,8,6,7,8,9,6,6,7,8,8,7,9,10,9,9,8,8,4,4,5,6,9,8,12]
Ttest_indResult=ss.ttest_ind(a,b)
#print(ss.ttest_ind(a,b))
print(Ttest_indResult)
 
### 方差检验
agr1 = [40, 50, 39, 43, 49]
agr2 = [28, 26, 30, 26, 34]
agr3 = [38, 39, 43, 32, 36]
F_onewayResult = ss.f_oneway(agr1,agr2,agr3)
print(F_onewayResult)
 
 
### 线性回归
from sklearn.linear_model import LinearRegression
X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
y = np.dot(X, np.array([1, 2])) + 3
reg = LinearRegression().fit(X, y)
reg.score()

推荐阅读