epistasislab / scikit-mdr Goto Github PK
View Code? Open in Web Editor NEWA sklearn-compatible Python implementation of Multifactor Dimensionality Reduction (MDR) for feature construction.
License: MIT License
A sklearn-compatible Python implementation of Multifactor Dimensionality Reduction (MDR) for feature construction.
License: MIT License
A reminder to add a warning to make sure that encodings (both phenotype and genotype) are consistent when working with a discovery and a replication dataset.
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.
genetic_data = pd.read_csv('https://github.com/EpistasisLab/scikit-mdr/blob/master/data/GAMETES_Epistasis_2-Way_20atts_0.4H_EDM-1_1.tsv.gz', sep='\t', compression='gzip')
The above command is not working, error says : "BadGzipFile: Not a gzipped file (b'\n\n')"
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).
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?
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
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
Need to make sure the transform method returns a numpy matrix, not just a vector.
Hi,
What code should I use to output the cross-validation consistency and prediction error for each 2-way models I had generated?
Thank you,
Jennifer
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
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
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)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.