def testRSENFailsIfNonBinaryMatrixSentIn(self):
     self.train_features[0][0] = 2
     error = ""
     try:
         model = RandomSubsetElasticNet(1, 2, self.binary_feature_indices)
         model.fit(self.train_features, self.train_results)
     except ValueError as valueError:
         error = SafeCastUtil.safeCast(valueError, str)
     assert "Non-binary feature" in error
    def train(self, results, features, hyperparams, feature_names):
        binary_feature_indices = self.fetchBinaryFeatureIndices(feature_names)
        model = RandomSubsetElasticNet(
            hyperparams.get(self.ALPHA),
            hyperparams.get(self.L_ONE_RATIO),
            binary_feature_indices,
            p=self.p_val,
            explicit_phrases=self.determineExplicitPhrases(hyperparams))

        model.fit(features, results)
        self.log.debug(
            "Successful creation of Random Subset Elastic Net model: %s\n",
            model)
        return model
    def trainModelWithExplicitNumberOfPhrases(self, phrase_count, at_least):
        num_phrases = 0
        model = None
        explicit_count = 0
        if not at_least:
            explicit_count = phrase_count
        while (not at_least and num_phrases != phrase_count) or (at_least and num_phrases < phrase_count):

            model = RandomSubsetElasticNet(1, 0.5, self.binary_feature_indices, upper_bound=0.5, lower_bound=0, p=0,
                                           explicit_model_count=(explicit_count - 1))
            model.fit(self.train_features, self.train_results)
            num_phrases = len(model.models_by_phrase)
            [self.assertScore(model_phrase) for model_phrase in model.models_by_phrase if model_phrase.phrase.value is not None]

        return model
 def assertInvalidParams(self, binary_feature_indices, alpha=1, l_one_ratio=2, upper_bound=0.5, lower_bound=0.1, p=0,
                         explicit_model_count=-1, max_boolean_generation_attempts=10,
                         default_coverage_threshold=0.8, explicit_phrases=None):
     error = ""
     try:
         RandomSubsetElasticNet(alpha, l_one_ratio, binary_feature_indices, upper_bound=upper_bound,
                                lower_bound=lower_bound, p=p, explicit_model_count=explicit_model_count,
                                max_boolean_generation_attempts=max_boolean_generation_attempts,
                                coverage_threshold=default_coverage_threshold, explicit_phrases=explicit_phrases)
     except AttributeError as attributeError:
         error = SafeCastUtil.safeCast(attributeError, str)
     assert "invalid parameters" in error