小编Sta*_*pol的帖子

Python中的多元线性回归

我似乎找不到任何进行多重回归的python库.我发现的唯一的东西只做简单的回归.我需要对几个自变量(x1,x2,x3等)回归我的因变量(y).

例如,使用此数据:

print 'y        x1      x2       x3       x4      x5     x6       x7'
for t in texts:
    print "{:>7.1f}{:>10.2f}{:>9.2f}{:>9.2f}{:>10.2f}{:>7.2f}{:>7.2f}{:>9.2f}" /
   .format(t.y,t.x1,t.x2,t.x3,t.x4,t.x5,t.x6,t.x7)
Run Code Online (Sandbox Code Playgroud)

(以上输出:)

      y        x1       x2       x3        x4     x5     x6       x7
   -6.0     -4.95    -5.87    -0.76     14.73   4.02   0.20     0.45
   -5.0     -4.55    -4.52    -0.71     13.74   4.47   0.16     0.50
  -10.0    -10.96   -11.64    -0.98     15.49   4.18   0.19     0.53
   -5.0     -1.08    -3.36     0.75     24.72   4.96   0.16     0.60
   -8.0     -6.52    -7.45    -0.86     16.59   4.29   0.10     0.48
   -3.0     -0.81    -2.36    -0.50     22.44   4.81   0.15     0.53
   -6.0     -7.01    -7.33    -0.33 …
Run Code Online (Sandbox Code Playgroud)

python statistics numpy scipy linear-regression

119
推荐指数
6
解决办法
16万
查看次数

如何检查matplotlib的pylab后端是否内联运行?

我正在修改一个使用matplotlib绘制一些特殊图形的python模块.

现在,这个模块只是将所有数字保存为文件.

我希望能够在ipython笔记本中工作时导入模块并查看结果"内联",另一方面我希望保留默认功能,将模块保存为文件,当模块导入所有其他模块时案例.

所以我需要以某种方式检查模块是否在ipython笔记本中导入并且pylab是否内联操作.

我怎么检查这个?

python matplotlib ipython ipython-notebook

10
推荐指数
2
解决办法
3738
查看次数

如何使用PyObjC在WebKit WebView中加载用户CSS?

我想要一个使用我自己的CSS的小浏览器.问题是CSS没有加载,或者我想,它加载但没有任何影响.

这是完整的代码(我不使用Interface Builder):

import Foundation
import WebKit
import AppKit
import objc

def main():
    app = AppKit.NSApplication.sharedApplication()
    rect = Foundation.NSMakeRect(100,350,600,800)
    win = AppKit.NSWindow.alloc()
    win.initWithContentRect_styleMask_backing_defer_(rect, AppKit.NSTitledWindowMask | AppKit.NSClosableWindowMask | AppKit.NSResizableWindowMask | AppKit.NSMiniaturizableWindowMask, AppKit.NSBackingStoreBuffered, False)
    win.display()
    win.orderFrontRegardless()

    webview = WebKit.WebView.alloc()
    webview.initWithFrame_(rect)

    webview.preferences().setUserStyleSheetEnabled_(objc.YES)
    print webview.preferences().userStyleSheetEnabled()
    cssurl = Foundation.NSURL.URLWithString_("http://dev.stanpol.ru/user.css")
    webview.preferences().setUserStyleSheetLocation_(cssurl)
    print webview.preferences().userStyleSheetLocation()

    pageurl = Foundation.NSURL.URLWithString_("http://dev.stanpol.ru/index.html")
    req = Foundation.NSURLRequest.requestWithURL_(pageurl)
    webview.mainFrame().loadRequest_(req)

    win.setContentView_(webview)
    app.run()

if __name__ == '__main__':
    main()
Run Code Online (Sandbox Code Playgroud)

代码运行没有错误.打印

True
http://dev.stanpol.ru/user.css
Run Code Online (Sandbox Code Playgroud)

但是我的CSS在WebView中没有任何影响.

我尝试了不同的解决方案,例如添加DOM链接:

pageurl = Foundation.NSURL.URLWithString_("http://dev.stanpol.ru/index.html")
req = Foundation.NSURLRequest.requestWithURL_(pageurl)
webview.mainFrame().loadRequest_(req)

dom = webview.mainFrame().DOMDocument()
link = dom.createElement_("link")
link.setAttribute_value_("rel", …
Run Code Online (Sandbox Code Playgroud)

css python pyobjc webkit objective-c

9
推荐指数
1
解决办法
1330
查看次数

如何将pandas DataFrame的索引dtype更改为int32?

DataFrame索引的默认dtype是int64,我想将其更改为int32.

我尝试用pd.DataFrame.set_indexNumPy数组更改它int32,也尝试用新的索引dtype=np.int32.它没有用,总是返回索引int64.

有人可以显示一个工作代码来生成int32大小的Pandas索引吗?

我使用conda Pandas v0.20.1.

python indexing numpy pandas

8
推荐指数
1
解决办法
1680
查看次数

如何计算熊猫组中的所有正值和负值?

我们假设我们有一张桌子:

df = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo'],
                   'B' : ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three'],
                   'C' : np.random.randn(8), 'D' : np.random.randn(8)})
Run Code Online (Sandbox Code Playgroud)

输出:

      A       B          C           D
0    foo     one    -1.304026    0.237045
1    bar     one     0.030488   -0.672931
2    foo     two     0.530976   -0.669559
3    bar     three  -0.004624   -1.604039
4    foo     two    -0.247809   -1.571291
5    bar     two    -0.570580    1.454514
6    foo     one     1.441081    0.096880
7    foo     three   0.296377    1.575791
Run Code Online (Sandbox Code Playgroud)

我想计算C列中有多少正负数属于A列中的每个组以及具有多大比例.A中的组比foo和bar多得多,因此组名不应该在代码中.

我试图通过A组合然后过滤,但没有找到正确的方法.还试图与一些聪明的lambda聚合,但没有成功.

python lambda pandas

7
推荐指数
1
解决办法
8181
查看次数

如何更改所选文本的不透明度?

我在网页上有几乎看不见的文字,opacity: 0.1; 我希望它在被选中时变得可见.

但是,选择也几乎是不可见的.不幸的是,::selection不会改变不透明度.

css selection opacity css3

1
推荐指数
1
解决办法
3536
查看次数