# Path: insults/util.py
# def make_sure_path_exists(path):
# def data_file(category, name=None):
# def data_directory(category):
# def log_file(name):
# def save_folds(folds):
# def saved_folds():
# def save_model( clf, location=SAVEFILE_LOCATION ):
# def load_model( location=SAVEFILE_LOCATION, model_filename=MODEL_FILENAME):
# def get_parser():
# def tied_rank(x):
# def auc(actual, posterior):
# def score():
# SAVEFILE_LOCATION = "models/stored/"
# MODEL_FILENAME = "insult_classifier.joblib.pkl"


import os
import numpy as np
import logging
from sklearn.externals import joblib
from sklearn import linear_model
from insults import util
        for i in range(0,self.max_iter,self.n_iter):

            if self.coef_ is not None:
                assert(self.intercept_ is not None)
                linear_model.SGDRegressor.fit(self,X,y,coef_init=self.coef_,intercept_init=self.intercept_)
            else:
                linear_model.SGDRegressor.fit(self,X,y)
            # record coefs and intercept for later
            self.stages_.append((i+self.n_iter,self.coef_.copy(),self.intercept_.copy()))
            logging.info('done %d/%d steps' % (i+self.n_iter,self.max_iter))
            logging.info('training set auc %f' % self.auc(X,y))

    def auc(self,X,y):
        yhat = self.predict(X)
        return util.auc(np.array(y),yhat)

    def staged_predict(self,X):
        """
        Predict after each of the stages.
        """
        return [(n_iter_,self.predict(X,coef=coef_,intercept=intercept_)) for (n_iter_,coef_,intercept_) in self.stages_]

    def staged_auc(self,X,y):
        """
        calculate the AUC after each of the stages.

        returns: ns   -- list of iteration numbers
                 aucs -- list of corresponding areas under the curve.
        """
        y = np.array(y)

# Path: insults/util.py
# def make_sure_path_exists(path):
# def data_file(category, name=None):
# def data_directory(category):
# def log_file(name):
# def save_folds(folds):
# def saved_folds():
# def save_model( clf, location=SAVEFILE_LOCATION ):
# def load_model( location=SAVEFILE_LOCATION, model_filename=MODEL_FILENAME):
# def get_parser():
# def tied_rank(x):
# def auc(actual, posterior):
# def score():
# SAVEFILE_LOCATION = "models/stored/"
# MODEL_FILENAME = "insult_classifier.joblib.pkl"


# Path: insults/classifier.py
import os
import numpy as np
import logging
from sklearn.externals import joblib
from sklearn import linear_model
from insults import util

        for i in range(0,self.max_iter,self.n_iter):

            if self.coef_ is not None:
                assert(self.intercept_ is not None)
                linear_model.SGDRegressor.fit(self,X,y,coef_init=self.coef_,intercept_init=self.intercept_)
            else:
                linear_model.SGDRegressor.fit(self,X,y)
            # record coefs and intercept for later
            self.stages_.append((i+self.n_iter,self.coef_.copy(),self.intercept_.copy()))
            logging.info('done %d/%d steps' % (i+self.n_iter,self.max_iter))
            logging.info('training set auc %f' % self.auc(X,y))

    def auc(self,X,y):
        yhat = self.predict(X)
        return util.auc(np.array(y),yhat)

    def staged_predict(self,X):
        """
        Predict after each of the stages.
        """
        return [(n_iter_,self.predict(X,coef=coef_,intercept=intercept_)) for (n_iter_,coef_,intercept_) in self.stages_]

    def staged_auc(self,X,y):
        """
        calculate the AUC after each of the stages.

        returns: ns   -- list of iteration numbers
                 aucs -- list of corresponding areas under the curve.
        """
        y = np.array(y)

        results = [ (n, util.auc(y,p)) for n,p in self.staged_predict(X)]