Exemple #1
0
    def predict_proba(self, X, regression=False):
        X = self.tfidf.transform(X)
        if regression:
            raise ValueError('Cannot predict probabilites of a regression!')
        else:
            return self.rfc.predict_proba(X)


if __name__ == '__main__':
    traits = ['OPN', 'CON', 'EXT', 'AGR', 'NEU']
    model = Model()

    for trait in traits:
        dp = DataPrep()
        X_regression, y_regression = dp.prep_data('status',
                                                  trait,
                                                  regression=True,
                                                  model_comparison=False)
        X_categorical, y_categorical = dp.prep_data('status',
                                                    trait,
                                                    regression=False,
                                                    model_comparison=False)
        print('Fitting trait ' + trait + ' regression model...')
        model.fit(X_regression, y_regression, regression=True)
        print('Done!')
        print('Fitting trait ' + trait + ' categorical model...')
        model.fit(X_categorical, y_categorical, regression=False)
        print('Done!')
        with open('static/' + trait + '_model.pkl', 'wb') as f:
            # Write the model to a file.
            pickle.dump(model, f)
Exemple #2
0
        if regression:
            return self.rfr.predict(X)
        else:
            return self.rfc.predict(X)

    def predict_prob(self, X, regression=False):
        X = self.tfidf.transform(X)
        if regression:
            raise ValueError('Cannot predict probabilites of a regression!')
        else:
            return self.rfc.predict_proba(X)


if __name__ == '__main__':
    traits = ['OPN', 'CON', 'EXT', 'AGR', 'NEU']
    model = Model()

    for trait in traits:
        dp = DataPrep()
        X_regression, y_regression = dp.prep_data(trait, regression=True)
        X_categorical, y_categorical = dp.prep_data(trait, regression=False)
        print('Entrenando rasgo ' + trait + ' con modelo regression...')
        model.fit(X_regression, y_regression, regression=True)
        print('Hecho!')
        print('Entrenando rasgo ' + trait + ' con modelo categorical...')
        model.fit(X_categorical, y_categorical, regression=False)
        print('Hecho!')
        with open('static/' + trait + '_model.pkl', 'wb') as f:
            # Write the model to a file.
            pickle.dump(model, f)
    print("Entrenamiento terminado!")