栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

.py脚本运行另一个python文件(Linux,Windows)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

.py脚本运行另一个python文件(Linux,Windows)

最主要的一句代码是:
import os
os.system('python train.py')
下面是我自己写的进行五折验证的代码。
from sklearn.model_selection import KFold
import numpy as np
import os

with open("./dataset/all.txt", "r") as f:
    lines = []
    for line in f.readlines():
        line = line.strip('n')  #去掉列表中每一个元素的换行符
        lines.append(line)
        # print(line)
    num = 1
    X = np.arange(1549)
    # y = np.random.choice([1,2],12,p=[0.4,0.6])
    kf = KFold(n_splits=5,shuffle=True,random_state=0)  # 初始化KFold
    for train_index , test_index in kf.split(X):  # 调用split方法切分数据
        with open("./dataset/train.txt","w") as ft:
              
            for i in train_index:
                # print(i)
                ft.write(lines[i] + 'n')
        with open("./dataset/val.txt","w") as fv:
            
            for i in test_index:
                # print(i)
                fv.write(lines[i]+'n')
        # os.system('nohup python train%d.py > out%d.log'%(num,num))
        os.system('python train%d.py  > out%d.log'%(num,num))
        num = num + 1 
        

 
        
    

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/757259.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号