Navigation

    Quantiacs Community

    • Register
    • Login
    • Search
    • Categories
    • News
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Q17 Machine learning - RidgeRegression (Long/Short); there is an error in the code

    Strategy help
    3
    4
    485
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      EDDIEE last edited by

      The loop "for asset_name in asset_name_all:" creates a model for each asset, but the individual models are never saved. At the end, the model for the last asset is returned and all the predictions are created based on this last model (asset 'XRP').

      def train_model(data):
      """Create and train the models working on an asset-by-asset basis."""

      asset_name_all = data.coords['asset'].values
      
      data = data.sel(time=slice('2013-05-01',None)) # cut the noisy data head before 2013-05-01
      
      features_all = get_features(data)
      target_all = get_target_classes(data)
      
      model = create_model()
      
      for asset_name in asset_name_all:
          
          # drop missing values:
          target_cur = target_all.sel(asset=asset_name).dropna('time', 'any')
          features_cur = features_all.sel(asset=asset_name).dropna('time', 'any')
      
          # align features and targets:
          target_for_learn_df, feature_for_learn_df = xr.align(target_cur, features_cur, join='inner')
      
          if len(features_cur.time) < 10:
              # not enough points for training
              continue
      
          
          
          try:
              model.fit(feature_for_learn_df.values, target_for_learn_df)
          except KeyboardInterrupt as e:
              raise e
          except:
              logging.exception('model training failed')
      
      return model
      support 1 Reply Last reply Reply Quote 1
      • support
        support @EDDIEE last edited by

        @eddiee Thanks a lot. If you have some good fix, could you upload it to our repo in github? Or send a snippet here, we will happily update it. Sorry for the issue.

        E 1 Reply Last reply Reply Quote 0
        • E
          EDDIEE @support last edited by

          @support

          This is a possible fix, but no gurantee. You have to adjust also the prediction function.

          def train_model(data):
          """Create and train the models working on an asset-by-asset basis."""

          models = dict()

          asset_name_all = data.coords['asset'].values

          data = data.sel(time=slice('2013-05-01',None)) # cut the noisy data head before 2013-05-01

          features_all = get_features(data)
          target_all = get_target_classes(data)

          model = create_model()

          for asset_name in asset_name_all:

          # drop missing values:
          target_cur = target_all.sel(asset=asset_name).dropna('time', 'any')
          features_cur = features_all.sel(asset=asset_name).dropna('time', 'any')
          
          # align features and targets:
          target_for_learn_df, feature_for_learn_df = xr.align(target_cur, features_cur, join='inner')
          
          if len(features_cur.time) < 10:
              # not enough points for training
              continue
          
          
          
          try:
              model.fit(feature_for_learn_df.values, target_for_learn_df)
              models[asset_name] = model
          except KeyboardInterrupt as e:
              raise e
          except:
              logging.exception('model training failed')
          

          return models

          1 Reply Last reply Reply Quote 0
          • A
            aluminum.pig Banned last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB | Contributors
            • Documentation
            • About
            • Career
            • My account
            • Privacy policy
            • Terms and Conditions
            • Cookies policy
            Home
            Copyright © 2014 - 2021 Quantiacs LLC.
            Powered by NodeBB | Contributors