dssg/catwalk

View on GitHub

Showing 28 of 28 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

            for pct_thresh in group.get('thresholds', {}).get('percentiles', []):
                logging.info('Processing percent threshold %s', pct_thresh)
                predicted_classes = numpy.array(generate_binary_at_x(
                    predictions_proba_sorted,
                    pct_thresh,
Severity: Major
Found in catwalk/evaluation.py and 1 other location - About 1 day to fix
catwalk/evaluation.py on lines 247..263

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 123.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

            for abs_thresh in group.get('thresholds', {}).get('top_n', []):
                logging.info('Processing absolute threshold %s', abs_thresh)
                predicted_classes = numpy.array(generate_binary_at_x(
                    predictions_proba_sorted,
                    abs_thresh,
Severity: Major
Found in catwalk/evaluation.py and 1 other location - About 1 day to fix
catwalk/evaluation.py on lines 228..244

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 123.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

File model_trainers.py has 422 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from sklearn.model_selection import ParameterGrid

from sqlalchemy.orm import sessionmaker

import importlib
Severity: Minor
Found in catwalk/model_trainers.py - About 6 hrs to fix

    File evaluation.py has 282 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import numpy
    from results_schema import Evaluation
    from catwalk.utils import db_retry, sort_predictions_and_labels
    from catwalk.metrics import *
    from sqlalchemy.orm import sessionmaker
    Severity: Minor
    Found in catwalk/evaluation.py - About 2 hrs to fix

      File storage.py has 256 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      from .utils import upload_object_to_key, key_exists, model_cache_key, download_object
      import os
      import pickle
      import pandas
      import yaml
      Severity: Minor
      Found in catwalk/storage.py - About 2 hrs to fix

        Function __init__ has 14 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(self, penalty='l2', dual=False, tol=1e-4, C=1.0,
        Severity: Major
        Found in catwalk/estimators/classifiers.py - About 1 hr to fix

          Function _write_to_db has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def _write_to_db(
                  self,
                  model_id,
                  matrix_store,
                  predictions,
          Severity: Minor
          Found in catwalk/predictors.py - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Similar blocks of code found in 4 locations. Consider refactoring.
          Open

          @Metric(greater_is_better=False)
          def false_positives(_, predictions_binary, labels, parameters):
              return int(confusion_matrix(labels, predictions_binary)[0,1])
          Severity: Major
          Found in catwalk/metrics.py and 3 other locations - About 1 hr to fix
          catwalk/metrics.py on lines 87..89
          catwalk/metrics.py on lines 97..99
          catwalk/metrics.py on lines 102..104

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 38.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 4 locations. Consider refactoring.
          Open

          @Metric(greater_is_better=False)
          def false_negatives(_, predictions_binary, labels, parameters):
              return int(confusion_matrix(labels, predictions_binary)[1,0])
          Severity: Major
          Found in catwalk/metrics.py and 3 other locations - About 1 hr to fix
          catwalk/metrics.py on lines 87..89
          catwalk/metrics.py on lines 92..94
          catwalk/metrics.py on lines 97..99

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 38.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 4 locations. Consider refactoring.
          Open

          @Metric(greater_is_better=True)
          def true_negatives(_, predictions_binary, labels, parameters):
              return int(confusion_matrix(labels, predictions_binary)[0,0])
          Severity: Major
          Found in catwalk/metrics.py and 3 other locations - About 1 hr to fix
          catwalk/metrics.py on lines 87..89
          catwalk/metrics.py on lines 92..94
          catwalk/metrics.py on lines 102..104

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 38.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 4 locations. Consider refactoring.
          Open

          @Metric(greater_is_better=True)
          def true_positives(_, predictions_binary, labels, parameters):
              return int(confusion_matrix(labels, predictions_binary)[1,1])
          Severity: Major
          Found in catwalk/metrics.py and 3 other locations - About 1 hr to fix
          catwalk/metrics.py on lines 92..94
          catwalk/metrics.py on lines 97..99
          catwalk/metrics.py on lines 102..104

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 38.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Function _write_model_to_db has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def _write_model_to_db(
          Severity: Major
          Found in catwalk/model_trainers.py - About 50 mins to fix

            Function evaluate has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def evaluate(
            Severity: Minor
            Found in catwalk/evaluation.py - About 45 mins to fix

              Function _generate_evaluations has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def _generate_evaluations(
              Severity: Minor
              Found in catwalk/evaluation.py - About 45 mins to fix

                Function matrix_with_sorted_columns has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def matrix_with_sorted_columns(self, columns):
                        columnset = set(self.columns())
                        desired_columnset = set(columns)
                        if columnset == desired_columnset:
                            if self.columns() != columns:
                Severity: Minor
                Found in catwalk/storage.py - About 45 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function _entity_feature_values has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                def _entity_feature_values(matrix, feature_name, as_of_date=None):
                    """Finds the value of the given feature for each entity in a matrix
                
                    Args:
                        matrix (pandas.DataFrame), with index either 'entity_id' or 'entity_id'/'as_of_date'
                Severity: Minor
                Found in catwalk/individual_importance/uniform.py - About 45 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def __init__(
                Severity: Minor
                Found in catwalk/model_trainers.py - About 45 mins to fix

                  Function _train_and_store_model has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def _train_and_store_model(
                  Severity: Minor
                  Found in catwalk/model_trainers.py - About 45 mins to fix

                    Function process_train_task has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        def process_train_task(
                    Severity: Minor
                    Found in catwalk/model_trainers.py - About 35 mins to fix

                      Function _write_to_db has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          def _write_to_db(
                      Severity: Minor
                      Found in catwalk/predictors.py - About 35 mins to fix
                        Severity
                        Category
                        Status
                        Source
                        Language