-
Notifications
You must be signed in to change notification settings - Fork 4
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
Finished plots and figures for reproduction #78
Merged
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fa6913d
Added file to create histogram to identify brain mask
AlonDaks c18694e
added brain mask plot
AlonDaks 718bf8c
Finished reproduction plots and figures
AlonDaks 2b8aa42
added more hyperparams to RF cross validation
AlonDaks 5d08373
Merge branch 'master' of https://github.com/berkeley-stat159/project-…
AlonDaks 9c592f9
Merge branch 'master' of https://github.com/berkeley-stat159/project-…
AlonDaks 3b1885a
Merge branch 'master' of https://github.com/berkeley-stat159/project-…
AlonDaks 24e5d9f
updated rf_cross_validate to work with linear_modeling APIs
AlonDaks 36a7dd6
svm cross validation
AlonDaks 37babc0
RF cross validation on scene-change-removed data
AlonDaks 8163254
updated CV region for rf cross validate
AlonDaks 536e23f
Changed data makefile to download data from source
AlonDaks 021af16
Finished data download and checking scripts
AlonDaks cff6a32
Updated data_path utility and tests to reflect new data download scheme
AlonDaks 24c3d55
added completion message to data download script
AlonDaks 73bd127
Merge branch 'master' of https://github.com/berkeley-stat159/project-…
AlonDaks 7d44c5e
fixed issues according to code review
AlonDaks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 26 additions & 17 deletions
43
code/stat159lambda/classification/random_forest/rf_cross_validate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,38 @@ | ||
from __future__ import print_function, division | ||
import numpy as np | ||
from sklearn.cross_validation import KFold | ||
from sklearn.metrics import accuracy_score | ||
from stat159lambda.classification import design_matrix as dm | ||
from stat159lambda.classification.random_forest import rf | ||
from stat159lambda.classification import partition_volumes as pv | ||
from stat159lambda.config import REPO_HOME_PATH | ||
from stat159lambda.config import REPO_HOME_PATH, NUM_VOXELS | ||
from stat159lambda.linear_modeling import linear_modeling as lm | ||
from stat159lambda.utils import data_path as dp | ||
|
||
design_matrix = dm.DesignMatrix( | ||
'{0}/data/processed/sub1_rcds_2d.npy'.format(REPO_HOME_PATH), | ||
pv.get_train_indices(), range(200)) | ||
|
||
X_train = design_matrix.get_design_matrix() | ||
y_train = np.array(design_matrix.get_labels()) | ||
voxels_sorted_by_t_statistic = lm.VoxelExtractor(1, 'int-ext').t_stat() | ||
num_features_values = [200, 400, 600, 1000, 1500, 2000, 3000, 5000, 10000] | ||
design_matrix = dm.DesignMatrix(dp.get_smoothed_2d_path(1, 4)) | ||
train_volume_indices = pv.get_train_indices() | ||
cv_values = [] | ||
for num_features in num_features_values: | ||
voxel_feature_indices = voxels_sorted_by_t_statistic[:num_features] | ||
|
||
cv_accuracies = [] | ||
for train, test in KFold(len(X_train), 5): | ||
X_cv_train = X_train[train, :] | ||
y_cv_train = y_train[train] | ||
X_cv_test = X_train[test, :] | ||
y_cv_test = y_train[test] | ||
model = rf.Classifier(X_cv_train, y_cv_train) | ||
model.train() | ||
y_predicted = model.predict(X_cv_test) | ||
cv_accuracies.append(accuracy_score(y_predicted, y_cv_test)) | ||
X_train = design_matrix.get_design_matrix(train_volume_indices, voxel_feature_indices) | ||
y_train = np.array(design_matrix.get_labels(train_volume_indices)) | ||
|
||
print np.mean(cv_accuracies) | ||
cv_accuracies = [] | ||
for train, test in KFold(len(X_train), 5): | ||
X_cv_train = X_train[train, :] | ||
y_cv_train = y_train[train] | ||
X_cv_test = X_train[test, :] | ||
y_cv_test = y_train[test] | ||
model = rf.Classifier(X_cv_train, y_cv_train) | ||
model.train() | ||
y_predicted = model.predict(X_cv_test) | ||
cv_accuracies.append(accuracy_score(y_predicted, y_cv_test)) | ||
|
||
cv_values.append(np.mean(cv_accuracies)) | ||
|
||
np.save('cv_values', cv_values) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
code/stat159lambda/classification/svm/svm_cross_validate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from __future__ import print_function, division | ||
import numpy as np | ||
from sklearn.cross_validation import KFold | ||
from sklearn.metrics import accuracy_score | ||
from stat159lambda.classification import design_matrix as dm | ||
from stat159lambda.classification.svm import svm | ||
from stat159lambda.classification import partition_volumes as pv | ||
from stat159lambda.config import REPO_HOME_PATH, NUM_VOXELS | ||
from stat159lambda.linear_modeling import linear_modeling as lm | ||
from stat159lambda.utils import data_path as dp | ||
|
||
|
||
voxels_sorted_by_t_statistic = lm.VoxelExtractor(1, 'int-ext').t_stat() | ||
# num_features_values = range(100, NUM_VOXELS/100, 100) | ||
# for num_features in num_features_values: | ||
voxel_feature_indices = voxels_sorted_by_t_statistic[:1000] | ||
design_matrix = dm.DesignMatrix(dp.get_smoothed_2d_path(1, 4), pv.get_train_indices(), voxel_feature_indices) | ||
|
||
print('classifying') | ||
X_train = design_matrix.get_design_matrix() | ||
y_train = np.array(design_matrix.get_labels()) | ||
|
||
cv_accuracies = [] | ||
for train, test in KFold(len(X_train), 5): | ||
X_cv_train = X_train[train, :] | ||
y_cv_train = y_train[train] | ||
X_cv_test = X_train[test, :] | ||
y_cv_test = y_train[test] | ||
model = svm.Classifier(X_cv_train, y_cv_train) | ||
model.train() | ||
y_predicted = model.predict(X_cv_test) | ||
cv_accuracies.append(accuracy_score(y_predicted, y_cv_test)) | ||
|
||
print(np.mean(cv_accuracies)) | ||
|
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you wanted, you could calculate this constant using VOXEL_DIMENSIONS. But it's fine as it is too