Package: awtest
GapLearnGapLearn bridges gaps between other machine learning and deep learning tools. All models can be passed to the functions below regardless of the framework they were built upon (scikit-learn, tensorflow, xgboost, or even good ole numpy).My first package objective is to bring transparency to the often black-boxy model training process by making by making robust post-mortem analysis of the hyperparameter and feature selection processes possible. The functions below also further automate some processes while still giving the user full control of the results.Many features are on their way. Unit tests and full documentation will be added shortly.The source code is available onGitHubInstallationpipinstallgaplearnSee the latest version onPyPISubmodulescvThecvsubmodule will have these classes (sfs has been released):sfsDescription:This is a sequential feature selector that enables you to perform backwards elimination with any model (not just a linear regression).At each step, the feature that has the lowest permutation importance is selected for removal. The permutation importance is measured as the decrease in accuracy by default, but the user can pass any custom scoring function.Improvements on their way:Add forward selection and all subsets testingAdd more built-in scoring functions to for assessing feature permutation importanceCreate custom permutation scoring method to removeeli5as a dependencyEnable a user to get the feature set that matches a certain criteria ("has n features", "has score > x")Methodsbackwards_elimination(X, y, model = 'logit', params = {}, fit_function = None, predict_function = None, score_function = None, score_name = 'accuracy', cols = [], verbose = 0)Run the backwards eliminationParams:X: (DataFrame or matrix) with independent variablesy: (iterable) dependent corresponding variable valuesparams: (dict) parameter set for modelmodel: (str or custom model type) if str ('logit' or 'rfc'), a corresponding sci-kit learn model will be used; if custom model type, the model you pass will be usedfit_function: (function) the function that will be used to train the model; the function must accept the parametersmodel,X, andy; if this value is not set,backwards_eliminationwill attempt to use your model'sfitmethodpredict_function: (function) the function that will be used to make predictions with the model; the function must accept the parametersmodel, andX; if this value is not set,backwards_eliminationwill attempt to use your model'spredictmethodscore_function: (function) the function that will be used to score the model and determine the feature permutation importance; the function must accept the parametersyandpreds; if this value is not set, the accuracy will be usedscore_name: (str) name of the score calculated by thescore_function; 'accuracy' by defaultExample:importpandasaspdfromgaplearn.cvimportsfs#### Perform a backwards elimination with sci-kit learn's random forest model ####X=pd.read_csv('X_classification.csv')y=pd.read_csv('y_classification.csv')fs_rfc=sfs()print('The backwards elimination has been run:{}'.format(fs_rfc.be_complete))fs_rfc.backwards_elimination(X,y,model='rfc',params={'n_jobs':-1})# Get the step-by-step summarysummary_rfc=fs_rfc.get_summary_be()# Alternatively, `summary_rfc = fs_rfc.summary_be`# Get the predictions and true values for each observationresults_rfc=fs_rfc.get_results_be()# Alternatively, `results_rfc = fs_rfc.results_be# Get the features used in the analysisfeatures_rfc=fs_rfc.features_be# Alternatives, `sorted(list(results_rfc['feature to remove']))# Identify which feature set can achieve at least 85% accuracy with the smallest number of featuressummary_rfc[summary_rfc['overall accuracy']>.85]#### Perform a more complex backwards elimination with sci-kit learn's naive bayes model ####fromsklearn.linear_modelimportSGDRegressormodel_sgd=SGDRegressor(loss='modified_huber',penalty='elasticnet')X=pd.read_csv('X_regression.csv')y=pd.read_csv('y_regression.csv')fs_nb=sfs()defmse(y,preds):score=sum([(preds[i]-y[i])**2foriinrange(y.shape[0])])/y.shape[0]returnscoredefarbitrary_prediction(model,X):preds=model.predict(X)+1# arbitrarily deciding to add 1 to the prediction (realistically, this would be a wrapper for model that don't have a `fit` method)returnpredsfs_nb.backwards_elimination(X,y,model=model_sgd,predict_function=arbitrary_prediction,score_function=mse)# Get the step-by-step summarysummary_nb=fs_nb.get_summary_be()# Alternatively, `summary = fs_nb.summary_be`# Get the predictions and true values for each observationresults_nb=fs_nb.get_results_be()# Alternatively, `results = fs_nb.results_be# Get the features used in the analysisfeatures_nb=fs_nb.features_be# Alternatives, `sorted(list(results['feature to remove']))param_search_cluster (in development)Description:This is a hyperparameter grid/random search for clustering algorithmsUnlike other grid/random search algorithms, this one enables you to get the observation-by-observation results from each parameter set so that you can do deep post-mortem analysis of the grid/random search.param_search (in development)Description:This is a hyperparameter grid/random search for both regression algorithms and classification algorithmsUnlike other grid/random search algorithms, this one enables you to get the observation-by-observation results from each parameter set so that you can do deep post-mortem analysis of the grid/random search.data_engThedata_engsubmodule will have these classes (sfs has been released):distributed_sql (in development)Description:This enables users to chunk multi-parameter sql queries and process them on multiple threads.