cleaning up
This commit is contained in:
@@ -318,7 +318,7 @@ MathJax.Hub.Config({
|
||||
</center>
|
||||
<br>
|
||||
<center>
|
||||
<h4>Nov 2, 2022</h4>
|
||||
<h4>Nov 3, 2022</h4>
|
||||
</center> <!-- date -->
|
||||
<br>
|
||||
|
||||
|
||||
@@ -356,12 +356,6 @@ display(grades)
|
||||
X <span style="color: #666666">=</span> grades<span style="color: #666666">.</span>loc[:, grades<span style="color: #666666">.</span>columns <span style="color: #666666">!=</span> <span style="color: #BA2121">'Grade'</span>]<span style="color: #666666">.</span>values
|
||||
y <span style="color: #666666">=</span> grades<span style="color: #666666">.</span>loc[:, grades<span style="color: #666666">.</span>columns <span style="color: #666666">==</span> <span style="color: #BA2121">'Grade'</span>]<span style="color: #666666">.</span>values
|
||||
<span style="color: #008000">print</span>(X)
|
||||
<span style="color: #408080; font-style: italic"># Create the encoder.</span>
|
||||
encoder <span style="color: #666666">=</span> OneHotEncoder(handle_unknown<span style="color: #666666">=</span><span style="color: #BA2121">"ignore"</span>)
|
||||
<span style="color: #408080; font-style: italic"># Assume for simplicity all features are categorical.</span>
|
||||
encoder<span style="color: #666666">.</span>fit(X)
|
||||
<span style="color: #408080; font-style: italic"># Apply the encoder.</span>
|
||||
X <span style="color: #666666">=</span> encoder<span style="color: #666666">.</span>transform(X)
|
||||
<span style="color: #408080; font-style: italic"># Then do a Classification tree</span>
|
||||
tree_clf <span style="color: #666666">=</span> DecisionTreeClassifier(max_depth<span style="color: #666666">=2</span>)
|
||||
tree_clf<span style="color: #666666">.</span>fit(X, y)
|
||||
@@ -375,10 +369,6 @@ export_graphviz(
|
||||
)
|
||||
cmd <span style="color: #666666">=</span> <span style="color: #BA2121">'dot -Tpng DataFiles/grade.dot -o DataFiles/grades.png'</span>
|
||||
os<span style="color: #666666">.</span>system(cmd)
|
||||
|
||||
|
||||
<span style="color: #408080; font-style: italic">#data_pandas = pd.DataFrame(data,index=['Frodo','Bilbo','Aragorn','Sam'])</span>
|
||||
<span style="color: #408080; font-style: italic">#df.columns = ['First', 'Second', 'Third', 'Fourth', 'Fifth']</span>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -360,8 +360,8 @@ simpleprediction <span style="color: #666666">=</span> simpletree<span style="co
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Var:'</span>, variance[degree])
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'</span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121"> >= </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121"> + </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121"> = </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121">'</span><span style="color: #666666">.</span>format(error[degree], bias[degree], variance[degree], bias[degree]<span style="color: #666666">+</span>variance[degree]))
|
||||
|
||||
mse_simpletree<span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( np<span style="color: #666666">.</span>mean((y_test <span style="color: #666666">-</span> simpleprediction)<span style="color: #666666">**2</span>)
|
||||
<span style="color: #008000">print</span>(mse_simpletree)
|
||||
mse_simpletree<span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( np<span style="color: #666666">.</span>mean((y_test <span style="color: #666666">-</span> simpleprediction)<span style="color: #666666">**2</span>))
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Simple tree:"</span>,mse_simpletree)
|
||||
plt<span style="color: #666666">.</span>xlim(<span style="color: #666666">1</span>,maxdepth)
|
||||
plt<span style="color: #666666">.</span>plot(polydegree, error, label<span style="color: #666666">=</span><span style="color: #BA2121">'MSE'</span>)
|
||||
plt<span style="color: #666666">.</span>plot(polydegree, bias, label<span style="color: #666666">=</span><span style="color: #BA2121">'bias'</span>)
|
||||
|
||||
@@ -318,7 +318,7 @@ MathJax.Hub.Config({
|
||||
</center>
|
||||
<br>
|
||||
<center>
|
||||
<h4>Nov 2, 2022</h4>
|
||||
<h4>Nov 3, 2022</h4>
|
||||
</center> <!-- date -->
|
||||
<br>
|
||||
|
||||
|
||||
@@ -184,7 +184,7 @@ MathJax.Hub.Config({
|
||||
</center>
|
||||
<br>
|
||||
<center>
|
||||
<h4>Nov 2, 2022</h4>
|
||||
<h4>Nov 3, 2022</h4>
|
||||
</center> <!-- date -->
|
||||
<br>
|
||||
|
||||
@@ -1139,12 +1139,6 @@ display(grades)
|
||||
X = grades.loc[:, grades.columns != <span style="color: #CD5555">'Grade'</span>].values
|
||||
y = grades.loc[:, grades.columns == <span style="color: #CD5555">'Grade'</span>].values
|
||||
<span style="color: #658b00">print</span>(X)
|
||||
<span style="color: #228B22"># Create the encoder.</span>
|
||||
encoder = OneHotEncoder(handle_unknown=<span style="color: #CD5555">"ignore"</span>)
|
||||
<span style="color: #228B22"># Assume for simplicity all features are categorical.</span>
|
||||
encoder.fit(X)
|
||||
<span style="color: #228B22"># Apply the encoder.</span>
|
||||
X = encoder.transform(X)
|
||||
<span style="color: #228B22"># Then do a Classification tree</span>
|
||||
tree_clf = DecisionTreeClassifier(max_depth=<span style="color: #B452CD">2</span>)
|
||||
tree_clf.fit(X, y)
|
||||
@@ -1158,10 +1152,6 @@ export_graphviz(
|
||||
)
|
||||
cmd = <span style="color: #CD5555">'dot -Tpng DataFiles/grade.dot -o DataFiles/grades.png'</span>
|
||||
os.system(cmd)
|
||||
|
||||
|
||||
<span style="color: #228B22">#data_pandas = pd.DataFrame(data,index=['Frodo','Bilbo','Aragorn','Sam'])</span>
|
||||
<span style="color: #228B22">#df.columns = ['First', 'Second', 'Third', 'Fourth', 'Fifth']</span>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
@@ -2228,8 +2218,8 @@ simpleprediction = simpletree.predict(X_test_scaled)
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Var:'</span>, variance[degree])
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'{} >= {} + {} = {}'</span>.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
|
||||
|
||||
mse_simpletree= np.mean( np.mean((y_test - simpleprediction)**<span style="color: #B452CD">2</span>)
|
||||
<span style="color: #658b00">print</span>(mse_simpletree)
|
||||
mse_simpletree= np.mean( np.mean((y_test - simpleprediction)**<span style="color: #B452CD">2</span>))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Simple tree:"</span>,mse_simpletree)
|
||||
plt.xlim(<span style="color: #B452CD">1</span>,maxdepth)
|
||||
plt.plot(polydegree, error, label=<span style="color: #CD5555">'MSE'</span>)
|
||||
plt.plot(polydegree, bias, label=<span style="color: #CD5555">'bias'</span>)
|
||||
|
||||
@@ -262,7 +262,7 @@ MathJax.Hub.Config({
|
||||
</center>
|
||||
<br>
|
||||
<center>
|
||||
<h4>Nov 2, 2022</h4>
|
||||
<h4>Nov 3, 2022</h4>
|
||||
</center> <!-- date -->
|
||||
<br>
|
||||
|
||||
@@ -1147,12 +1147,6 @@ display(grades)
|
||||
X = grades.loc[:, grades.columns != <span style="color: #CD5555">'Grade'</span>].values
|
||||
y = grades.loc[:, grades.columns == <span style="color: #CD5555">'Grade'</span>].values
|
||||
<span style="color: #658b00">print</span>(X)
|
||||
<span style="color: #228B22"># Create the encoder.</span>
|
||||
encoder = OneHotEncoder(handle_unknown=<span style="color: #CD5555">"ignore"</span>)
|
||||
<span style="color: #228B22"># Assume for simplicity all features are categorical.</span>
|
||||
encoder.fit(X)
|
||||
<span style="color: #228B22"># Apply the encoder.</span>
|
||||
X = encoder.transform(X)
|
||||
<span style="color: #228B22"># Then do a Classification tree</span>
|
||||
tree_clf = DecisionTreeClassifier(max_depth=<span style="color: #B452CD">2</span>)
|
||||
tree_clf.fit(X, y)
|
||||
@@ -1166,10 +1160,6 @@ export_graphviz(
|
||||
)
|
||||
cmd = <span style="color: #CD5555">'dot -Tpng DataFiles/grade.dot -o DataFiles/grades.png'</span>
|
||||
os.system(cmd)
|
||||
|
||||
|
||||
<span style="color: #228B22">#data_pandas = pd.DataFrame(data,index=['Frodo','Bilbo','Aragorn','Sam'])</span>
|
||||
<span style="color: #228B22">#df.columns = ['First', 'Second', 'Third', 'Fourth', 'Fifth']</span>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
@@ -2224,8 +2214,8 @@ simpleprediction = simpletree.predict(X_test_scaled)
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Var:'</span>, variance[degree])
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'{} >= {} + {} = {}'</span>.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
|
||||
|
||||
mse_simpletree= np.mean( np.mean((y_test - simpleprediction)**<span style="color: #B452CD">2</span>)
|
||||
<span style="color: #658b00">print</span>(mse_simpletree)
|
||||
mse_simpletree= np.mean( np.mean((y_test - simpleprediction)**<span style="color: #B452CD">2</span>))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Simple tree:"</span>,mse_simpletree)
|
||||
plt.xlim(<span style="color: #B452CD">1</span>,maxdepth)
|
||||
plt.plot(polydegree, error, label=<span style="color: #CD5555">'MSE'</span>)
|
||||
plt.plot(polydegree, bias, label=<span style="color: #CD5555">'bias'</span>)
|
||||
|
||||
@@ -339,7 +339,7 @@ MathJax.Hub.Config({
|
||||
</center>
|
||||
<br>
|
||||
<center>
|
||||
<h4>Nov 2, 2022</h4>
|
||||
<h4>Nov 3, 2022</h4>
|
||||
</center> <!-- date -->
|
||||
<br>
|
||||
|
||||
@@ -1224,12 +1224,6 @@ display(grades)
|
||||
X <span style="color: #666666">=</span> grades<span style="color: #666666">.</span>loc[:, grades<span style="color: #666666">.</span>columns <span style="color: #666666">!=</span> <span style="color: #BA2121">'Grade'</span>]<span style="color: #666666">.</span>values
|
||||
y <span style="color: #666666">=</span> grades<span style="color: #666666">.</span>loc[:, grades<span style="color: #666666">.</span>columns <span style="color: #666666">==</span> <span style="color: #BA2121">'Grade'</span>]<span style="color: #666666">.</span>values
|
||||
<span style="color: #008000">print</span>(X)
|
||||
<span style="color: #408080; font-style: italic"># Create the encoder.</span>
|
||||
encoder <span style="color: #666666">=</span> OneHotEncoder(handle_unknown<span style="color: #666666">=</span><span style="color: #BA2121">"ignore"</span>)
|
||||
<span style="color: #408080; font-style: italic"># Assume for simplicity all features are categorical.</span>
|
||||
encoder<span style="color: #666666">.</span>fit(X)
|
||||
<span style="color: #408080; font-style: italic"># Apply the encoder.</span>
|
||||
X <span style="color: #666666">=</span> encoder<span style="color: #666666">.</span>transform(X)
|
||||
<span style="color: #408080; font-style: italic"># Then do a Classification tree</span>
|
||||
tree_clf <span style="color: #666666">=</span> DecisionTreeClassifier(max_depth<span style="color: #666666">=2</span>)
|
||||
tree_clf<span style="color: #666666">.</span>fit(X, y)
|
||||
@@ -1243,10 +1237,6 @@ export_graphviz(
|
||||
)
|
||||
cmd <span style="color: #666666">=</span> <span style="color: #BA2121">'dot -Tpng DataFiles/grade.dot -o DataFiles/grades.png'</span>
|
||||
os<span style="color: #666666">.</span>system(cmd)
|
||||
|
||||
|
||||
<span style="color: #408080; font-style: italic">#data_pandas = pd.DataFrame(data,index=['Frodo','Bilbo','Aragorn','Sam'])</span>
|
||||
<span style="color: #408080; font-style: italic">#df.columns = ['First', 'Second', 'Third', 'Fourth', 'Fifth']</span>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
@@ -2301,8 +2291,8 @@ simpleprediction <span style="color: #666666">=</span> simpletree<span style="co
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Var:'</span>, variance[degree])
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'</span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121"> >= </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121"> + </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121"> = </span><span style="color: #BB6688; font-weight: bold">{}</span><span style="color: #BA2121">'</span><span style="color: #666666">.</span>format(error[degree], bias[degree], variance[degree], bias[degree]<span style="color: #666666">+</span>variance[degree]))
|
||||
|
||||
mse_simpletree<span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( np<span style="color: #666666">.</span>mean((y_test <span style="color: #666666">-</span> simpleprediction)<span style="color: #666666">**2</span>)
|
||||
<span style="color: #008000">print</span>(mse_simpletree)
|
||||
mse_simpletree<span style="color: #666666">=</span> np<span style="color: #666666">.</span>mean( np<span style="color: #666666">.</span>mean((y_test <span style="color: #666666">-</span> simpleprediction)<span style="color: #666666">**2</span>))
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Simple tree:"</span>,mse_simpletree)
|
||||
plt<span style="color: #666666">.</span>xlim(<span style="color: #666666">1</span>,maxdepth)
|
||||
plt<span style="color: #666666">.</span>plot(polydegree, error, label<span style="color: #666666">=</span><span style="color: #BA2121">'MSE'</span>)
|
||||
plt<span style="color: #666666">.</span>plot(polydegree, bias, label<span style="color: #666666">=</span><span style="color: #BA2121">'bias'</span>)
|
||||
|
||||
Binary file not shown.
+518
-902
File diff suppressed because one or more lines are too long
@@ -742,12 +742,6 @@ display(grades)
|
||||
X = grades.loc[:, grades.columns != 'Grade'].values
|
||||
y = grades.loc[:, grades.columns == 'Grade'].values
|
||||
print(X)
|
||||
# Create the encoder.
|
||||
encoder = OneHotEncoder(handle_unknown="ignore")
|
||||
# Assume for simplicity all features are categorical.
|
||||
encoder.fit(X)
|
||||
# Apply the encoder.
|
||||
X = encoder.transform(X)
|
||||
# Then do a Classification tree
|
||||
tree_clf = DecisionTreeClassifier(max_depth=2)
|
||||
tree_clf.fit(X, y)
|
||||
@@ -763,9 +757,6 @@ cmd = 'dot -Tpng DataFiles/grade.dot -o DataFiles/grades.png'
|
||||
os.system(cmd)
|
||||
|
||||
|
||||
#data_pandas = pd.DataFrame(data,index=['Frodo','Bilbo','Aragorn','Sam'])
|
||||
#df.columns = ['First', 'Second', 'Third', 'Fourth', 'Fifth']
|
||||
|
||||
!ec
|
||||
|
||||
|
||||
@@ -1525,8 +1516,8 @@ for degree in range(1,maxdepth):
|
||||
print('Var:', variance[degree])
|
||||
print('{} >= {} + {} = {}'.format(error[degree], bias[degree], variance[degree], bias[degree]+variance[degree]))
|
||||
|
||||
mse_simpletree= np.mean( np.mean((y_test - simpleprediction)**2)
|
||||
print(mse_simpletree)
|
||||
mse_simpletree= np.mean( np.mean((y_test - simpleprediction)**2))
|
||||
print("Simple tree:",mse_simpletree)
|
||||
plt.xlim(1,maxdepth)
|
||||
plt.plot(polydegree, error, label='MSE')
|
||||
plt.plot(polydegree, bias, label='bias')
|
||||
|
||||
Reference in New Issue
Block a user