1

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

1
  • 1
    call Friedman1Test() directly instead of the friedman_1.Friedman1Test(), as mentioned in my answer. Commented Aug 15, 2021 at 20:47

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.