我正在使用neurolab进行机器学习分类问题,链接: - http://code.google.com/p/neurolab/
我的问题是,我们可以逐步训练神经网络吗?
为了进一步解释,我有三部分输入数据,我想训练Neuro Net
e = net.train(input_part1, output_part1, show=1, epochs=100, goal=0.0001)
e = net.train(input_part2, output_part2, show=1, epochs=100, goal=0.0001)
e = net.train(input_part3, output_part3, show=1, epochs=100, goal=0.0001)
Run Code Online (Sandbox Code Playgroud)
将前两部分的火车呼叫将有效预测神经网络参数 - 或者 - 这只会使用最后的训练数据吗?
我对Python仍然有点新鲜,但是,我现在感觉真的很愚蠢因为我只花了一个小时试图弄清楚为什么这个for循环没有做我想要的.我不应该在for循环上花一个小时.无论如何,我正在尝试生成一个字典列表,并给每个字典一个唯一的编号,所以我这样做...
def initiate(n):
records = {'num':0,'blah':0,'doubleblah':0}
x = []
for i in range(n):
x.append(records)
x[i]['num'] = i
return x
x = initiate(4)
print(x)
Run Code Online (Sandbox Code Playgroud)
我希望函数能够返回 -
[
{'num': 0, 'doubleblah': 0, 'blah': 0},
{'num': 1, 'doubleblah': 0, 'blah': 0},
{'num': 2, 'doubleblah': 0, 'blah': 0},
{'num': 3, 'doubleblah': 0, 'blah': 0}
]
Run Code Online (Sandbox Code Playgroud)
但它实际上归还了这个 -
[
{'num': 3, 'doubleblah': 0, 'blah': 0},
{'num': 3, 'doubleblah': 0, 'blah': 0},
{'num': 3, 'doubleblah': 0, 'blah': 0},
{'num': 3, 'doubleblah': 0, 'blah': 0} …Run Code Online (Sandbox Code Playgroud) 我已经看过其他几个与此类似的"问题"(和google'd吨),但它们似乎都不符合我的问题.
我试图制作一个非固定长度,唯一的文本字符串,只包含我指定的字符串中的字符.例如,由大写和小写的a-zA-Z字符组成.(对于这个例子,我只使用a,b和c小写)
像这样的东西(下面的代码破碎)
def next(index, validCharacters = 'abc'):
return uniqueShortAsPossibleString
Run Code Online (Sandbox Code Playgroud)
index参数将是与文本字符串相关的索引(整数),例如:
next(1) == 'a'
next(2) == 'b'
next(3) == 'c'
next(4) == 'aa'
next(5) == 'ab'
next(6) == 'ac'
next(7) == 'ba'
next(8) == 'bb'
next(9) == 'bc'
next(10) == 'ca'
next(11) == 'cb'
next(12) == 'cc'
Run Code Online (Sandbox Code Playgroud)
等等.字符串:
总之,如何编写next()函数将整数索引值与指定字符的唯一短字符串相关联?
PS我是SO的新手,这个网站多年来一直帮助我,虽然我从来没有做过帐户或问过问题(到现在为止),但我真的希望我做了一个好的工作来解释我的问题.我试图用这个完成.
我是使用Python的新手,在尝试从.tpl文档引用我的样式表时遇到了一个问题.我的python,template和css文件都在同一个目录中,但是当我使用CMD将页面加载到"localhost:8080"时,它显示的模板没有应用样式.
在我的模板文档index.tpl中,我引用了三个样式表:
<link rel="stylesheet" type="text/css" href="demo.css" />
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="animate-custom.css" />
Run Code Online (Sandbox Code Playgroud)
我的python文件输出模板:index.py:
from bottle import route,template,debug,run
import sqlite3
@route('/')
def player():
return template('index.tpl')
debug(True)
run(reloader=True)
Run Code Online (Sandbox Code Playgroud) getresponserecv在读取HTML请求的标头时发出许多调用。实际上recv,它为每个字节发出,导致许多系统调用。如何进行优化?
我在具有strace dump的Ubuntu计算机上进行了验证。
样例代码:
conn = httplib.HTTPConnection("www.python.org")
conn.request("HEAD", "/index.html")
r1 = conn.getresponse()
Run Code Online (Sandbox Code Playgroud)
strace转储:
sendto(3, "HEAD /index.html HTTP/1.1\r\nHost:"..., 78, 0, NULL, 0) = 78
recvfrom(3, "H", 1, 0, NULL, NULL) = 1
recvfrom(3, "T", 1, 0, NULL, NULL) = 1
recvfrom(3, "T", 1, 0, NULL, NULL) = 1
recvfrom(3, "P", 1, 0, NULL, NULL) = 1
recvfrom(3, "/", 1, 0, NULL, NULL) = 1
...
Run Code Online (Sandbox Code Playgroud) 我试图在python3中使用xlrd读取excel文件,但是我没有从读取单元格得到结果,因为我在excel中看到它们.
我试图访问的单元格似乎有一些外部源集,从中刷新它们,但由于该源不可用,excel会显示一些缓存值.这些值位于同一个excel文件中的其他位置,因此当您在工作表中看到例如"2.65111"时,单元格的实际内容在excel的此编辑栏中显示为"= BC12".
当我尝试通过xlrd读取此内容时:
wb=xlrd.open_workbook("filename.xls",formatting_info=True)
wb.sheet_by_name("sheetname").cell(12,9)
Run Code Online (Sandbox Code Playgroud)
单元格内容显示为:
'text:'[XXXX]' (XF:95)'
Run Code Online (Sandbox Code Playgroud)
(其中XXXX很可能是此外部.csv文件的列的名称)
我要么期望xlrd返回我在excel中看到的"2.65111",或者至少将"= BC12"作为对其他单元格的引用,但我不能以任何方式使用"[XXXXX]"的东西.
有没有办法让xlrd显示这两个中的任何一个?
我真的很困惑它来自哪里"[XXXXX]",以及为什么这与我在excel中看到的如此不同.
PS:我不能只使用BC12单元格中的数据,因为这应该是文件的自动处理,只有"原始"单元格具有固定位置,而其他单元格可能在第二天处于另一个随机位置.
下面是我从 csv 文件中提取数据的代码(我从转储的 mysql 中获得了该文件)。
data = csv.reader(f, delimiter=',', quotechar='"')
Run Code Online (Sandbox Code Playgroud)
经过几次测试,我发现我上面的代码有一个大问题。它无法提取如下数据:
"25","Mike Ross","Tennok\"","NO"
Run Code Online (Sandbox Code Playgroud)
有什么想法可以解决这个问题吗?质量。
我想删除'Joe'末尾的空格
name = 'Joe'
print(name, ', you won!')
>>>Joe , you won!
Run Code Online (Sandbox Code Playgroud)
我尝试了rstrip方法,但它没有用
name='Joe'
name=name.rstrip()
print(name, ', you won!')
>>>Joe , you won!
Run Code Online (Sandbox Code Playgroud)
我唯一的解决方案是连接字符串
name='Joe'
name=name+','
print(name,'you won!')
>>>Joe, you won!
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
我一直在努力理解__new__和元编程.所以我看看官方的python源代码.
http://hg.python.org/cpython/file/2.7/Lib/fractions.py
它们__new__对Fractions 的功能如下:
class Fraction(Rational):
def __new__(cls, numerator=0, denominator=None):
"""Constructs a Fraction. ... """
self = super(Fraction, cls).__new__(cls)
...
if isinstance(numerator, float):
# Exact conversion from float
value = Fraction.from_float(numerator)
self._numerator = value._numerator
self._denominator = value._denominator
return self
@classmethod
def from_float(cls, f):
"""Converts a finite float to a rational number, exactly. ..."""
# ...
return cls(*f.as_integer_ratio())
Run Code Online (Sandbox Code Playgroud)
为什么他们return self,而不是
return Fraction.from_float(numerator)
Run Code Online (Sandbox Code Playgroud)
我以为我明白了,但现在我很困惑.
(编辑)
为了支持子类化,改变它会有什么不同
return cls.from_float(numerator)
Run Code Online (Sandbox Code Playgroud) 我是 python 新手,上次编码是在 80 年代中期,所以我感谢您的耐心帮助。
看来 .rolling(window) 要求窗口是固定整数。我需要一个滚动窗口,其中窗口或回溯期是动态的并由另一列给出。
在下表中,我查找 Lookbacksum,它是 Lookback 列指定的数据的滚动总和。
d={'Data':[1,1,1,2,3,2,3,2,1,2],
'Lookback':[0,1,2,2,1,3,3,2,3,1],
'LookbackSum':[1,2,3,4,5,8,10,7,8,3]}
df=pd.DataFrame(data=d)
Run Code Online (Sandbox Code Playgroud)
例如:
Data Lookback LookbackSum
0 1 0 1
1 1 1 2
2 1 2 3
3 2 2 4
4 3 1 5
5 2 3 8
6 3 3 10
7 2 2 7
8 1 3 8
9 2 1 3
Run Code Online (Sandbox Code Playgroud) python ×10
python-3.x ×3
python-2.7 ×2
algorithm ×1
bottle ×1
csv ×1
excel ×1
httplib ×1
pandas ×1
strip ×1
whitespace ×1
xlrd ×1