Reputation: 4210
I have 2 jupyter notebooks, first one is named friedman_1.ipynb and I defined a class. In 2nd jupyter notebook, I can import it without error. However I got an error when calling the class method. see below. Thanks for your help.
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
in 2nd jupyter notebook, I am trying to import the module and call its class method, then I got an error
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
Upvotes: 1
Views: 286
Reputation: 5184
Try this
from ipynb.fs.full.friedman_1 import *
# create the Friedman-1 test class:
friedman = Friedman1Test(NUM_OF_FEATURES, NUM_OF_SAMPLES, RANDOM_SEED)
friedman
You have already imported the class when you use the asterisk, you just need to call the class constructor directly.
Upvotes: 1
Reputation: 19322
You are already importing all the functions and classes into the notebook. Try the following directly. -
from ipynb.fs.full.friedman_1 import *
friedman = Friedman1Test(NUM_OF_FEATURES, NUM_OF_SAMPLES, RANDOM_SEED)
friedman
Upvotes: 1