forked from nilearn/nilearn.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintroduction.html
935 lines (869 loc) · 54.9 KB
/
introduction.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nilearn: Statistical Analysis for NeuroImaging in Python — Machine learning for NeuroImaging</title>
<link rel="stylesheet" href="_static/nature.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="_static/gallery.css" />
<link rel="stylesheet" type="text/css" href="_static/gallery-binder.css" />
<link rel="stylesheet" type="text/css" href="_static/gallery-dataframe.css" />
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/language_data.js"></script>
<script type="text/javascript" src="_static/copybutton.js"></script>
<link rel="shortcut icon" href="_static/favicon.ico"/>
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="2. Decoding and MVPA: predicting from brain images" href="decoding/index.html" />
<link rel="prev" title="User guide: table of contents" href="user_guide.html" />
<meta content="True" name="HandheldFriendly">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="keywords" content="nilearn, neuroimaging, python, neuroscience, machinelearning">
<script type="text/javascript">
function updateTopMenuPosition(height, width) {
if($(window).scrollTop() > height && $(window).outerWidth() > 1024) {
//begin to scroll
$('.related-wrapper').css("z-index", 1000);
$('.related-wrapper').css("position", "sticky");
$('.related-wrapper').css("top", 0);
$('.related-wrapper').css("width", width)
} else {
//lock it back into place
$('.related-wrapper').css("position", "relative");
$('.related-wrapper').css("top", 0)
}
}
$(function() {
var banner_height = $('#logo-banner').outerHeight();
var banner_width = $('#logo-banner').outerWidth();
var width = $('.related-wrapper').css("height", $('.related').outerHeight());
updateTopMenuPosition(banner_height, width);
$(window).scroll(function(event) {
updateTopMenuPosition(banner_height, width)
});
$(window).resize(function(event) {
var banner_width = $('#logo-banner').outerWidth();
var menu_height = $('.related').outerHeight();
$('.related').css("width", banner_width);
$('.related-wrapper').css("height", menu_height);
updateTopMenuPosition(banner_height, width)
})
});
</script>
<script type="text/javascript">
function updateSideBarPosition(top, offset, sections) {
var pos = $(window).scrollTop();
// Lock the table of content to a fixed position once we scroll enough
var topShift = 2 * offset;
if(pos > top + topShift + 1) {
// begin to scroll with sticky menu bar
var topShift = -topShift + 1;
if ($(window).outerWidth() < 1024) {
// compensate top menu that disappears
topShift -= offset + 1
}
$('.sphinxsidebarwrapper').css("position", "fixed");
$('.sphinxsidebarwrapper').css("top", topShift)
}
else {
//lock it back into place
$('.sphinxsidebarwrapper').css("position", "relative");
$('.sphinxsidebarwrapper').css("top",0)
}
// Highlight the current section
i = 0;
current_section = 0;
$('a.internal').removeClass('active');
for(i in sections) {
if(sections[i] > pos) {
break
}
if($('a.internal[href$="' + i + '"]').is(':visible')){
current_section = i
}
}
$('a.internal[href$="' + current_section + '"]').addClass('active');
$('a.internal[href$="' + current_section + '"]').parent().addClass('active')
}
$(function () {
// Lock the table of content to a fixed position once we scroll enough
var tocOffset = $('.related-wrapper').outerHeight();
var marginTop = parseFloat($('.sphinxsidebarwrapper').css('margin-top').replace(/auto/, 0));
var top = $('.sphinxsidebarwrapper').offset().top - marginTop;
sections = {};
url = document.URL.replace(/#.*$/, "");
// Grab positions of our sections
$('.headerlink').each(function(){
sections[this.href.replace(url, '')] = $(this).offset().top - 50
});
updateSideBarPosition(top, tocOffset, sections);
$(window).scroll(function(event) {
updateSideBarPosition(top, tocOffset, sections)
});
$(window).resize(function(event) {
tocOffset = $('.related-wrapper').outerHeight();
updateSideBarPosition(top, tocOffset, sections)
});
});
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-41920728-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head><body>
<div id="logo-banner">
<div class="logo">
<a href="index.html">
<img src="_static/nilearn-logo.png" alt="Nilearn logo" border="0" />
</a>
</div>
<!-- A tag cloud to make it easy for people to find what they are
looking for -->
<div class="tags">
<ul>
<li>
<big><a href="auto_examples/decoding/plot_haxby_anova_svm.html">SVM</a></big>
</li>
<li>
<small><a href="connectivity/parcellating.html">Ward
clustering</a></small>
</li>
<li>
<a href="decoding/searchlight.html">Searchlight</a>
</li>
<li>
<big><a href="connectivity/resting_state_networks.html">ICA</a></big>
</li>
<li>
<a href="manipulating_images/data_preparation.html">Nifti IO</a>
</li>
<li>
<a href="modules/reference.html#module-nilearn.datasets">Datasets</a>
</li>
</ul>
</div>
<div class="banner">
<h1>Nilearn:</h1>
<h2>Statistics for NeuroImaging in Python</h2>
</div>
<div class="search_form">
<div class="gcse-search" id="cse" style="width: 100%;"></div>
<script>
(function() {
var cx = '017289614950330089114:elrt9qoutrq';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
</div>
</div>
<div class=related-wrapper>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="py-modindex.html" title="Python Module Index"
>modules</a></li>
<li class="right" >
<a href="decoding/index.html" title="2. Decoding and MVPA: predicting from brain images"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="user_guide.html" title="User guide: table of contents"
accesskey="P">previous</a> |</li>
<li><a href="index.html">Nilearn Home</a> | </li>
<li><a href="user_guide.html">User Guide</a> | </li>
<li><a href="auto_examples/index.html">Examples</a> | </li>
<li><a href="modules/reference.html">Reference</a> | </li>
<li id="navbar-about"><a href="authors.html">About</a>| </li>
<li id="navbar-ecosystem"><a href="http://www.nipy.org/">Nipy ecosystem</a></li>
<li class="nav-item nav-item-1"><a href="user_guide.html" accesskey="U">User guide: table of contents</a> »</li>
</ul>
</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="introduction-nilearn-in-a-nutshell">
<h1>1. Introduction: nilearn in a nutshell<a class="headerlink" href="#introduction-nilearn-in-a-nutshell" title="Permalink to this headline">¶</a></h1>
<div class="contents local topic" id="contents">
<p class="topic-title"><strong>Contents</strong></p>
<ul class="simple">
<li><a class="reference internal" href="#what-is-nilearn-mvpa-decoding-predictive-models-functional-connectivity" id="id4">What is nilearn: MVPA, decoding, predictive models, functional connectivity</a></li>
<li><a class="reference internal" href="#installing-nilearn" id="id5">Installing nilearn</a></li>
<li><a class="reference internal" href="#python-for-neuroimaging-a-quick-start" id="id6">Python for NeuroImaging, a quick start</a></li>
</ul>
</div>
<div class="section" id="what-is-nilearn-mvpa-decoding-predictive-models-functional-connectivity">
<h2><a class="toc-backref" href="#id4">1.1. What is nilearn: MVPA, decoding, predictive models, functional connectivity</a><a class="headerlink" href="#what-is-nilearn-mvpa-decoding-predictive-models-functional-connectivity" title="Permalink to this headline">¶</a></h2>
<div class="topic">
<p class="topic-title"><strong>Why use nilearn?</strong></p>
<p>Nilearn makes it easy to use many advanced <strong>machine learning</strong>,
<strong>pattern recognition</strong> and <strong>multivariate statistical</strong> techniques on
neuroimaging data for applications such as <strong>MVPA</strong> (Mutli-Voxel
Pattern Analysis),
<a class="reference internal" href="decoding/index.html#decoding"><span class="std std-ref">decoding</span></a>,
<a class="reference internal" href="decoding/index.html#decoding"><span class="std std-ref">predictive modelling</span></a>,
<a class="reference internal" href="connectivity/functional_connectomes.html#functional-connectomes"><span class="std std-ref">functional connectivity</span></a>,
<a class="reference internal" href="connectivity/parcellating.html#parcellating-brain"><span class="std std-ref">brain parcellations</span></a>,
<a class="reference internal" href="connectivity/functional_connectomes.html#functional-connectomes"><span class="std std-ref">connectomes</span></a>.</p>
<p>Nilearn can readily be used on <a class="reference internal" href="decoding/decoding_intro.html#decoding-intro"><span class="std std-ref">task fMRI</span></a>,
<a class="reference internal" href="connectivity/functional_connectomes.html#functional-connectomes"><span class="std std-ref">resting-state</span></a>, or
<a class="reference internal" href="auto_examples/02_decoding/plot_oasis_vbm.html#sphx-glr-auto-examples-02-decoding-plot-oasis-vbm-py"><span class="std std-ref">VBM</span></a> data.</p>
<p>For a machine-learning expert, the value of nilearn can be seen as
domain-specific <strong>feature engineering</strong> construction, that is, shaping
neuroimaging data into a feature matrix well suited to statistical
learning, or vice versa.</p>
</div>
<div class="section" id="why-is-machine-learning-relevant-to-neuroimaging-a-few-examples">
<h3>1.1.1. Why is machine learning relevant to NeuroImaging? A few examples!<a class="headerlink" href="#why-is-machine-learning-relevant-to-neuroimaging-a-few-examples" title="Permalink to this headline">¶</a></h3>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name" colspan="2">Diagnosis and prognosis:</th></tr>
<tr class="field-odd field"><td> </td><td class="field-body"><p class="first">Predicting a clinical score or even treatment response
from brain imaging with <a class="reference internal" href="decoding/index.html#decoding"><span class="std std-ref">supervised
learning</span></a> e.g. <a class="reference external" href="http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0029482">[Mourao-Miranda 2012]</a></p>
</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Measuring generalization scores:</th></tr>
<tr class="field-even field"><td> </td><td class="field-body"><ul class="first simple">
<li><strong>Information mapping</strong>: using the prediction accuracy of a classifier
to characterize relationships between brain images and stimuli. (e.g.
<a class="reference internal" href="decoding/searchlight.html#searchlight"><span class="std std-ref">searchlight</span></a>) <a class="reference external" href="http://www.pnas.org/content/103/10/3863.short">[Kriegeskorte 2005]</a></li>
<li><strong>Transfer learning</strong>: measuring how much an estimator trained on one
specific psychological process/task can predict the neural activity
underlying another specific psychological process/task
(e.g. discriminating left from
right eye movements also discriminates additions from subtractions
<a class="reference external" href="http://www.sciencemag.org/content/324/5934/1583.short">[Knops 2009]</a>)</li>
</ul>
</td>
</tr>
<tr class="field-odd field"><th class="field-name" colspan="2">High-dimensional multivariate statistics:</th></tr>
<tr class="field-odd field"><td> </td><td class="field-body"><p class="first">From a statistical point of view, machine learning implements
statistical estimation of models with a large number of parameters.
Tricks pulled in machine learning (e.g. regularization) can
make this estimation possible despite the usually
small number of observations in the neuroimaging domain
<a class="reference external" href="http://icml.cc/2012/papers/688.pdf">[Varoquaux 2012]</a>. This
usage of machine learning requires some understanding of the models.</p>
</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Data mining / exploration:</th></tr>
<tr class="field-even field"><td> </td><td class="field-body"><p class="first last">Data-driven exploration of brain images. This includes the extraction of
the major brain networks from resting-state data (“resting-state networks”)
or movie-watching data as well as the discovery of connectionally coherent
functional modules (“connectivity-based parcellation”).
For example,
<a class="reference internal" href="connectivity/resting_state_networks.html#extracting-rsn"><span class="std std-ref">Extracting functional brain networks: ICA and related</span></a> or <a class="reference internal" href="connectivity/parcellating.html#parcellating-brain"><span class="std std-ref">Clustering to parcellate the brain in regions</span></a> with clustering.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="glossary-machine-learning-vocabulary">
<h3>1.1.2. Glossary: machine learning vocabulary<a class="headerlink" href="#glossary-machine-learning-vocabulary" title="Permalink to this headline">¶</a></h3>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name" colspan="2">Supervised learning:</th></tr>
<tr class="field-odd field"><td> </td><td class="field-body"><p class="first"><a class="reference internal" href="decoding/index.html#decoding"><span class="std std-ref">Supervised learning</span></a> is interested in predicting an
<strong>output variable</strong>, or <strong>target</strong>, <cite>y</cite>, from <strong>data</strong> <cite>X</cite>.
Typically, we start from labeled data (the <strong>training set</strong>). We need to
know the <cite>y</cite> for each instance of <cite>X</cite> in order to train the model. Once
learned, this model is then applied to new unlabeled data (the <strong>test set</strong>)
to predict the labels (although we actually know them). There are
essentially two possible goals:</p>
<ul class="simple">
<li>a <strong>regression</strong> problem: predicting a continuous variable, such
as participant age, from the data <cite>X</cite></li>
<li>a <strong>classification</strong> problem: predicting a binary variable that splits
the observations into two groups, such as patients versus controls</li>
</ul>
<p>In neuroimaging research, supervised learning is typically used to
derive an underlying cognitive process (e.g., emotional versus non-emotional
theory of mind), a behavioral variable (e.g., reaction time or IQ), or
diagnosis status (e.g., schizophrenia versus healthy) from brain images.</p>
</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Unsupervised learning:</th></tr>
<tr class="field-even field"><td> </td><td class="field-body"><p class="first"><a class="reference external" href="http://scikit-learn.org/stable/unsupervised_learning.html">Unsupervised learning</a> is
concerned with data <cite>X</cite> without any labels. It analyzes the structure
of a dataset to find coherent underlying structure,
for instance using <strong>clustering</strong>, or to extract latent
factors, for instance using <strong>independent components analysis (ICA)</strong>.</p>
<p class="last">In neuroimaging research, it is typically used to create functional and
anatomical brain atlases by clustering based on connectivity or to
extract the main brain networks from resting-state correlations. An
important option of future research will be the identification of
potential neurobiological subgroups in psychiatric and neurobiological
disorders.</p>
</td>
</tr>
</tbody>
</table>
<div class="line-block">
<div class="line"><br /></div>
</div>
</div>
</div>
<div class="section" id="installing-nilearn">
<span id="installation"></span><h2><a class="toc-backref" href="#id5">1.2. Installing nilearn</a><a class="headerlink" href="#installing-nilearn" title="Permalink to this headline">¶</a></h2>
<script type="text/javascript">
var OSName=2;
if (navigator.userAgent.indexOf("Win")!=-1) OSName=1;
if (navigator.userAgent.indexOf("Mac")!=-1) OSName=2;
if (navigator.userAgent.indexOf("X11")!=-1) OSName=3;
if (navigator.userAgent.indexOf("Linux")!=-1) OSName=3;
if (navigator.userAgent.indexOf("Android")!=-1) OSName=1;
$(document).ready(function(){
$("ul#tabs li.active").removeClass("active");
$("ul#tab li.active").removeClass("active");
$("ul#tabs li:nth-child("+OSName+")").addClass("active");
$("ul#tab li:nth-child("+OSName+")").addClass("active");
});
$(document).ready(function(){
$("ul#tabs li").click(function(e){
if (!$(this).hasClass("active")) {
var tabNum = $(this).index();
var nthChild = tabNum+1;
$("ul#tabs li.active").removeClass("active");
$(this).addClass("active");
$("ul#tab li.active").removeClass("active");
jQuery("ul#tab li:nth-child("+nthChild+")").fadeIn(400).siblings().hide();
$("ul#tab li:nth-child("+nthChild+")").addClass("active");
}
});
});
</script>
<div class="container">
<ul id="tabs">
<li class="active">Windows</li>
<li>Mac</li>
<li>Linux</li>
<li>Get source</li>
</ul>
<ul id="tab">
<li class="active">
<p class="emphasize">First: download and install 64 bit <a
<class="reference external"
<href="https://store.continuum.io/cshop/anaconda/"
<target="_blank">Anaconda</a></p>
<p>We recommend that you <strong>install a complete
<span style="color:red">64 bit</span> scientific Python
distribution like <a class="reference external" href="
https://www.anaconda.com/download/" target="_blank">Anaconda</a>
</strong>. Since it meets all the requirements of nilearn, it will save
you time and trouble. You could also check <a class="reference external"
href="http://python-xy.github.io/" target="_blank">PythonXY</a>
as an alternative.</p>
<p>Nilearn requires a Python installation and the following
dependencies: ipython, scipy, scikit-learn, joblib, matplotlib,
nibabel and pandas.</p>
<p class="emphasize">Second: open a Command Prompt</p>
<p><strong>(Press "Win-R", type "cmd" and press "Enter". This will open
the program cmd.exe, which is the command prompt)</strong><br/>
Then type the following line and press "Enter"</p>
<div class="code"><pre>pip install -U --user nilearn</pre></div>
<p class="emphasize">Third: open IPython</p>
<p><strong>(You can open it by writing "ipython" in the command prompt
and pressing "Enter")</strong><br/>
Then type in the following line and press "Enter":</p>
<div class="code"><pre>In [1]: import nilearn</pre></div>
<p>If no error occurs, you have installed nilearn correctly.</p>
</li>
<li>
<p class="emphasize">First: download and install 64 bit <a class="
reference external" href="https://www.anaconda.com/download/"
target="_blank">Anaconda</a></p>
<p>We recommend that you <strong>install a complete
<span style="color:red">64 bit</span> scientific
Python distribution like <a class="reference external"
href="https://www.anaconda.com/download/" target="_blank">
Anaconda</a></strong>. Since it meets all the requirements of nilearn,
it will save you time and trouble.</p>
<p>Nilearn requires a Python installation and the following
dependencies: ipython, scipy, scikit-learn, joblib,
matplotlib, nibabel and pandas.</p>
<p class="emphasize">Second: open a Terminal</p>
<p><strong>(Navigate to /Applications/Utilities and double-click on
Terminal)</strong><br/>
Then type the following line and press "Enter"</p>
<div class="code"><pre>pip install -U --user nilearn</pre></div>
<p class="emphasize">Third: open IPython</p>
<p><strong>(You can open it by writing "ipython" in the terminal and
pressing "Enter")</strong><br/>
Then type in the following line and press "Enter":</p>
<div class="code"><pre>In [1]: import nilearn</pre></div>
<p>If no error occurs, you have installed nilearn correctly.</p>
</li>
<li>
<div class="contents"><p>If you are using <strong>Ubuntu or Debian</strong>
and you have access to <a class="reference external"
href="http://neuro.debian.net/" target="_blank">
Neurodebian</a>, then simply install the
<a class="reference external"
href="http://neuro.debian.net/pkgs/python-nilearn.html" target="_blank">python-nilearn package</a> through Neurodebian.</p></div>
<p class="emphasize">First: Install dependencies</p>
<p>Install or ask your system administrator to install the following
packages using the distribution package manager: <strong>ipython</strong>
, <strong>scipy</strong>, <strong>scikit-learn</strong> (sometimes called <cite>sklearn</cite>,
or <cite>python-sklearn</cite>), <strong>joblib</strong>,
<strong>matplotlib</strong> (sometimes
called <cite>python-matplotlib</cite>), <strong>nibabel</strong>
(sometimes called <cite>python-nibabel</cite>) and <strong>pandas</strong>
(sometimes called <cite>python-pandas</cite>).</p>
<p><strong>If you do not have access to the package manager we recommend
that you install a complete <span style="color:red">64 bit</span>
scientific Python distribution like
<a class="reference external"
href="https://www.anaconda.com/download/" target="_blank">
Anaconda</a></strong>. Since it meets all the requirements of nilearn,
it will save you time and trouble.</p>
<p class="emphasize">Second: open a Terminal</p>
<p><strong>(Press ctrl+alt+t and a Terminal console will pop up)</strong><br/>
Then type the following line and press "Enter"</p>
<div class="code"><pre>pip install -U --user nilearn</pre></div>
<p class="emphasize">Third: open IPython</p>
<p><strong>(You can open it by writing "ipython" in the terminal and
pressing "Enter")</strong><br/>
Then type in the following line and press "Enter":</p>
<div class="code"><pre>In [1]: import nilearn</pre></div>
<p>If no error occurs, you have installed nilearn correctly.</p>
</li>
<li>
<p class="emphasize">To Install the development version:</p>
<p><strong>Use git as an alternative to using pip, to get the latest
nilearn version</strong></p>
<p class="first">Simply run the following command (as a shell command,
not a Python command):</p>
<div class="code"><pre>git clone https://github.com/nilearn/nilearn.git</pre>
</div>
<p>In the future, you can readily update your copy of nilearn by
executing “git pull” in the nilearn root directory (as a
shell command).</p>
<p>If you really do not want to use git, you may still download the
latest development snapshot from the following link (unziping required):
<a class="reference external"
href="https://github.com/nilearn/nilearn/archive/master.zip">
https://github.com/nilearn/nilearn/archive/master.zip</a></p>
<p><strong>Install in the nilearn directory created by the previous
steps, run (again, as a shell command):</strong></p>
<div class="code"><pre>python setup.py develop --user</pre></div>
<p><strong>Now to test everything is set up correctly, open IPython and
type in the following line:</strong></p>
<div class="code"><pre>In [1]: import nilearn</pre></div>
<p>If no error occurs, you have installed nilearn correctly.</p>
</li>
</ul>
</div>
</div>
<div class="section" id="python-for-neuroimaging-a-quick-start">
<span id="quick-start"></span><h2><a class="toc-backref" href="#id6">1.3. Python for NeuroImaging, a quick start</a><a class="headerlink" href="#python-for-neuroimaging-a-quick-start" title="Permalink to this headline">¶</a></h2>
<p>If you don’t know Python, <strong>Don’t panic. Python is easy</strong>. It is important
to realize that most things you will do in nilearn require only a few or a
few dozen lines of Python code.
Here, we give
the basics to help you get started. For a very quick start into the programming
language, you can <a class="reference external" href="http://www.learnpython.org/">learn it online</a>.
For a full-blown introduction to
using Python for science, see the <a class="reference external" href="http://scipy-lectures.github.io/">scipy lecture notes</a>.</p>
<p>We will be using <a class="reference external" href="http://jupyter.org">Jupyter</a> for notebooks, or
<a class="reference external" href="http://ipython.org">IPython</a>, which provides an interactive scientific
environment that facilitates many everyday data-manipulation steps (e.g.
interactive debugging, easy visualization). You can choose notebooks or
terminal:</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Notebooks:</th><td class="field-body"><p class="first">Start the Jupter notebook either with the application menu, or by
typing:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">jupyter</span> <span class="n">notebook</span>
</pre></div>
</div>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Terminal:</th><td class="field-body"><p class="first">Start ipython by typing:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ipython</span> <span class="o">--</span><span class="n">matplotlib</span>
</pre></div>
</div>
<div class="last admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The <code class="docutils literal notranslate"><span class="pre">--matplotlib</span></code> flag, which configures matplotlib for
interactive use inside IPython.</p>
</div>
</td>
</tr>
</tbody>
</table>
<p>These will give you a <em>prompt</em> in which you can execute commands:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">In</span> <span class="p">[</span><span class="mi">1</span><span class="p">]:</span> <span class="mi">1</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="mi">3</span>
<span class="n">Out</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span> <span class="mi">7</span>
</pre></div>
</div>
<div class="topic">
<p class="topic-title"><cite>>>></cite> <strong>Prompt</strong></p>
<p>Below we’ll be using <cite>>>></cite> to indicate input lines. If you wish to copy and
paste these input lines directly, click on the <cite>>>></cite> located
at the top right of the code block to toggle these prompt signs</p>
</div>
<div class="section" id="your-first-steps-with-nilearn">
<h3>1.3.1. Your first steps with nilearn<a class="headerlink" href="#your-first-steps-with-nilearn" title="Permalink to this headline">¶</a></h3>
<p>First things first, nilearn does not have a graphical user interface.
But you will soon realize that you don’t really need one.
It is typically used interactively in IPython or in an automated way by Python
code.
Most importantly, nilearn functions that process neuroimaging data accept
either a filename (i.e., a string variable) or a <a class="reference external" href="http://nipy.org/nibabel/nibabel_images.html">NiftiImage object</a>. We call the latter
“niimg-like”.</p>
<p>Suppose for instance that you have a Tmap image saved in the Nifti file
“t_map000.nii” in the directory “/home/user”. To visualize that image, you will
first have to import the <a class="reference internal" href="plotting/index.html#plotting"><span class="std std-ref">plotting</span></a> functionality by:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">nilearn</span> <span class="k">import</span> <span class="n">plotting</span>
</pre></div>
</div>
<p>Then you can call the function that creates a “glass brain” by giving it
the file name:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">plotting</span><span class="o">.</span><span class="n">plot_glass_brain</span><span class="p">(</span><span class="s2">"/home/user/t_map000.nii"</span><span class="p">)</span>
</pre></div>
</div>
<div class="sidebar">
<p class="first sidebar-title">File name matchings</p>
<p class="last">The filename could be given as “~/t_map000.nii’ as nilearn expands “~” to
the home directory.
<a class="reference internal" href="manipulating_images/input_output.html#filename-matching"><span class="std std-ref">See more on file name matchings</span></a>.</p>
</div>
<a class="reference external image-reference" href="auto_examples/01_plotting/plot_demo_glass_brain.html"><img alt="_images/sphx_glr_plot_demo_glass_brain_001.png" class="align-center" src="_images/sphx_glr_plot_demo_glass_brain_001.png" style="width: 396.0px; height: 156.0px;" /></a>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">There are many other plotting functions. Take your time to have a look
at the <a class="reference internal" href="plotting/index.html#plotting"><span class="std std-ref">different options</span></a>.</p>
</div>
<div class="line-block">
<div class="line"><br /></div>
</div>
<p>For simple functions/operations on images, many functions exist, such as in
the <a class="reference internal" href="modules/reference.html#module-nilearn.image" title="nilearn.image"><code class="xref py py-mod docutils literal notranslate"><span class="pre">nilearn.image</span></code></a> module for image manipulation, e.g.
<a class="reference internal" href="modules/generated/nilearn.image.smooth_img.html#nilearn.image.smooth_img" title="nilearn.image.smooth_img"><code class="xref py py-func docutils literal notranslate"><span class="pre">image.smooth_img</span></code></a> for smoothing:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">nilearn</span> <span class="k">import</span> <span class="n">image</span>
<span class="gp">>>> </span><span class="n">smoothed_img</span> <span class="o">=</span> <span class="n">image</span><span class="o">.</span><span class="n">smooth_img</span><span class="p">(</span><span class="s2">"/home/user/t_map000.nii"</span><span class="p">,</span> <span class="n">fwhm</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
</pre></div>
</div>
<p>The returned value <cite>smoothed_img</cite> is a <a class="reference external" href="http://nipy.org/nibabel/nibabel_images.html">NiftiImage object</a>. It can either be passed
to other nilearn functions operating on niimgs (neuroimaging images) or
saved to disk with:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">smoothed_img</span><span class="o">.</span><span class="n">to_filename</span><span class="p">(</span><span class="s2">"/home/user/t_map000_smoothed.nii"</span><span class="p">)</span>
</pre></div>
</div>
<p>Finally, nilearn deals with Nifti images that come in two flavors: 3D
images, which represent a brain volume, and 4D images, which represent a
series of brain volumes. To extract the n-th 3D image from a 4D image, you can
use the <a class="reference internal" href="modules/generated/nilearn.image.index_img.html#nilearn.image.index_img" title="nilearn.image.index_img"><code class="xref py py-func docutils literal notranslate"><span class="pre">image.index_img</span></code></a> function (keep in mind that array indexing
always starts at 0 in the Python language):</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">first_volume</span> <span class="o">=</span> <span class="n">image</span><span class="o">.</span><span class="n">index_img</span><span class="p">(</span><span class="s2">"/home/user/fmri_volumes.nii"</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
</pre></div>
</div>
<p>To loop over each individual volume of a 4D image, use <a class="reference internal" href="modules/generated/nilearn.image.iter_img.html#nilearn.image.iter_img" title="nilearn.image.iter_img"><code class="xref py py-func docutils literal notranslate"><span class="pre">image.iter_img</span></code></a>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">for</span> <span class="n">volume</span> <span class="ow">in</span> <span class="n">image</span><span class="o">.</span><span class="n">iter_img</span><span class="p">(</span><span class="s2">"/home/user/fmri_volumes.nii"</span><span class="p">):</span>
<span class="gp">... </span> <span class="n">smoothed_img</span> <span class="o">=</span> <span class="n">image</span><span class="o">.</span><span class="n">smooth_img</span><span class="p">(</span><span class="n">volume</span><span class="p">,</span> <span class="n">fwhm</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
</pre></div>
</div>
<div class="green topic">
<p class="topic-title"><strong>Exercise: varying the amount of smoothing</strong></p>
<p>Want to sharpen your skills with nilearn?
Compute the mean EPI for first subject of the brain development
dataset downloaded with <a class="reference internal" href="modules/generated/nilearn.datasets.fetch_development_fmri.html#nilearn.datasets.fetch_development_fmri" title="nilearn.datasets.fetch_development_fmri"><code class="xref py py-func docutils literal notranslate"><span class="pre">nilearn.datasets.fetch_development_fmri</span></code></a> and
smooth it with an FWHM varying from 0mm to 20mm in increments of 5mm</p>
<p><strong>Hints:</strong></p>
<blockquote>
<div><ul class="simple">
<li>Inspect the ‘.keys()’ of the object returned by
<a class="reference internal" href="modules/generated/nilearn.datasets.fetch_development_fmri.html#nilearn.datasets.fetch_development_fmri" title="nilearn.datasets.fetch_development_fmri"><code class="xref py py-func docutils literal notranslate"><span class="pre">nilearn.datasets.fetch_development_fmri</span></code></a></li>
<li>Look at the “reference” section of the documentation: there is a
function to compute the mean of a 4D image</li>
<li>To perform a for loop in Python, you can use the “range” function</li>
<li>The solution can be found <a class="reference internal" href="auto_examples/06_manipulating_images/plot_smooth_mean_image.html#sphx-glr-auto-examples-06-manipulating-images-plot-smooth-mean-image-py"><span class="std std-ref">here</span></a></li>
</ul>
</div></blockquote>
</div>
<div class="line-block">
<div class="line"><br /></div>
</div>
<div class="topic">
<p class="topic-title"><strong>Tutorials to learn the basics</strong></p>
<p>The two following tutorials may be useful to get familiar with data
representation in nilearn:</p>
<ul class="simple">
<li><a class="reference internal" href="auto_examples/plot_nilearn_101.html#sphx-glr-auto-examples-plot-nilearn-101-py"><span class="std std-ref">Basic nilearn example: manipulating and looking at data</span></a></li>
<li><a class="reference internal" href="auto_examples/plot_3d_and_4d_niimg.html#sphx-glr-auto-examples-plot-3d-and-4d-niimg-py"><span class="std std-ref">3D and 4D niimgs: handling and visualizing</span></a></li>
</ul>
<p>More tutorials can be found <a class="reference internal" href="auto_examples/index.html#tutorial-examples"><span class="std std-ref">here</span></a></p>
</div>
<hr class="docutils" />
<p>Now, if you want out-of-the-box methods to process neuroimaging data, jump
directly to the section you need:</p>
<ul class="simple">
<li><a class="reference internal" href="decoding/index.html#decoding"><span class="std std-ref">Decoding and MVPA: predicting from brain images</span></a></li>
<li><a class="reference internal" href="connectivity/index.html#functional-connectivity"><span class="std std-ref">Functional connectivity and resting state</span></a></li>
</ul>
<div class="line-block">
<div class="line"><br /></div>
</div>
</div>
<div class="section" id="scientific-computing-with-python">
<h3>1.3.2. Scientific computing with Python<a class="headerlink" href="#scientific-computing-with-python" title="Permalink to this headline">¶</a></h3>
<p>In case you plan to become a casual nilearn user, note that you will not need
to deal with number and array manipulation directly in Python.
However, if you plan to go beyond that, here are a few pointers.</p>
<div class="section" id="basic-numerics">
<h4>1.3.2.1. Basic numerics<a class="headerlink" href="#basic-numerics" title="Permalink to this headline">¶</a></h4>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name" colspan="2">Numerical arrays:</th></tr>
<tr class="field-odd field"><td> </td><td class="field-body"><p class="first">The numerical data (e.g. matrices) are stored in numpy arrays:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">>>> </span><span class="n">t</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">2000</span><span class="p">)</span> <span class="c1"># 2000 points between 1 and 10</span>
<span class="gp">>>> </span><span class="n">t</span>
<span class="go">array([ 1. , 1.00450225, 1.0090045 , ..., 9.9909955 ,</span>
<span class="go"> 9.99549775, 10. ])</span>
<span class="gp">>>> </span><span class="n">t</span> <span class="o">/</span> <span class="mi">2</span>
<span class="go">array([ 0.5 , 0.50225113, 0.50450225, ..., 4.99549775,</span>
<span class="go"> 4.99774887, 5. ])</span>
<span class="gp">>>> </span><span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">t</span><span class="p">)</span> <span class="c1"># Operations on arrays are defined in the numpy module</span>
<span class="go">array([ 0.54030231, 0.53650833, 0.53270348, ..., -0.84393609,</span>
<span class="go"> -0.84151234, -0.83907153])</span>
<span class="gp">>>> </span><span class="n">t</span><span class="p">[:</span><span class="mi">3</span><span class="p">]</span> <span class="c1"># In Python indexing is done with [] and starts at zero</span>
<span class="go">array([ 1. , 1.00450225, 1.0090045 ])</span>
</pre></div>
</div>
<p><a class="reference external" href="http://scipy-lectures.github.io/intro/numpy/index.html">More documentation …</a></p>
</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Plotting and figures:</th></tr>
<tr class="field-even field"><td> </td><td class="field-body"><div class="first figure align-right">
<a class="reference external image-reference" href="auto_examples/plot_python_101.html"><img alt="_images/sphx_glr_plot_python_101_001.png" src="_images/sphx_glr_plot_python_101_001.png" style="width: 192.0px; height: 144.0px;" /></a>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="gp">>>> </span><span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">t</span><span class="p">))</span>
<span class="go">[<matplotlib.lines.Line2D object at ...>]</span>
</pre></div>
</div>
<p><a class="reference external" href="http://scipy-lectures.github.io/intro/matplotlib/matplotlib.html">More documentation …</a></p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name" colspan="2">Image processing:</th></tr>
<tr class="field-odd field"><td> </td><td class="field-body"><div class="first highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">scipy</span> <span class="k">import</span> <span class="n">ndimage</span>
<span class="gp">>>> </span><span class="n">t_smooth</span> <span class="o">=</span> <span class="n">ndimage</span><span class="o">.</span><span class="n">gaussian_filter</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">sigma</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
</pre></div>
</div>
<p><a class="reference external" href="http://scipy-lectures.github.io/advanced/image_processing/index.html">More documentation …</a></p>
</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Signal processing:</th></tr>
<tr class="field-even field"><td> </td><td class="field-body"><div class="first highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">scipy</span> <span class="k">import</span> <span class="n">signal</span>
<span class="gp">>>> </span><span class="n">t_detrended</span> <span class="o">=</span> <span class="n">signal</span><span class="o">.</span><span class="n">detrend</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
</pre></div>
</div>
<p><a class="reference external" href="http://scipy-lectures.github.io/intro/scipy.html#signal-processing-scipy-signal">More documentation …</a></p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Much more:</th><td class="field-body"><table class="hlist"><tr><td><ul>
<li><p class="first">Simple statistics:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">scipy</span> <span class="k">import</span> <span class="n">stats</span>
</pre></div>
</div>
</li>
</ul>
</td><td><ul>
<li><p class="first">Linear algebra:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">scipy</span> <span class="k">import</span> <span class="n">linalg</span>
</pre></div>
</div>
</li>
</ul>
</td></tr></table>
<p class="last"><a class="reference external" href="http://scipy-lectures.github.io/intro/scipy.html">More documentation…</a></p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="scikit-learn-machine-learning-in-python">
<h4>1.3.2.2. Scikit-learn: machine learning in Python<a class="headerlink" href="#scikit-learn-machine-learning-in-python" title="Permalink to this headline">¶</a></h4>
<div class="topic">
<p class="topic-title"><strong>What is scikit-learn?</strong></p>
<p><a class="reference external" href="http://scikit-learn.org">Scikit-learn</a> is a Python library for machine
learning. Its strong points are:</p>
<ul class="simple">
<li>Easy to use and well documented</li>
<li>Computationally efficient</li>
<li>Provides a wide variety of standard machine learning methods for non-experts</li>
</ul>
</div>
<p>The core concept in <a class="reference external" href="http://scikit-learn.org">scikit-learn</a> is the
estimator object, for instance an SVC (<a class="reference external" href="http://scikit-learn.org/stable/modules/svm.html">support vector classifier</a>).
It is first created with the relevant parameters:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">sklearn</span><span class="p">;</span> <span class="n">sklearn</span><span class="o">.</span><span class="n">set_config</span><span class="p">(</span><span class="n">print_changed_only</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">sklearn.svm</span> <span class="k">import</span> <span class="n">SVC</span>
<span class="gp">>>> </span><span class="n">svc</span> <span class="o">=</span> <span class="n">SVC</span><span class="p">(</span><span class="n">kernel</span><span class="o">=</span><span class="s1">'linear'</span><span class="p">,</span> <span class="n">C</span><span class="o">=</span><span class="mf">1.</span><span class="p">)</span>
</pre></div>
</div>
<p>These parameters are detailed in the documentation of
the object: in IPython or Jupter you can do:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>In [3]: SVC?
...
Parameters
----------
C : float or None, optional (default=None)
Penalty parameter C of the error term. If None then C is set
to n_samples.
kernel : string, optional (default='rbf')
Specifies the kernel type to be used in the algorithm.
It must be one of 'linear', 'poly', 'rbf', 'sigmoid', 'precomputed'.
If none is given, 'rbf' will be used.
...
</pre></div>
</div>
<p>Once the object is created, you can fit it on data. For instance, here we
use a hand-written digits dataset, which comes with scikit-learn:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">sklearn</span> <span class="k">import</span> <span class="n">datasets</span>
<span class="gp">>>> </span><span class="n">digits</span> <span class="o">=</span> <span class="n">datasets</span><span class="o">.</span><span class="n">load_digits</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">data</span> <span class="o">=</span> <span class="n">digits</span><span class="o">.</span><span class="n">data</span>
<span class="gp">>>> </span><span class="n">labels</span> <span class="o">=</span> <span class="n">digits</span><span class="o">.</span><span class="n">target</span>
</pre></div>
</div>
<p>Let’s use all but the last 10 samples to train the SVC:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">svc</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">data</span><span class="p">[:</span><span class="o">-</span><span class="mi">10</span><span class="p">],</span> <span class="n">labels</span><span class="p">[:</span><span class="o">-</span><span class="mi">10</span><span class="p">])</span>
<span class="go">SVC(C=1.0, ...)</span>
</pre></div>
</div>
<p>and try predicting the labels on the left-out data:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">svc</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="o">-</span><span class="mi">10</span><span class="p">:])</span>
<span class="go">array([5, 4, 8, 8, 4, 9, 0, 8, 9, 8])</span>
<span class="gp">>>> </span><span class="n">labels</span><span class="p">[</span><span class="o">-</span><span class="mi">10</span><span class="p">:]</span> <span class="c1"># The actual labels</span>
<span class="go">array([5, 4, 8, 8, 4, 9, 0, 8, 9, 8])</span>
</pre></div>
</div>
<p>To find out more, try the <a class="reference external" href="http://scikit-learn.org/stable/tutorial/index.html">scikit-learn tutorials</a>.</p>
</div>
</div>
<div class="section" id="finding-help">
<h3>1.3.3. Finding help<a class="headerlink" href="#finding-help" title="Permalink to this headline">¶</a></h3>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name" colspan="2">Reference material:</th></tr>
<tr class="field-odd field"><td> </td><td class="field-body"><ul class="first simple">
<li>A quick and gentle introduction to scientific computing with Python can
be found in the
<a class="reference external" href="http://scipy-lectures.github.io/">scipy lecture notes</a>.</li>
<li>The documentation of scikit-learn explains each method with tips on
practical use and examples:
<a class="reference external" href="http://scikit-learn.org/">http://scikit-learn.org/</a>.
While not specific to neuroimaging, it is often a recommended read.
Be careful to consult the documentation of the scikit-learn version
that you are using.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name" colspan="2">Mailing lists and forums:</th></tr>
<tr class="field-even field"><td> </td><td class="field-body"><ul class="first last simple">
<li>Don’t hesitate to ask questions about nilearn on <a class="reference external" href="https://neurostars.org/t/nilearn/">neurostars</a>.</li>
<li>You can find help with neuroimaging in Python (file I/O,
neuroimaging-specific questions) via the nipy user group:
<a class="reference external" href="https://groups.google.com/forum/?fromgroups#!forum/nipy-user">https://groups.google.com/forum/?fromgroups#!forum/nipy-user</a></li>
<li>For machine-learning and scikit-learn questions, expertise can be
found on the scikit-learn mailing list:
<a class="reference external" href="https://mail.python.org/mailman/listinfo/scikit-learn">https://mail.python.org/mailman/listinfo/scikit-learn</a></li>
</ul>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h4> Giving credit </h4>
<ul class="simple">
<li><p>Please consider <a href="authors.html#citing">citing the
papers</a>.</p></li>
</ul>
<h3><a href="index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">1. Introduction: nilearn in a nutshell</a><ul>
<li><a class="reference internal" href="#what-is-nilearn-mvpa-decoding-predictive-models-functional-connectivity">1.1. What is nilearn: MVPA, decoding, predictive models, functional connectivity</a><ul>
<li><a class="reference internal" href="#why-is-machine-learning-relevant-to-neuroimaging-a-few-examples">1.1.1. Why is machine learning relevant to NeuroImaging? A few examples!</a></li>
<li><a class="reference internal" href="#glossary-machine-learning-vocabulary">1.1.2. Glossary: machine learning vocabulary</a></li>
</ul>
</li>
<li><a class="reference internal" href="#installing-nilearn">1.2. Installing nilearn</a></li>
<li><a class="reference internal" href="#python-for-neuroimaging-a-quick-start">1.3. Python for NeuroImaging, a quick start</a><ul>
<li><a class="reference internal" href="#your-first-steps-with-nilearn">1.3.1. Your first steps with nilearn</a></li>
<li><a class="reference internal" href="#scientific-computing-with-python">1.3.2. Scientific computing with Python</a><ul>
<li><a class="reference internal" href="#basic-numerics">1.3.2.1. Basic numerics</a></li>
<li><a class="reference internal" href="#scikit-learn-machine-learning-in-python">1.3.2.2. Scikit-learn: machine learning in Python</a></li>
</ul>
</li>
<li><a class="reference internal" href="#finding-help">1.3.3. Finding help</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="user_guide.html"
title="previous chapter">User guide: table of contents</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="decoding/index.html"
title="next chapter">2. Decoding and MVPA: predicting from brain images</a></p>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
© The nilearn developers 2010-2020.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.8.5.
<span style="padding-left: 5ex;">
<a href="_sources/introduction.rst.txt"
rel="nofollow">Show this page source</a>
</span>
</div>
</body>
</html>