小编Ros*_*ent的帖子

当培训和测试中的功能数量不同时,如何在生产环境中处理“一键编码”?

在进行某些实验时,我们通常训练70%,然后测试33%。但是,当您的模型投入生产时会发生什么?可能会发生以下情况:

训练集:

-----------------------
| Ser |Type Of Car    |
-----------------------
|  1  | Hatchback     |
|  2  | Sedan         |
|  3  | Coupe         |
|  4  | SUV           |
-----------------------
Run Code Online (Sandbox Code Playgroud)

经过一键热编码后,我们得到的是:

-----------------------------------------
| Ser | Hatchback | Sedan | Coupe | SUV |
-----------------------------------------
|  1  |     1     |   0   |   0    |  0 |
|  2  |     0     |   1   |   0    |  0 |
|  3  |     0     |   0   |   1    |  0 |
|  4 …
Run Code Online (Sandbox Code Playgroud)

python machine-learning feature-selection one-hot-encoding

4
推荐指数
2
解决办法
701
查看次数

Python:捕获异常后如何停止执行?

我有一个类 dataset.py ,它有很多函数,还实现了一个记录器,如下所示:

class dataset:
    def get_data():
        try:
            if(sourcefile != None):
                if not os.path.isfile(sourceFile):
                    raise FileNotFoundError
        except FileNotFoundError:
            logger.error('File not found!')
    def do_something():
        return
Run Code Online (Sandbox Code Playgroud)

我通过以下方式使用这些类:

datasetObj = dataset()
datasetObj.get_data()
datasetObj.do_something()
Run Code Online (Sandbox Code Playgroud)

现在,即使 get_data() 引发 FileNotFoundError,它也会在 except 块中处理,并且程序继续转到 do_something()。

我该如何阻止这个?如果出现文件未找到错误,则应停止执行。如何将异常返回给调用者并使 main.py 不再执行?

python exception try-catch

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