GithubHelp home page GithubHelp logo

epistasislab / scikit-mdr Goto Github PK

View Code? Open in Web Editor NEW
126.0 126.0 26.0 141 KB

A sklearn-compatible Python implementation of Multifactor Dimensionality Reduction (MDR) for feature construction.

License: MIT License

Python 95.79% Shell 4.21%

scikit-mdr's People

Contributors

hyunjuna avatar nickotto avatar rhiever avatar tuannguyen27 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scikit-mdr's Issues

Confusion with documentation and MDR feature construction output

Hi, in the first example in the README, it states:

"For example, MDR can be used to construct a new feature composed from two existing features:"

but "GAMETES_Epistasis_2-Way_20atts_0.4H_EDM-1_1" used in the example has 21 columns, not 2.

The resulting output is a single column, which is a single feature -- is it that there's a single feature produced because that's what those 21 columns boiled down to, or is it because only 2 features from the dataframe were selected and used to construct the new feature? Or is there another reason?

Thanks in advance! I will continue reading the MDR paper I found on pubmed in the meanwhile.

Divide utility functions into separate modules

Instead of keeping all of the modules in the same utils.py file, break them out into separate submodules. This will help prevent situations where, for example, a user imports matplotlib when they're only using the n_way_models function (that doesn't use matplotlib).

reduce 200x200000 into 200x1000

Hi, I have a ChIP-seq style dataset of RPKM values that I want to reduce from 200x200000 into 200x1000, so that I only end up with 1000 variables at the end of the MDR process, for my 200 records.

What would be the recommended way to use scikit-mdr for this task?

np.int is throwing a deprecation error

https://github.com/EpistasisLab/scikit-mdr/blob/master/mdr/mdr.py#L126

is throwing

DeprecationWarning: np.int is a deprecated alias for the builtin int. To silence this warning, use int by itself. Doing this will not modify any behavior and is safe. When replacing np.int, you may wish to use e.g. np.int64 or np.int32 to specify the precision. If you wish to review your current use, check the release note link for additional information.

Numpy version: 1.24.2
Python version 3.9.1

Deprecation details can be found here

Add MDR utils module

Provide common functions for MDR such as:

  • Entropy / MDR entropy measures

  • Common MDR visualizations

    • Colorized MDR grid

    • Entropy network

  • Create all n-way models wrapper

Error when class labels aren't [0,1]

An error occurs when the class labels are not 0 and 1.
When counting the number of cases and controls for each cell in a grid,

MDR code uses the following code (line 76-78):

       for row_i in range(features.shape[0]):
            feature_instance = tuple(features[row_i])
            self.class_count_matrix[feature_instance][classes[row_i]] += 1

classes is an array of y values passed as a parameter.
Think of class_count_matrix as a (# of possible feature_instances) by (# of classes).
Then since MDR takes in only binary data, # of classes is always 2 and therefore appropriate indices would be 0 and 1 for the dimension.
But if the class labels are 0 and 2 not 0 and 1, then the program will try to index the class_count_matrix as class_count_matrix[(tuple of a feature_instance)][2], which is out of bounds.

Error message:

  File "<ipython-input-180-e1715a88facf>", line 10, in <module>
    mdr.fit(X_train, y_train)

  File "C:\Users\Hayley Son\Anaconda3\lib\site-packages\mdr\mdr.py", line 78, in fit
    self.class_count_matrix[feature_instance][classes[row_i]] += 1

IndexError: index 2 is out of bounds for axis 0 with size 2

cannot import module BaggingClassifier

I tried to install scikit-mdr on an Ubuntu 14.04 Linux via pip install but got this error below. To make sure it wasn't a versions issue with scikit-learn, I did a sudo pip install -U scikit-learn, which completed successfully, then tried to load MDR on a python console. See below.

Any ideas?

Successfully installed scikit-learn
Cleaning up...
avilella@ubuntu14:~$ 
avilella@ubuntu14:~$ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from mdr import MDR
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/mdr/__init__.py", line 23, in <module>
    from .mdr_ensemble import MDREnsemble
  File "/usr/local/lib/python2.7/dist-packages/mdr/mdr_ensemble.py", line 26, in <module>
    from sklearn.ensemble import BaggingClassifier
ImportError: cannot import name BaggingClassifier

Example for finding features with epistatic effects with scikit-mdr

It seems that the utilities in mdr.utils is designed for this purpose but there is no documentation about how to use them. I have a quick look into those codes and made the demo for calculating scores for n-way combinations and I think it maybe a way to finding feature combinations with epistatic effect. Please let me know if it is the correct way.

from mdr import MDRClassifier
import pandas as pd
from mdr.utils import n_way_models
import operator

genetic_data = pd.read_csv('https://github.com/EpistasisLab/scikit-mdr/raw/development/data/GAMETES_Epistasis_2-Way_20atts_0.4H_EDM-1_1.tsv.gz', sep='\t', compression='gzip')

features = genetic_data.drop('class', axis=1).values
labels = genetic_data['class'].values
feature_names = list(genetic_data.columns)

my_mdr = MDRClassifier()
my_mdr.fit(features, labels)
print("Score for using all features", my_mdr.score(features, labels))

#n: list (default: [2])
#The maximum size(s) of the MDR model to generate.
#e.g., if n == [3], all 3-way models will be generated.
n = [2]
mdr_score_list = []
#  Note that this function performs an exhaustive search through all feature combinations and can be computationally expensive.
for _, mdr_model_score, model_features in n_way_models(my_mdr, features, labels, n=n, feature_names=feature_names):
    mdr_score_list.append((model_features, mdr_model_score))
mdr_score_list.sort(key=operator.itemgetter(1), reverse=True)
print("The combination with highest score:", mdr_score_list[0])

Exported output:

Score for using all features 0.998125
The combination with highest score: (['P1', 'P2'], 0.793125)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.