在关于reshape()函数的numpy手册中,它说
>>> a = np.zeros((10, 2))
# A transpose make the array non-contiguous
>>> b = a.T
# Taking a view makes it possible to modify the shape without modifying the
# initial object.
>>> c = b.view()
>>> c.shape = (20)
AttributeError: incompatible shape for a non-contiguous array
Run Code Online (Sandbox Code Playgroud)
我的问题是:
c.shape = (20)抛出错误incompatible shape for a non-contiguous array?感谢您的回答!
NLTK包提供了一种方法show_most_informative_features()来查找这两个类的最重要的功能,输出如下:
contains(outstanding) = True pos : neg = 11.1 : 1.0
contains(seagal) = True neg : pos = 7.7 : 1.0
contains(wonderfully) = True pos : neg = 6.8 : 1.0
contains(damon) = True pos : neg = 5.9 : 1.0
contains(wasted) = True neg : pos = 5.8 : 1.0
Run Code Online (Sandbox Code Playgroud)
正如在这个问题中所回答的,如何获得scikit-learn分类器的最丰富的功能?,这也适用于scikit-learn.但是,对于二元分类器,该问题的答案仅输出最佳特征本身.
所以我的问题是,我如何识别该特征的相关类,如上面的例子(优秀是pos类中最有用的信息,而seagal在负面类中信息量最大)?
编辑:实际上我想要的是每个班级最丰富的单词列表.我怎样才能做到这一点?谢谢!
我正在尝试使用 psycopg2 访问 PostgreSQL:
sql = """
SELECT
%s
FROM
table;
"""
cur = con.cursor()
input = (['id', 'name'], )
cur.execute(sql, input)
data = pd.DataFrame.from_records(cur.fetchall())
Run Code Online (Sandbox Code Playgroud)
但是,返回的结果是:
0
0 [id, name]
1 [id, name]
2 [id, name]
3 [id, name]
4 [id, name]
Run Code Online (Sandbox Code Playgroud)
如果我尝试访问单列,它看起来像:
0
0 id
1 id
2 id
3 id
4 id
Run Code Online (Sandbox Code Playgroud)
列名周围的引用似乎有问题(不应出现单引号):
In [49]: print cur.mogrify(sql, input)
SELECT
'id'
FROM
table;
Run Code Online (Sandbox Code Playgroud)
但我正在关注文档:http : //initd.org/psycopg/docs/usage.html#
任何人都可以告诉我这里发生了什么?非常感谢!!!