Python代码
load_model.py
def load_model(path):
df=process_data(path)
load_model=XGBClassifier()
load_model=joblib.load("C:\\Users\\DELL\\Desktop\\model.pkl")
y_pred=load_model.predict(df)
return y_pred
if __name__ == '__main__':
print(load_model(sys.argv[1]))
C#代码
using System;
using System.Collections;
using System.Diagnostics;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Process p = new Process();
string path = @"C:\Users\DELL\Desktop\load_model.py";
string sArguments = path;
string pysgv = @"C:\Users\DELL\Desktop\canshu";//py文件需要传的参数
sArguments += " " + pysgv;
p.StartInfo.FileName = @"python.exe"; //python3.6的安装路径
p.StartInfo.Arguments = sArguments;//python命令的参数
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();//启动进程
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();//关键,等待外部程序退出后才能往下执行}
Console.Write(output);//输出
Console.Write("执行完毕!");
p.Close();
}
}
}