简体   繁体   English

列python blaze之间的相关性

[英]correlation between columns python blaze

Got a simple question about how-to use python blaze module for analysis. 有一个关于如何使用python blaze模块进行分析的简单问题。 So, i'm trying to do this code: 所以,我正在尝试执行此代码:

from blaze import SQL,Table
from sqlalchemy import create_engine
from scipy.stats import pearsonr
sql_path=r'/path/to/my/database.db'
e=create_engine('sqlite:///%s'%sql_path)
blz_sql=SQL(e,'analysis_dataframe')
blz_frame=Table(blz_sql)
blz_cols=blz_frame.columns
corr=pearsonr(blz_frame[blz_cols[0]],blz_frame[blz_cols[10]])
print(corr)

And here i got this error: 在这里我得到了这个错误:

TypeError: len() of unsized object

After reading some blaze docs, i found that the problem is about converting blaze column to some structure like this: 在阅读了一些blaze文档之后,我发现问题在于将blaze列转换为这样的结构:

import pandas as pd
from blaze import into
df=into(pd.DataFrame,blz_frame[blz_cols[0]]

But this conversion makes iterative calculation of pearsonr on list of columns slower. 但是这种转换使得列表列上的pearsonr的迭代计算变慢。 So, how can i simply convert blaze column into np.array to use calculations (like pearsonr or statsmodels.api.Logit(blz_frame.y,blz_frame[[train_cols]]) on it?) If it makes sense,i'm using Anaconda for Python 3.4, my version of blaze: 那么,我怎样才能简单地将blaze列转换为np.array以使用计算(如pearsonr或statsmodels.api.Logit(blz_frame.y,blz_frame [[train_cols]])?)如果它有意义,我正在使用用于Python 3.4的Anaconda,我的版本:

import blaze
print(blaze.__version__)
#returns 0.6.3

Modules like scipy.stats often expect a numpy array or pandas DataFrame explicitly. scipy.stats这样的模块通常会明确地期望一个numpy数组或pandas DataFrame。 Their logic is baked into these data structures. 他们的逻辑融入了这些数据结构。

Blaze can help you do numpy or pandas like things on foreign datasets (like your sqlite database) but are unable to reach into libraries like scipy.stats and change their code. Blaze可以帮助你像外国数据集(比如你的sqlite数据库)那样做numpy或pandas,但是无法进入像scipy.stats这样的scipy.stats并更改它们的代码。

I see the following solutions: 我看到以下解决方案:

  1. Suck all of the data from sqlite into an ndarray/DataFrame (as you're doing here) (this is slow) 将sqlite中的所有数据都吸收到ndarray / DataFrame中(就像你在这里做的那样)(这很慢)
  2. Improve scipy.stats so that it doesn't assume particular data structures. 改进scipy.stats ,使其不承担特定的数据结构。 (this would require changing a mature codebase) (这需要更改成熟的代码库)
  3. Write some basic statistics on a more general interface that includes Blaze 在包含Blaze的更通用的界面上写一些基本的统计数据

In the case of Pearson Correlation it would be quite simple to redefine the algorithm in a more general way (#3). 在Pearson Correlation的情况下,以更一般的方式重新定义算法将非常简单(#3)。 Perhaps a Blaze-stats or just general stats module would be appropriate here. 也许Blaze-stats或只是一般统计模块在这里是合适的。

Generally speaking, Blaze does not provide the promise that the existing scientific python code will work on foreign data structures. 一般来说,Blaze没有提供现有科学python代码可以在外部数据结构上工作的承诺。 That is a lofty goal. 这是一个崇高的目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM