在一些Python会话之后,Linux变得越来越慢
我可能有个“奇怪”的问题。我正在使用LinuxMint和python,经过一些“会话”之后,我认为linux变得非常慢。我有时会中止python脚本,因为我看到它出了问题或其他什么。如果我重新启动我的电脑,我知道它运行得很快 其他一些迭代步骤也是如此:例如:在一些Python会话之后,Linux变得越来越慢,python,linux,performance,numpy,Python,Linux,Performance,Numpy,我可能有个“奇怪”的问题。我正在使用LinuxMint和python,经过一些“会话”之后,我认为linux变得非常慢。我有时会中止python脚本,因为我看到它出了问题或其他什么。如果我重新启动我的电脑,我知道它运行得很快 其他一些迭代步骤也是如此:例如: for test in tests: os.system("python code.py "+something[i][0]+" "+something[i][1]+" 3 "+test+" usage") 在迭代2或3中,代码变
for test in tests:
os.system("python code.py "+something[i][0]+" "+something[i][1]+" 3 "+test+" usage")
在迭代2或3中,代码变得越来越慢。有没有可能,我使用的numpy数组不正确?或者python有没有可能不删除“last”seassion,而是将其保存在Linux的“后台”中?很抱歉,如果问题有点“糟糕”,现在不要讨论python的行为
在LinuxMint和Ubuntu2台计算机上进行了尝试
我的电脑:
至强E3-1231 v3,16GB DDR3
MCVE
def手动(测试,测试2):
#拆分为X和y
X=[]
y=[]
例如,这段代码将使用另一个python文件执行5次,就像我在开始时提到的os.system顺序一样
看起来,这只发生在Linux上,而不是在windows上。你能提供一个例子吗?我添加了一些东西,但如果这些真的有用的话,现在就不需要了。一般来说,在很多蟒蛇“开始”或“中止”之后,例如50年后。。。Linux的速度越来越慢。如果我启动控制中心查看任务,还有10个python任务。。其中4个是使用的(并行化的原因),另外6个不是从CPU使用的。你能修复你的缩进吗?当代码执行时,Python进程使用的资源(CPU、内存)会发生什么变化?例如,您可以使用
htop
进行检查。
import numpy as np
from sklearn.ensemble import RandomForestClassifier
target=int(sys.argv[3])
method=sys.argv[4]
vs=sys.argv[5]
for i,j in enumerate(test):
X.append(test[i][0])
y.append(float(test[i][1]))
x=np.array(X)
y=np.array(y)
pRF={
'class_weight':['balanced_subsample'],
'n_estimators':treeRange,
'max_features':['sqrt'],
'min_samples_leaf':[1,2,3]}
classifiers=[RandomForestClassifier(random_state=1)]
paraCV=[pRF]
titles=['RF']
for name, clf, parCV in zip(titles,classifiers,paraCV):
fol=10
skf = StratifiedKFold(y, n_folds=fol)
pre,sen,spe,ba,area,params,scores=[],[],[],[],[],[],[]
#outer loop
for train_index, test_index in skf:
#inner loop
#print train_index, test_index
predi=[]
train=train_index.tolist()
test=test_index.tolist()
X_train=[]
X_test=[]
y_train=[]
y_test=[]
for i in train:
X_train.append(x[i])
for i in test:
X_test.append(x[i])
for i in train:
y_train.append(y[i])
for i in test:
y_test.append(y[i])
gs = GridSearchCV(estimator=clf,param_grid=parCV,cv=fol,n_jobs=5).fit(X_train,y_train)
expected= [0.0 if z==2.0 else z for z in y_test]
predicted=gs.predict_proba(X_test)
predicted1= predicted[:,0].tolist()
params.append(gs.best_params_)
expi=expected
expected=np.array(expected)
# and so on.. code would be way to long for an MCVE
if __name__=="__main__":
train=sys.argv[1]
test=sys.argv[2]