我有两个jupyter笔记本,第一个名为friedman_1.ipynb,我定义了一个类。在第二个jupyter笔记本中,我可以毫无错误地导入它。但是,我在调用类方法时出错。见下文。谢谢你的帮助
class Friedman1Test:
"""This class encapsulates the Friedman1 regression test for feature selection
"""
VALIDATION_SIZE = 0.20
NOISE = 1.0
def __init__(self, numFeatures, numSamples, randomSeed):
"""
:param numFeatures: total number of features to be used (at least 5)
:param numSamples: number of samples in dataset
:param randomSeed: random seed value used for reproducible results
"""
self.numFeatures = numFeatures
self.numSamples = numSamples
self.randomSeed = randomSeed
在第二个jupyter笔记本中,我试图导入模块并调用其类方法,然后我得到了一个错误
from ipynb.fs.full.friedman_1 import *
# create the Friedman-1 test class:
friedman = friedman_1.Friedman1Test(NUM_OF_FEATURES, NUM_OF_SAMPLES, RANDOM_SEED)
friedman
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-12-48edeee5c421> in <module>
1 # create the Friedman-1 test class:
----> 2 friedman = friedman_1.Friedman1Test(NUM_OF_FEATURES, NUM_OF_SAMPLES, RANDOM_SEED)
3 friedman
NameError: name 'friedman_1' is not defined
您已经将所有函数和类导入笔记本。直接尝试下列方法
试试这个
当您使用星号时已经导入了类,您只需要直接调用类构造函数
相关问题 更多 >
编程相关推荐