CountVectorizerseems a bit dense and tries to do too much. This is not a bad thing but from a design viewpoint, it could benefit from making use of thePipelineframework and separately define thepreprocessorandtokenizeror even justanalyzeras transformers in and of themselves and defineCountVectorizeras a pipeline of these operatons. Should conform or make use of existing frameworks where possible rather than extending functionality to allow for exceptions.- Functions from the
metricmodule such asconfusion_matrixandclassification_reportought to support cross-validation by perhaps allowing acvparameter. This might be awkward given that we already havecross_val_scoreandlearning_curveand those are supposed to be the functions which take care of cross validation scoring. It might make sense to useconfusion_matrixas the scoring function forcross_val_scorebut the latter only accepts scoring functions which return a single value so that won't work. The other thing is thatcross_val_scorecan only work with one scoring function at a time for if we wanted to define our own cross-validatedclassification_reportor just make use ofcross_val_scorefor differenct metrics, we'd need to train the model again each time for every metric we want to use to evaluate the under cross-validation. - The
learning_curvemethod should behave consistently withcross_val_scorein that it should return a value (or in this case a learning curve) for each cross-validation fold, rather the just the mean. - The
learning_curvemethod still has the bug where there might only be a single class when the training sets are partitioned into the defined training sizes._safe_splitor whichever helper function used to partition the training data should ensure that no partition has only one class. It might not be a good idea to reorder the instances of the training data so that the targets arr ordered like['class_0', 'class_1', 'class_2', 'class_0', 'class_1', 'class_2', ..., 'class_0', 'class_1', 'class_2'](as has been suggested scikit-learn/scikit-learn#2701 (comment)) as for many learning algorithms, the search through the hypothese space is very much affected or even sometimes guided by the order of the training data. It is worth noting that a shuffle might be enough but we just need to calculate and document the probability that a partition contains only one class after a uniformly distributed shuffle. - The
chi2univariate feature selection metric is still somewhat of a mystery as it is not clear what it does with frequencies vs. categorical variables. In fact, it is not even clear what occurs in the case of categorical vs. categorical variables since the chi-squared calculation obtained from explicitly enumerating the contingency table is inconsistent withchi2. See http://stackoverflow.com/questions/21281328/scikit-learn-chi-squared-statistic-and-corresponding-contingency-table - I've just been trying to work with
RFECVfor the last few hours and found a number of issues. Some of these have already been mentioned above but I will list them again for completeness and elaboration. grid_scores_is of shape[n_features]but the documentation states it is[n_subsets_of_features]. Note that with a normalized value of step (i.e.
if 0.0 < self.step < 1.0:
step = int(self.step * n_features)
else:
step = int(self.step)