统计和因果推理的图书馆
statinf的Python项目详细描述
他汀
1。安装
您可以从PyPI获取statif:
pip install statinf
statinf
是一个用于统计和因果推理的库。
它提供了从传统OLS到神经网络的主要统计模型。在
该库在Windows、Linux和MacOs上受支持。
2。文件
您可以在https://www.florianfelice.com/statinf找到完整的文档。在
您还可以在documentation上找到库的FAQ和{a6}。在
3。可用模块
以下是statinf
上可用模块的非详尽列表:
- 在
在MLP
实现多层感知器 (请参见MLP了解更多详细信息和示例)。在 - 在
在OLS
允许使用普通最小二乘法进行线性回归 (请参见OLS了解更多详细信息和示例)。在 - 在
在GLM
实现了广义线性模型 更多细节和示例请参见GLM)。在 - 在
在stats
允许使用descriptive和 tests统计。在 - 在
在data
是一个处理数据的模块,例如data generation, One Hot Encoding和其他 (请参见data processing或(有关更多详细信息,请参见data generation模块)。在
您可以在https://www.florianfelice.com/statinf上找到以下示例和更多示例。 关注未来releases。在
3.1条。OLS
statinf
附带OLS回归,分析公式如下:
输出将是:
==================================================================================| OLS summary |==================================================================================|R²=0.98475 | R² Adj. =0.98464 ||n=999|p=7|| Fisher value=10676.727 ||==================================================================================| Variables | Coefficients | Std. Errors | t-values | Probabilities |==================================================================================| X0 |1.3015 |0.03079 |42.273 |0.0 *** || X1 | -0.48712 |0.03123 | -15.597 |0.0 *** || X2 |1.62079 |0.04223 |38.377 |0.0 *** || X3 |2.55237 |0.0326 |78.284 |0.0 *** || X4 | -7.54776 |0.03247 | -232.435 |0.0 *** || X1*X2 |0.03626 |0.02866 |1.265 |0.206 || exp(X2)| -0.00929 |0.01551 | -0.599 |0.549 |==================================================================================| Significance codes: 0. < *** < 0.001 < ** < 0.01 < * < 0.05 < . < 0.1 < '' < 1|
3.2条。GLM
logistic回归可用于服从伯努利分布的二元分类。由于是回归矩阵,我们有:
然后我们用以下方法实现回归:
fromstatinf.regressionsimportGLMfromstatinf.dataimportgenerate_dataset# Generate a synthetic datasetdata=generate_dataset(coeffs=[1.2556,-6.465,1.665414,-1.5444],n=2500,std_dev=10.5,binary=True)# We split data into train/test/applicationtrain=data.iloc[0:1000]test=data.iloc[1001:2000]# We set the linear formula for Xbformula="Y ~ X0 + X1 + X2 + X3"logit=GLM(formula,train,test_set=test)# Fit the modellogit.fit(plot=False,maxit=10)logit.get_weights()
输出将是:
==================================================================================| Logit summary |==================================================================================| McFadden R²=0.67128 | McFadden R² Adj. =0.6424 || Log-Likelihood = -227.62 | Null Log-Likelihood = -692.45 || LR test p-value =0.0 |Covariance= nonrobust ||n=999|p=5||Iterations=8|Convergence= True |==================================================================================| Variables | Coefficients | Std. Errors | t-values | Probabilities |==================================================================================| X0 | -1.13024 |0.10888 | -10.381 |0.0 *** || X1 |0.02963 |0.07992 |0.371 |0.711 || X2 | -1.40968 |0.1261 | -11.179 |0.0 *** || X3 |0.5253 |0.08966 |5.859 |0.0 *** |==================================================================================| Significance codes: 0. < *** < 0.001 < ** < 0.01 < * < 0.05 < . < 0.1 < '' < 1|==================================================================================
3.3条。Multi Layer Perceptron
您可以使用MLP
类训练神经网络。
下面的例子展示了如何训练一个具有1个线性层的MLP。它相当于用梯度下降实现OLS。在
fromstatinf.dataimportgenerate_datasetfromstatinf.mlimportMLP,Layer# Generate the synthetic datasetdata=generate_dataset(coeffs=[1.2556,-6.465,1.665414,1.5444],n=1000,std_dev=1.6)Y=['Y']X=[cforcindata.columnsifcnotinY]# Initialize the network and its architecturenn=MLP()nn.add(Layer(4,1,activation='linear'))# Train the neural networknn.train(data=data,X=X,Y=Y,epochs=1,learning_rate=0.001)# Extract the network's weightsprint(nn.get_weights())
输出:
{'weights 0':array([[1.32005564],[-6.38121934],[1.64515704],[1.48571785]]),'bias 0':array([0.81190412])}
- 项目
标签: