Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Planned functionality #1

Open
rhiever opened this issue Feb 29, 2016 · 19 comments
Open

Planned functionality #1

rhiever opened this issue Feb 29, 2016 · 19 comments

Comments

@rhiever
Copy link
Owner

rhiever commented Feb 29, 2016

In the immediate future, datacleaner will:

  • Encode all non-numerical variables as numerical variables
  • Replace all NaNs with the median of the column or drop all NaN rows (configurable)

See this tweet chain for more ideas.

If anyone has more ideas, please add them here.

rhiever added a commit that referenced this issue Mar 2, 2016
Currently only for autoclean()
rhiever added a commit that referenced this issue Mar 2, 2016
rhiever added a commit that referenced this issue Mar 2, 2016
We should use the mode (i.e., most common value) of the column for
categorical variables, and the median for continuous variables.

Since there’s no easy way to detect continuous vs. categorical
variables in pandas, we use a heuristic: If >20% of the values in a
column are unique, then it is probably a continuous variable.
Otherwise, it is probably a categorical variable.

(Related to #1)
rhiever added a commit that referenced this issue Mar 2, 2016
Related to #1 and imputing
@jaumebp
Copy link

jaumebp commented Mar 6, 2016

In my experience it is worth identifying ordinal variables (e.g. numerical grades) and handle then separately. In many cases these can be treated as continuous variables, but sometimes it is necessary to treat them as discrete ones. One example of this is missing value imputation. If treating them as continuous you may end up injecting fake values that then can mislead the downstream analysis.

Thanks for the project! I tested it on some of my biomedical datasets and compared the PCA before/after the cleaning. The only case where there were differences is a dataset with discrete variables (Exome sequencing) and specifically in the columns where some of the values were '0'. There was the following error message:
sys:1: DtypeWarning: Columns (6,19,131,225,404,416,515,651,833,945,975,986,1265,1327,1387,1494,1541,1558,1715,1737,1854,1875,1947,1980,2015,2024,2111,2132,2140,2165,2426,2652,2667,2668,2871,2943,2978,2997,3165,3335,3634,3807,3945,4010,4018,4177,4191,4196,4243,4245,4389,4463,4553,4772,4814,4841,4962) have mixed types. Specify dtype option on import or set low_memory=False.

@rhiever
Copy link
Owner Author

rhiever commented Mar 6, 2016

Indeed, which is why I'm trying to discover how to identify ordinal vs. continuous variables. I posted this question on StackOverflow to brainstorm.

@jaumebp
Copy link

jaumebp commented Mar 6, 2016

In our software we went with a much simpler approach. Letting the user specify a list of attributes to be treated as ordinal. Of course, an automatic solution is far more elegant :)

@westurner
Copy link

"Convenience function: Detect if there are non-numerical features and encode them as numerical features" EpistasisLab/tpot#61

@westurner
Copy link

Do I have to do get_dummies() all by myself?
http://pandas.pydata.org/pandas-docs/stable/generated/pandas.get_dummies.html

... get_dummies() accepts a number of kwargs

@westurner
Copy link

Do I have to do get_dummies() all by myself?

I think it illogical to e.g. average Exterior1st in the Kaggle House Prices Dataset: the average of ImStucc and Wd Sdng seems nonsensical?

@westurner
Copy link

CSVW as JSONLD may be a good way to specify a dataset header with the relevant metadata for such operations? pandas-dev/pandas#3402

@rhiever
Copy link
Owner Author

rhiever commented Dec 14, 2016

You should be able to use the sklearn OneHotEncoder to get the equivalent of the pandas get_dummies().

@westurner
Copy link

You should be able to use the sklearn OneHotEncoder to get the equivalent of the pandas get_dummies().

http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OneHotEncoder.html

Is there a way to specify that I only need certain columns to be expanded into multiple columns w/ OneHotEncoder?

@rhiever
Copy link
Owner Author

rhiever commented Dec 14, 2016

See the docs you linked and the categorical_features parameter.

@westurner
Copy link

@westurner
Copy link

westurner commented Dec 14, 2016

Do I need to write a FunctionTransformer to stack multiple preprocessing modules?

i.e for different columns. Or just run autoclean multiple times?

@rhiever
Copy link
Owner Author

rhiever commented Dec 15, 2016

Running autoclean multiple times might be the easier solution. Might be a useful extension to autocleaner to allow the user to pass multiple preprocessors in a list.

@westurner
Copy link

Might be a useful extension to autocleaner to allow the user to pass multiple preprocessors in a list.

https://github.com/paulgb/sklearn-pandas DataFrameMapper supports various combinations of columns and transformations.

@westurner
Copy link

It may be worth noting that pandas Categoricals have an ordered=True parameter. http://pandas.pydata.org/pandas-docs/stable/categorical.html#sorting-and-order

Does specifying the Categoricals have a different effect than inferring the ordinals from the happenstance sequence of strings in a given dataset?

@adrose
Copy link

adrose commented Feb 13, 2017

any plans to impute NA's rather then replace continuous variables with the median value?

@rhiever
Copy link
Owner Author

rhiever commented Feb 13, 2017

@adrose, do you mean via model-based imputation?

@adrose
Copy link

adrose commented Feb 13, 2017

@rhiever sorry should have been A LOT more specific, but yes something similar to what the Amelia command is doing in this R package - i.e. (bootstrapped linear regression).

Happy to expand on it more, or would be excited to see if you have any thoughts on this function if you think it may be applicable.

@westurner
Copy link

westurner commented Feb 14, 2017

  • https://en.wikipedia.org/wiki/Imputation_(statistics) :

    In statistics, imputation is the process of replacing missing data with substituted values. When substituting for a data point, it is known as "unit imputation"; when substituting for a component of a data point, it is known as "item imputation". There are three main problems that missing data causes: missing data can introduce a substantial amount of bias, make the handling and analysis of the data more arduous, and create reductions in efficiency.[1] Because missing data can create problems for analyzing data, imputation is seen as a way to avoid pitfalls involved with listwise deletion of cases that have missing values. That is to say, when one or more values are missing for a case, most statistical packages default to discarding any case that has a missing value, which may introduce bias or affect the representativeness of the results. Imputation preserves all cases by replacing missing data with an estimated value based on other available information. Once all missing values have been imputed, the data set can then be analysed using standard techniques for complete data.[2] Imputation theory is constantly developing and thus requires consistent attention to new information regarding the subject. There have been many theories embraced by scientists to account for missing data but the majority of them introduce large amounts of bias. A few of the well known attempts to deal with missing data include: hot deck and cold deck imputation; listwise and pairwise deletion; mean imputation; regression imputation; last observation carried forward; stochastic imputation; and multiple imputation. [emphasis added]

  • http://scikit-learn.org/stable/modules/preprocessing.html#imputation-of-missing-values
  • http://scikit-learn.org/stable/modules/classes.html#module-sklearn.preprocessing
  • http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.Imputer.html
    • class sklearn.preprocessing.Imputer(, strategy=('mean', 'median', 'most_frequent'), )
  • http://scikit-learn.org/stable/auto_examples/missing_values.html :

    Imputing missing values before building an estimator
    This example shows that imputing the missing values can give better results than discarding the samples containing any missing value. Imputing does not always improve the predictions, so please check via cross-validation. Sometimes dropping rows or using marker values is more effective.
    Missing values can be replaced by the mean, the median or the most frequent value using the strategy hyper-parameter. The median is a more robust estimator for data with high magnitude variables which could dominate results (otherwise known as a ‘long tail’)."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants