h2o-py/h2o/demos.py
def deeplearning(interactive=True, echo=True, testing=False):
    """Deep Learning model demo."""

    def demo_body(go):
        """
        Demo of H2O's Deep Learning model.

        This demo uploads a dataset to h2o, parses it, and shows a description.
        Then it divides the dataset into training and test sets, builds a GLM
        from the training set, and makes predictions for the test set.
        Finally, default performance metrics are displayed.
        """
        go()
        # Connect to H2O
        h2o.init()

        go()
        # Upload the prostate dataset that comes included in the h2o python package
        prostate = h2o.load_dataset("prostate")

        go()
        # Print a description of the prostate data
        prostate.describe()

        go()
        # Randomly split the dataset into ~70/30, training/test sets
        train, test = prostate.split_frame(ratios=[0.70])

        go()
        # Convert the response columns to factors (for binary classification problems)
        train["CAPSULE"] = train["CAPSULE"].asfactor()
        test["CAPSULE"] = test["CAPSULE"].asfactor()

        go()
        # Build a (classification) GLM
        from h2o.estimators import H2ODeepLearningEstimator
        prostate_dl = H2ODeepLearningEstimator(activation="Tanh", hidden=[10, 10, 10], epochs=10000)
        prostate_dl.train(x=list(set(prostate.col_names) - {"ID", "CAPSULE"}),
                          y="CAPSULE", training_frame=train)

        go()
        # Show the model
        prostate_dl.show()

        go()
        # Predict on the test set and show the first ten predictions
        predictions = prostate_dl.predict(test)
        predictions.show()

        go()
        # Show default performance metrics
        performance = prostate_dl.model_performance(test)
        performance.show()

    # Execute:
    _run_demo(demo_body, interactive, echo, testing)
def deeplearning(interactive=True, echo=True, testing=False):
    """Deep Learning model demo."""

    def demo_body(go):
        """
        Demo of H2O's Deep Learning model.

        This demo uploads a dataset to h2o, parses it, and shows a description.
        Then it divides the dataset into training and test sets, builds a GLM
        from the training set, and makes predictions for the test set.
        Finally, default performance metrics are displayed.
        """
        go()
        # Connect to H2O
        h2o.init()

        go()
        # Upload the prostate dataset that comes included in the h2o python package
        prostate = h2o.load_dataset("prostate")

        go()
        # Print a description of the prostate data
        prostate.describe()

        go()
        # Randomly split the dataset into ~70/30, training/test sets
        train, test = prostate.split_frame(ratios=[0.70])

        go()
        # Convert the response columns to factors (for binary classification problems)
        train["CAPSULE"] = train["CAPSULE"].asfactor()
        test["CAPSULE"] = test["CAPSULE"].asfactor()

        go()
        # Build a (classification) GLM
        from h2o.estimators import H2ODeepLearningEstimator
        prostate_dl = H2ODeepLearningEstimator(activation="Tanh", hidden=[10, 10, 10], epochs=10000)
        prostate_dl.train(x=list(set(prostate.col_names) - {"ID", "CAPSULE"}),
                          y="CAPSULE", training_frame=train)

        go()
        # Show the model
        prostate_dl.show()

        go()
        # Predict on the test set and show the first ten predictions
        predictions = prostate_dl.predict(test)
        predictions.show()

        go()
        # Show default performance metrics
        performance = prostate_dl.model_performance(test)
        performance.show()

    # Execute:
    _run_demo(demo_body, interactive, echo, testing)
def deeplearning ( interactive = True , echo = True , testing = False ) : def demo_body ( go ) : """
        Demo of H2O's Deep Learning model.

        This demo uploads a dataset to h2o, parses it, and shows a description.
        Then it divides the dataset into training and test sets, builds a GLM
        from the training set, and makes predictions for the test set.
        Finally, default performance metrics are displayed.
        """ go ( ) # Connect to H2O h2o . init ( ) go ( ) # Upload the prostate dataset that comes included in the h2o python package prostate = h2o . load_dataset ( "prostate" ) go ( ) # Print a description of the prostate data prostate . describe ( ) go ( ) # Randomly split the dataset into ~70/30, training/test sets train , test = prostate . split_frame ( ratios = [ 0.70 ] ) go ( ) # Convert the response columns to factors (for binary classification problems) train [ "CAPSULE" ] = train [ "CAPSULE" ] . asfactor ( ) test [ "CAPSULE" ] = test [ "CAPSULE" ] . asfactor ( ) go ( ) # Build a (classification) GLM from h2o . estimators import H2ODeepLearningEstimator prostate_dl = H2ODeepLearningEstimator ( activation = "Tanh" , hidden = [ 10 , 10 , 10 ] , epochs = 10000 ) prostate_dl . train ( x = list ( set ( prostate . col_names ) - { "ID" , "CAPSULE" } ) , y = "CAPSULE" , training_frame = train ) go ( ) # Show the model prostate_dl . show ( ) go ( ) # Predict on the test set and show the first ten predictions predictions = prostate_dl . predict ( test ) predictions . show ( ) go ( ) # Show default performance metrics performance = prostate_dl . model_performance ( test ) performance . show ( ) # Execute: _run_demo ( demo_body , interactive , echo , testing )
Deep Learning model demo.
Deep Learning model demo .