added to data organizing
This commit is contained in:
@@ -40,7 +40,8 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Representing data, overarching aims', 2, None, '___sec0')]}
|
||||
'sections': [('Representing data, overarching aims', 2, None, '___sec0'),
|
||||
('Representing data, overarching aims', 2, None, '___sec1')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -63,6 +64,7 @@ end of tocinfo -->
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">Representing data, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Representing data, overarching aims</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -112,6 +114,7 @@ end of tocinfo -->
|
||||
<ul class="pagination">
|
||||
<li class="active"><a href="._How2ReadData-bs000.html">1</a></li>
|
||||
<li><a href="._How2ReadData-bs001.html">2</a></li>
|
||||
<li><a href="._How2ReadData-bs002.html">3</a></li>
|
||||
<li><a href="._How2ReadData-bs001.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -40,7 +40,8 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Representing data, overarching aims', 2, None, '___sec0')]}
|
||||
'sections': [('Representing data, overarching aims', 2, None, '___sec0'),
|
||||
('Representing data, overarching aims', 2, None, '___sec1')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -63,6 +64,7 @@ end of tocinfo -->
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="#___sec0" style="font-size: 80%;">Representing data, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Representing data, overarching aims</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -82,18 +84,40 @@ end of tocinfo -->
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">scipy</span> <span style="color: #008000; font-weight: bold">import</span> sparse
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">pandas</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">pd</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">IPython.display</span> <span style="color: #008000; font-weight: bold">import</span> display
|
||||
eye <span style="color: #666666">=</span> np<span style="color: #666666">.</span>eye(<span style="color: #666666">4</span>)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(eye)
|
||||
sparse_mtx <span style="color: #666666">=</span> sparse<span style="color: #666666">.</span>csr_matrix(eye)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(sparse_mtx)
|
||||
x <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(<span style="color: #666666">-10</span>,<span style="color: #666666">10</span>,<span style="color: #666666">100</span>)
|
||||
y <span style="color: #666666">=</span> np<span style="color: #666666">.</span>sin(x)
|
||||
plt<span style="color: #666666">.</span>plot(x,y,marker<span style="color: #666666">=</span><span style="color: #BA2121">'x'</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
data <span style="color: #666666">=</span> {<span style="color: #BA2121">'Name'</span>: [<span style="color: #BA2121">"John"</span>, <span style="color: #BA2121">"Anna"</span>, <span style="color: #BA2121">"Peter"</span>, <span style="color: #BA2121">"Linda"</span>], <span style="color: #BA2121">'Location'</span>: [<span style="color: #BA2121">"Roma"</span>, <span style="color: #BA2121">"Napoli"</span>, <span style="color: #BA2121">"Torino"</span>, <span style="color: #BA2121">"Milano"</span>], <span style="color: #BA2121">'Age'</span>:[<span style="color: #666666">51</span>, <span style="color: #666666">21</span>, <span style="color: #666666">34</span>, <span style="color: #666666">45</span>]}
|
||||
data_pandas <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>DataFrame(data)
|
||||
display(data_pandas)
|
||||
</pre></div>
|
||||
<p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
<ul class="pagination">
|
||||
<li><a href="._How2ReadData-bs000.html">«</a></li>
|
||||
<li><a href="._How2ReadData-bs000.html">1</a></li>
|
||||
<li class="active"><a href="._How2ReadData-bs001.html">2</a></li>
|
||||
<li><a href="._How2ReadData-bs002.html">3</a></li>
|
||||
<li><a href="._How2ReadData-bs002.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
|
||||
@@ -40,7 +40,8 @@ Automatically generated HTML file from DocOnce source
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Representing data, overarching aims', 2, None, '___sec0')]}
|
||||
'sections': [('Representing data, overarching aims', 2, None, '___sec0'),
|
||||
('Representing data, overarching aims', 2, None, '___sec1')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -63,6 +64,7 @@ end of tocinfo -->
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- navigation toc: --> <li><a href="._How2ReadData-bs001.html#___sec0" style="font-size: 80%;">Representing data, overarching aims</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._How2ReadData-bs002.html#___sec1" style="font-size: 80%;">Representing data, overarching aims</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -112,6 +114,7 @@ end of tocinfo -->
|
||||
<ul class="pagination">
|
||||
<li class="active"><a href="._How2ReadData-bs000.html">1</a></li>
|
||||
<li><a href="._How2ReadData-bs001.html">2</a></li>
|
||||
<li><a href="._How2ReadData-bs002.html">3</a></li>
|
||||
<li><a href="._How2ReadData-bs001.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -147,6 +147,55 @@ td.padding {
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">scipy</span> <span style="color: #8B008B; font-weight: bold">import</span> sparse
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">pandas</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">pd</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">IPython.display</span> <span style="color: #8B008B; font-weight: bold">import</span> display
|
||||
eye = np.eye(<span style="color: #B452CD">4</span>)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(eye)
|
||||
sparse_mtx = sparse.csr_matrix(eye)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(sparse_mtx)
|
||||
x = np.linspace(-<span style="color: #B452CD">10</span>,<span style="color: #B452CD">10</span>,<span style="color: #B452CD">100</span>)
|
||||
y = np.sin(x)
|
||||
plt.plot(x,y,marker=<span style="color: #CD5555">'x'</span>)
|
||||
plt.show()
|
||||
data = {<span style="color: #CD5555">'Name'</span>: [<span style="color: #CD5555">"John"</span>, <span style="color: #CD5555">"Anna"</span>, <span style="color: #CD5555">"Peter"</span>, <span style="color: #CD5555">"Linda"</span>], <span style="color: #CD5555">'Location'</span>: [<span style="color: #CD5555">"Roma"</span>, <span style="color: #CD5555">"Napoli"</span>, <span style="color: #CD5555">"Torino"</span>, <span style="color: #CD5555">"Milano"</span>], <span style="color: #CD5555">'Age'</span>:[<span style="color: #B452CD">51</span>, <span style="color: #B452CD">21</span>, <span style="color: #B452CD">34</span>, <span style="color: #B452CD">45</span>]}
|
||||
data_pandas = pd.DataFrame(data)
|
||||
display(data_pandas)
|
||||
</pre></div>
|
||||
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec1">Representing data, overarching aims </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">scipy</span> <span style="color: #8B008B; font-weight: bold">import</span> sparse
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">pandas</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">pd</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">IPython.display</span> <span style="color: #8B008B; font-weight: bold">import</span> display
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">mglearn</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">sklearn</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.linear_model</span> <span style="color: #8B008B; font-weight: bold">import</span> LinearRegression
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.tree</span> <span style="color: #8B008B; font-weight: bold">import</span> DecisionTreeRegressor
|
||||
x, y = mglearn.datasets.make_wave(n_samples=<span style="color: #B452CD">100</span>)
|
||||
line = np.linspace(-<span style="color: #B452CD">3</span>,<span style="color: #B452CD">3</span>,<span style="color: #B452CD">1000</span>,endpoint=<span style="color: #658b00">False</span>).reshape(-<span style="color: #B452CD">1</span>,<span style="color: #B452CD">1</span>)
|
||||
reg = DecisionTreeRegressor(min_samples_split=<span style="color: #B452CD">3</span>).fit(x,y)
|
||||
plt.plot(line, reg.predict(line), label=<span style="color: #CD5555">"decision tree"</span>)
|
||||
regline = LinearRegression().fit(x,y)
|
||||
plt.plot(line, regline.predict(line), label= <span style="color: #CD5555">"Linear Rgression"</span>)
|
||||
plt.show()
|
||||
</pre></div>
|
||||
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -60,7 +60,8 @@ div { text-align: justify; text-justify: inter-word; }
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Representing data, overarching aims', 2, None, '___sec0')]}
|
||||
'sections': [('Representing data, overarching aims', 2, None, '___sec0'),
|
||||
('Representing data, overarching aims', 2, None, '___sec1')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -95,7 +96,57 @@ end of tocinfo -->
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eee8d5"><pre style="line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">scipy</span> <span style="color: #8B008B; font-weight: bold">import</span> sparse
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">pandas</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">pd</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">IPython.display</span> <span style="color: #8B008B; font-weight: bold">import</span> display
|
||||
eye = np.eye(<span style="color: #B452CD">4</span>)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(eye)
|
||||
sparse_mtx = sparse.csr_matrix(eye)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(sparse_mtx)
|
||||
x = np.linspace(-<span style="color: #B452CD">10</span>,<span style="color: #B452CD">10</span>,<span style="color: #B452CD">100</span>)
|
||||
y = np.sin(x)
|
||||
plt.plot(x,y,marker=<span style="color: #CD5555">'x'</span>)
|
||||
plt.show()
|
||||
data = {<span style="color: #CD5555">'Name'</span>: [<span style="color: #CD5555">"John"</span>, <span style="color: #CD5555">"Anna"</span>, <span style="color: #CD5555">"Peter"</span>, <span style="color: #CD5555">"Linda"</span>], <span style="color: #CD5555">'Location'</span>: [<span style="color: #CD5555">"Roma"</span>, <span style="color: #CD5555">"Napoli"</span>, <span style="color: #CD5555">"Torino"</span>, <span style="color: #CD5555">"Milano"</span>], <span style="color: #CD5555">'Age'</span>:[<span style="color: #B452CD">51</span>, <span style="color: #B452CD">21</span>, <span style="color: #B452CD">34</span>, <span style="color: #B452CD">45</span>]}
|
||||
data_pandas = pd.DataFrame(data)
|
||||
display(data_pandas)
|
||||
</pre></div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec1">Representing data, overarching aims </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eee8d5"><pre style="line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">scipy</span> <span style="color: #8B008B; font-weight: bold">import</span> sparse
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">pandas</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">pd</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">IPython.display</span> <span style="color: #8B008B; font-weight: bold">import</span> display
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">mglearn</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">sklearn</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.linear_model</span> <span style="color: #8B008B; font-weight: bold">import</span> LinearRegression
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.tree</span> <span style="color: #8B008B; font-weight: bold">import</span> DecisionTreeRegressor
|
||||
x, y = mglearn.datasets.make_wave(n_samples=<span style="color: #B452CD">100</span>)
|
||||
line = np.linspace(-<span style="color: #B452CD">3</span>,<span style="color: #B452CD">3</span>,<span style="color: #B452CD">1000</span>,endpoint=<span style="color: #658b00">False</span>).reshape(-<span style="color: #B452CD">1</span>,<span style="color: #B452CD">1</span>)
|
||||
reg = DecisionTreeRegressor(min_samples_split=<span style="color: #B452CD">3</span>).fit(x,y)
|
||||
plt.plot(line, reg.predict(line), label=<span style="color: #CD5555">"decision tree"</span>)
|
||||
regline = LinearRegression().fit(x,y)
|
||||
plt.plot(line, regline.predict(line), label= <span style="color: #CD5555">"Linear Rgression"</span>)
|
||||
plt.show()
|
||||
</pre></div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@@ -65,7 +65,8 @@ div { text-align: justify; text-justify: inter-word; }
|
||||
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Representing data, overarching aims', 2, None, '___sec0')]}
|
||||
'sections': [('Representing data, overarching aims', 2, None, '___sec0'),
|
||||
('Representing data, overarching aims', 2, None, '___sec1')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -100,7 +101,57 @@ end of tocinfo -->
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">scipy</span> <span style="color: #008000; font-weight: bold">import</span> sparse
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">pandas</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">pd</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">IPython.display</span> <span style="color: #008000; font-weight: bold">import</span> display
|
||||
eye <span style="color: #666666">=</span> np<span style="color: #666666">.</span>eye(<span style="color: #666666">4</span>)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(eye)
|
||||
sparse_mtx <span style="color: #666666">=</span> sparse<span style="color: #666666">.</span>csr_matrix(eye)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(sparse_mtx)
|
||||
x <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(<span style="color: #666666">-10</span>,<span style="color: #666666">10</span>,<span style="color: #666666">100</span>)
|
||||
y <span style="color: #666666">=</span> np<span style="color: #666666">.</span>sin(x)
|
||||
plt<span style="color: #666666">.</span>plot(x,y,marker<span style="color: #666666">=</span><span style="color: #BA2121">'x'</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
data <span style="color: #666666">=</span> {<span style="color: #BA2121">'Name'</span>: [<span style="color: #BA2121">"John"</span>, <span style="color: #BA2121">"Anna"</span>, <span style="color: #BA2121">"Peter"</span>, <span style="color: #BA2121">"Linda"</span>], <span style="color: #BA2121">'Location'</span>: [<span style="color: #BA2121">"Roma"</span>, <span style="color: #BA2121">"Napoli"</span>, <span style="color: #BA2121">"Torino"</span>, <span style="color: #BA2121">"Milano"</span>], <span style="color: #BA2121">'Age'</span>:[<span style="color: #666666">51</span>, <span style="color: #666666">21</span>, <span style="color: #666666">34</span>, <span style="color: #666666">45</span>]}
|
||||
data_pandas <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>DataFrame(data)
|
||||
display(data_pandas)
|
||||
</pre></div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec1">Representing data, overarching aims </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">scipy</span> <span style="color: #008000; font-weight: bold">import</span> sparse
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">pandas</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">pd</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">IPython.display</span> <span style="color: #008000; font-weight: bold">import</span> display
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">mglearn</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">sklearn</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.linear_model</span> <span style="color: #008000; font-weight: bold">import</span> LinearRegression
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.tree</span> <span style="color: #008000; font-weight: bold">import</span> DecisionTreeRegressor
|
||||
x, y <span style="color: #666666">=</span> mglearn<span style="color: #666666">.</span>datasets<span style="color: #666666">.</span>make_wave(n_samples<span style="color: #666666">=100</span>)
|
||||
line <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(<span style="color: #666666">-3</span>,<span style="color: #666666">3</span>,<span style="color: #666666">1000</span>,endpoint<span style="color: #666666">=</span><span style="color: #008000">False</span>)<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>,<span style="color: #666666">1</span>)
|
||||
reg <span style="color: #666666">=</span> DecisionTreeRegressor(min_samples_split<span style="color: #666666">=3</span>)<span style="color: #666666">.</span>fit(x,y)
|
||||
plt<span style="color: #666666">.</span>plot(line, reg<span style="color: #666666">.</span>predict(line), label<span style="color: #666666">=</span><span style="color: #BA2121">"decision tree"</span>)
|
||||
regline <span style="color: #666666">=</span> LinearRegression()<span style="color: #666666">.</span>fit(x,y)
|
||||
plt<span style="color: #666666">.</span>plot(line, regline<span style="color: #666666">.</span>predict(line), label<span style="color: #666666">=</span> <span style="color: #BA2121">"Linear Rgression"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<!-- dom:TITLE: Data Analysis and Machine Learning: Representing data -->\n",
|
||||
"# Data Analysis and Machine Learning: Representing data\n",
|
||||
"<!-- dom:AUTHOR: Morten Hjorth-Jensen at Department of Physics, University of Oslo & Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University -->\n",
|
||||
"<!-- Author: --> \n",
|
||||
"**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n",
|
||||
"\n",
|
||||
"Date: **Nov 26, 2017**\n",
|
||||
"\n",
|
||||
"Copyright 1999-2017, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"## Representing data, overarching aims"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%matplotlib inline\n",
|
||||
"\n",
|
||||
"import numpy as np\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"from scipy import sparse\n",
|
||||
"import pandas as pd\n",
|
||||
"from IPython.display import display\n",
|
||||
"eye = np.eye(4)\n",
|
||||
"print(eye)\n",
|
||||
"sparse_mtx = sparse.csr_matrix(eye)\n",
|
||||
"print(sparse_mtx)\n",
|
||||
"x = np.linspace(-10,10,100)\n",
|
||||
"y = np.sin(x)\n",
|
||||
"plt.plot(x,y,marker='x')\n",
|
||||
"plt.show()\n",
|
||||
"data = {'Name': [\"John\", \"Anna\", \"Peter\", \"Linda\"], 'Location': [\"Roma\", \"Napoli\", \"Torino\", \"Milano\"], 'Age':[51, 21, 34, 45]}\n",
|
||||
"data_pandas = pd.DataFrame(data)\n",
|
||||
"display(data_pandas)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Representing data, overarching aims"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"from scipy import sparse\n",
|
||||
"import pandas as pd\n",
|
||||
"from IPython.display import display\n",
|
||||
"import mglearn\n",
|
||||
"import sklearn\n",
|
||||
"from sklearn.linear_model import LinearRegression\n",
|
||||
"from sklearn.tree import DecisionTreeRegressor\n",
|
||||
"x, y = mglearn.datasets.make_wave(n_samples=100)\n",
|
||||
"line = np.linspace(-3,3,1000,endpoint=False).reshape(-1,1)\n",
|
||||
"reg = DecisionTreeRegressor(min_samples_split=3).fit(x,y)\n",
|
||||
"plt.plot(line, reg.predict(line), label=\"decision tree\")\n",
|
||||
"regline = LinearRegression().fit(x,y)\n",
|
||||
"plt.plot(line, regline.predict(line), label= \"Linear Rgression\")\n",
|
||||
"plt.show()"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -6,6 +6,48 @@ DATE: today
|
||||
!split
|
||||
===== Representing data, overarching aims =====
|
||||
!bblock
|
||||
|
||||
!bc pycod
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from scipy import sparse
|
||||
import pandas as pd
|
||||
from IPython.display import display
|
||||
eye = np.eye(4)
|
||||
print(eye)
|
||||
sparse_mtx = sparse.csr_matrix(eye)
|
||||
print(sparse_mtx)
|
||||
x = np.linspace(-10,10,100)
|
||||
y = np.sin(x)
|
||||
plt.plot(x,y,marker='x')
|
||||
plt.show()
|
||||
data = {'Name': ["John", "Anna", "Peter", "Linda"], 'Location': ["Roma", "Napoli", "Torino", "Milano"], 'Age':[51, 21, 34, 45]}
|
||||
data_pandas = pd.DataFrame(data)
|
||||
display(data_pandas)
|
||||
!ec
|
||||
!eblock
|
||||
|
||||
|
||||
|
||||
!split
|
||||
===== Representing data, overarching aims =====
|
||||
!bblock
|
||||
!bc pycod
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from scipy import sparse
|
||||
import pandas as pd
|
||||
from IPython.display import display
|
||||
import mglearn
|
||||
import sklearn
|
||||
from sklearn.linear_model import LinearRegression
|
||||
from sklearn.tree import DecisionTreeRegressor
|
||||
x, y = mglearn.datasets.make_wave(n_samples=100)
|
||||
line = np.linspace(-3,3,1000,endpoint=False).reshape(-1,1)
|
||||
reg = DecisionTreeRegressor(min_samples_split=3).fit(x,y)
|
||||
plt.plot(line, reg.predict(line), label="decision tree")
|
||||
regline = LinearRegression().fit(x,y)
|
||||
plt.plot(line, regline.predict(line), label= "Linear Rgression")
|
||||
plt.show()
|
||||
!ec
|
||||
!eblock
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ system doconce format html $name --html_style=bootstrap --pygments_html_style=de
|
||||
system doconce split_html $html.html --method=split --pagination --nav_button=bottom
|
||||
|
||||
# IPython notebook
|
||||
#system doconce format ipynb $name $opt
|
||||
system doconce format ipynb $name $opt
|
||||
|
||||
# LaTeX Beamer slides
|
||||
beamertheme=red_plain
|
||||
|
||||
Reference in New Issue
Block a user