added to data organizing
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user