<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de"><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://cleoparka.de/feed.xml" rel="self" type="application/atom+xml" /><link href="https://cleoparka.de/" rel="alternate" type="text/html" hreflang="de" /><updated>2026-06-20T02:00:04+02:00</updated><id>https://cleoparka.de/feed.xml</id><title type="html">Cleoparka</title><subtitle>Cleo Parka tüftelt sich die Welt, dass sie ihm gefällt.</subtitle><author><name>Cleo Parka</name><email>your-email@email.com</email></author><entry><title type="html">Mein neuer Beitrag Vimmi</title><link href="https://cleoparka.de/mein-neuer-beitrag/" rel="alternate" type="text/html" title="Mein neuer Beitrag Vimmi" /><published>2026-06-20T00:00:00+02:00</published><updated>2026-06-20T00:00:00+02:00</updated><id>https://cleoparka.de/mein-neuer-beitrag</id><content type="html" xml:base="https://cleoparka.de/mein-neuer-beitrag/"><![CDATA[<p>Die Sonne scheint. Doch das ist nur Schein.</p>

<p><img src="/assets/images/lighthouse.png" alt="Ein Leuchtturm als Testbild" /></p>]]></content><author><name>Cleo Parka</name><email>your-email@email.com</email></author><summary type="html"><![CDATA[Die Sonne scheint. Doch das ist nur Schein.]]></summary></entry><entry><title type="html">Star Trek: Ryker treffen</title><link href="https://cleoparka.de/Flirt-with-Ryker/" rel="alternate" type="text/html" title="Star Trek: Ryker treffen" /><published>2026-05-08T01:00:00+02:00</published><updated>2026-05-08T01:00:00+02:00</updated><id>https://cleoparka.de/Flirt%20with%20Ryker</id><content type="html" xml:base="https://cleoparka.de/Flirt-with-Ryker/"><![CDATA[<p>Wir freuen uns über das Leben in den Sternen.</p>]]></content><author><name>Cleo Parka</name><email>your-email@email.com</email></author><category term="jekyll" /><category term="update" /><summary type="html"><![CDATA[Wir freuen uns über das Leben in den Sternen.]]></summary></entry><entry><title type="html">Ich liebe Pferde wirklich</title><link href="https://cleoparka.de/apa-itu-shell/" rel="alternate" type="text/html" title="Ich liebe Pferde wirklich" /><published>2025-01-25T03:29:20+01:00</published><updated>2025-01-25T03:29:20+01:00</updated><id>https://cleoparka.de/apa-itu-shell</id><content type="html" xml:base="https://cleoparka.de/apa-itu-shell/"><![CDATA[<p>Ich weiß gar nicht mehr, wie das kam, dass Timo mich mit zum Reiten nahm. Freundschaft war vermutlich der primäre Grund, der zweite: Neugier, der dritte: Die glorreichen Sieben. Wenn ich bislang mit Leuten übers Reiten sprach, dann waren es immer unsere zwei Ausflüge zu einem Reiterhof in Logabirum, die mir in den Sinn kamen. Und trotz des leichten Schreckens, den sie mit sich brachten, sitze ich jetzt in einem Bett, das zu einem Reiterhof in Irland gehört. Hier mache ich gerade Working Holidays, die mit Holidays gehörig wenig zu tun haben. Und – ich greife vor – ich sitze hier auf Pferden, die meistens nicht nur in der Landschaft herumstehen, sondern auch darin laufen, schreiten, traben, galoppieren, meist mit mir obendrauf. Davon hätte ich höchstens zu träumen gewagt nach meinen Erlebnissen mit Timo und meinem ersten Leihpferd.</p>

<figure>
<img src="/apa-itu-shell/silje-midtgard-0F9oVQ3x2ak-unsplash.jpg" alt="kernel central of operating system" />
<figcaption>Pferdchen.</figcaption>
</figure>

<p>Ich war ungefähr neun. Mit dem Fahrrad zum Reiterhof zu fahren, war allein schon aufregend. So weite Strecken selbstständig hinter mich zu bringen, war ich nicht gewohnt. Das waren bestimmt zwölf Kilometer oder so. Oft mit Gegenwind – auf dem Hin- und dem Rückweg.</p>

<p>Ich weiß noch, dass Timo ein super Voltigierer war. Zumindest hat er an Wettbewerben teilgenommen. Und wohl deswegen durfte er sich einfach Pferde für einen Ausritt ins Grüne ausleihen und musste nicht im Kreis durch die Arena marschieren. Es war auch kein Thema, dass ich als Reitunkundiger auf so einem Ausflug mitkam. Bronko hieß mein Pferd, ein Name, der für meinen Geschmack zu sehr nach Gemüse klingt, um eines edlen Rosses würdig zu sein.</p>

<figure>
<img src="/apa-itu-shell/kernel.png" alt="kernel central of operating system" />
<figcaption>Fig 2. bagan kernel.</figcaption>
</figure>

<p>Zwei Gründe, die dafür sprechen , nach meiner Reiterfahrung mit Bronko nie wieder auf ein Pferd zu steigen:</p>

<ol>
  <li>Kurz nach dem Losreiten, vermutlich beim zweiten Besuch in Logabirum, fiel ich von Bronko herunter. Ich geriet so ins Gras, in knapper Entfernung einer Hausmauer, gegen die ich auch problemlos hätte knallen können. Ich tat das nicht, weiß aber spätestens seitdem, dass Pferderücken nicht nur optisch einen wesentlich höheren Abstand zum Boden aufweisen als mein Fahrradsattel. Und mein Fahrradunfall, der mir mein Untergebiss durcheinander haute, war schon schlimm.</li>
  <li>Als Timo mit seinem Pferd in den Trab ging, rannte Bronko hinterher. Mit der Folge, dass ich wie blöde im Sattel hoch- und runterhüpfte und feststellen musste, dass ich keine Kontrolle über das Pferd hatte. Timo stoppte mein Pferd und rettete mich (danke nochmal dafür!) vor dem erneuten Runterplumsen und einem vorzeitigen Verlust der Gradheit meines Untergebisses, das ja erst ein paar Jahre später beim Fahrradunfall seine endgültige Form gewinnen sollte. Seit diesem Vorfall vertrat ich mit festem Glauben die These vom Alphapferd, das die Herde führt, so wie Timos Pferd das meine in den Trab gebracht hat.</li>
</ol>

<p>Und trotzdem: Ich bin jetzt in Irland, bewohne ein Zimmer mit quietschendem Bett und meiner Freundin Johanna, die darin neben mir liegt und die Ursache für meinen Weg hierhin ist. Vier Wochen war sie schon hier, bevor ich nachkam. Ich nahm den Ryanair-Flieger (schrecklich: diese gelben Sitze) von Weeze nach Shannon, den Bus vom Flughafen nach Limerick Bus Station, von dort den Bus nach Abbeyfeale. Gegenüber dem Spar-Markt (gibt’s die eigentlich nur noch außerhalb von Deutschland? Nee, oder? Ich hab im Rheiderland auch mal wieder einen gesehen, ist aber schon länger her), also: gegenüber vom Spar-Markt bin ich ausgestiegen, dann zum Tesco-Markt gelaufen, dann da Süßigkeiten gekauft, dann bei der Familie Fitzgerald angerufen. Leona ist eine Tochter des Hauses, die mich abholte und erst mal Futtersäcke für die Hühner kaufte und zusammen mit dem Verkäufer in ihren Peugout donnerte, in dem ich saß und darüber staunte, wie selbstverständlich das Volk der Iren auf der falschen Seite fährt und die Gangschaltung mit links bedient.</p>

<p>Und das war erst der Anfang. Wie nur sollten in einem Land, in dem Autofahrer links in Kreisel hineinfahren, die mit „Yield“ beschriftet sind, die Pferde ordnungsgemäß funktionieren? Ich sollte es bald erfahren …</p>]]></content><author><name>Cleo Parka</name><email>your-email@email.com</email></author><category term="jekyll" /><category term="update" /><summary type="html"><![CDATA[Ich weiß gar nicht mehr, wie das kam, dass Timo mich mit zum Reiten nahm. Freundschaft war vermutlich der primäre Grund, der zweite: Neugier, der dritte: Die glorreichen Sieben. Wenn ich bislang mit Leuten übers Reiten sprach, dann waren es immer unsere zwei Ausflüge zu einem Reiterhof in Logabirum, die mir in den Sinn kamen. Und trotz des leichten Schreckens, den sie mit sich brachten, sitze ich jetzt in einem Bett, das zu einem Reiterhof in Irland gehört. Hier mache ich gerade Working Holidays, die mit Holidays gehörig wenig zu tun haben. Und – ich greife vor – ich sitze hier auf Pferden, die meistens nicht nur in der Landschaft herumstehen, sondern auch darin laufen, schreiten, traben, galoppieren, meist mit mir obendrauf. Davon hätte ich höchstens zu träumen gewagt nach meinen Erlebnissen mit Timo und meinem ersten Leihpferd.]]></summary></entry><entry><title type="html">Ich liebe Phasen wirklich</title><link href="https://cleoparka.de/schnupfen/" rel="alternate" type="text/html" title="Ich liebe Phasen wirklich" /><published>2025-01-22T03:29:20+01:00</published><updated>2025-01-22T03:29:20+01:00</updated><id>https://cleoparka.de/schnupfen</id><content type="html" xml:base="https://cleoparka.de/schnupfen/"><![CDATA[<p>Ich weiß gar nicht mehr, wie das kam, dass Timo mich mit zum Reiten nahm. Freundschaft war vermutlich der primäre Grund, der zweite: Neugier, der dritte: Die glorreichen Sieben. Wenn ich bislang mit Leuten übers Reiten sprach, dann waren es immer unsere zwei Ausflüge zu einem Reiterhof in Logabirum, die mir in den Sinn kamen. Und trotz des leichten Schreckens, den sie mit sich brachten, sitze ich jetzt in einem Bett, das zu einem Reiterhof in Irland gehört. Hier mache ich gerade Working Holidays, die mit Holidays gehörig wenig zu tun haben. Und – ich greife vor – ich sitze hier auf Pferden, die meistens nicht nur in der Landschaft herumstehen, sondern auch darin laufen, schreiten, traben, galoppieren, meist mit mir obendrauf. Davon hätte ich höchstens zu träumen gewagt nach meinen Erlebnissen mit Timo und meinem ersten Leihpferd.</p>

<figure>
<img src="/schnupfen/silje-midtgard-0F9oVQ3x2ak-unsplash.jpg" alt="kernel central of operating system" />
<figcaption>Pferdchen.</figcaption>
</figure>

<p>Ich war ungefähr neun. Mit dem Fahrrad zum Reiterhof zu fahren, war allein schon aufregend. So weite Strecken selbstständig hinter mich zu bringen, war ich nicht gewohnt. Das waren bestimmt zwölf Kilometer oder so. Oft mit Gegenwind – auf dem Hin- und dem Rückweg.</p>

<p>Ich weiß noch, dass Timo ein super Voltigierer war. Zumindest hat er an Wettbewerben teilgenommen. Und wohl deswegen durfte er sich einfach Pferde für einen Ausritt ins Grüne ausleihen und musste nicht im Kreis durch die Arena marschieren. Es war auch kein Thema, dass ich als Reitunkundiger auf so einem Ausflug mitkam. Bronko hieß mein Pferd, ein Name, der für meinen Geschmack zu sehr nach Gemüse klingt, um eines edlen Rosses würdig zu sein.</p>

<figure>
<img src="/apa-itu-shell/kernel.png" alt="kernel central of operating system" />
<figcaption>Fig 2. bagan kernel.</figcaption>
</figure>

<p>Zwei Gründe, die dafür sprechen , nach meiner Reiterfahrung mit Bronko nie wieder auf ein Pferd zu steigen:</p>

<ol>
  <li>Kurz nach dem Losreiten, vermutlich beim zweiten Besuch in Logabirum, fiel ich von Bronko herunter. Ich geriet so ins Gras, in knapper Entfernung einer Hausmauer, gegen die ich auch problemlos hätte knallen können. Ich tat das nicht, weiß aber spätestens seitdem, dass Pferderücken nicht nur optisch einen wesentlich höheren Abstand zum Boden aufweisen als mein Fahrradsattel. Und mein Fahrradunfall, der mir mein Untergebiss durcheinander haute, war schon schlimm.</li>
  <li>Als Timo mit seinem Pferd in den Trab ging, rannte Bronko hinterher. Mit der Folge, dass ich wie blöde im Sattel hoch- und runterhüpfte und feststellen musste, dass ich keine Kontrolle über das Pferd hatte. Timo stoppte mein Pferd und rettete mich (danke nochmal dafür!) vor dem erneuten Runterplumsen und einem vorzeitigen Verlust der Gradheit meines Untergebisses, das ja erst ein paar Jahre später beim Fahrradunfall seine endgültige Form gewinnen sollte. Seit diesem Vorfall vertrat ich mit festem Glauben die These vom Alphapferd, das die Herde führt, so wie Timos Pferd das meine in den Trab gebracht hat.</li>
</ol>

<p>Und trotzdem: Ich bin jetzt in Irland, bewohne ein Zimmer mit quietschendem Bett und meiner Freundin Johanna, die darin neben mir liegt und die Ursache für meinen Weg hierhin ist. Vier Wochen war sie schon hier, bevor ich nachkam. Ich nahm den Ryanair-Flieger (schrecklich: diese gelben Sitze) von Weeze nach Shannon, den Bus vom Flughafen nach Limerick Bus Station, von dort den Bus nach Abbeyfeale. Gegenüber dem Spar-Markt (gibt’s die eigentlich nur noch außerhalb von Deutschland? Nee, oder? Ich hab im Rheiderland auch mal wieder einen gesehen, ist aber schon länger her), also: gegenüber vom Spar-Markt bin ich ausgestiegen, dann zum Tesco-Markt gelaufen, dann da Süßigkeiten gekauft, dann bei der Familie Fitzgerald angerufen. Leona ist eine Tochter des Hauses, die mich abholte und erst mal Futtersäcke für die Hühner kaufte und zusammen mit dem Verkäufer in ihren Peugout donnerte, in dem ich saß und darüber staunte, wie selbstverständlich das Volk der Iren auf der falschen Seite fährt und die Gangschaltung mit links bedient.</p>

<p>Und das war erst der Anfang. Wie nur sollten in einem Land, in dem Autofahrer links in Kreisel hineinfahren, die mit „Yield“ beschriftet sind, die Pferde ordnungsgemäß funktionieren? Ich sollte es bald erfahren …</p>]]></content><author><name>Cleo Parka</name><email>your-email@email.com</email></author><category term="jekyll" /><category term="update" /><summary type="html"><![CDATA[Ich weiß gar nicht mehr, wie das kam, dass Timo mich mit zum Reiten nahm. Freundschaft war vermutlich der primäre Grund, der zweite: Neugier, der dritte: Die glorreichen Sieben. Wenn ich bislang mit Leuten übers Reiten sprach, dann waren es immer unsere zwei Ausflüge zu einem Reiterhof in Logabirum, die mir in den Sinn kamen. Und trotz des leichten Schreckens, den sie mit sich brachten, sitze ich jetzt in einem Bett, das zu einem Reiterhof in Irland gehört. Hier mache ich gerade Working Holidays, die mit Holidays gehörig wenig zu tun haben. Und – ich greife vor – ich sitze hier auf Pferden, die meistens nicht nur in der Landschaft herumstehen, sondern auch darin laufen, schreiten, traben, galoppieren, meist mit mir obendrauf. Davon hätte ich höchstens zu träumen gewagt nach meinen Erlebnissen mit Timo und meinem ersten Leihpferd.]]></summary></entry><entry><title type="html">Was macht die Kunst!</title><link href="https://cleoparka.de/testo/" rel="alternate" type="text/html" title="Was macht die Kunst!" /><published>2024-08-29T04:29:20+02:00</published><updated>2024-08-29T04:29:20+02:00</updated><id>https://cleoparka.de/testo</id><content type="html" xml:base="https://cleoparka.de/testo/"><![CDATA[<p>Pizza ipsum dolor amet buffalo sauce anchovies mushrooms, NY style peppers melted cheese platter burnt mouth. Steak white garlic green bell peppers bbq sauce thin crust pepperoni string cheese deep crust party bbq. Pan pizza deep crust extra sauce platter burnt mouth peppers. Philly chicken burnt mouth beef chicken and bacon, bbq rib pie mozzarella hand tossed sauteed onions stuffed.</p>

<p>Peppers black olives lasagna, extra sauce white garlic steak pie stuffed beef sausage stuffed crust meat lovers bbq marinara deep crust. Buffalo sauce pineapple bacon chicken and bacon NY style anchovies pork spinach stuffed thin crust philly chicken party. Extra sauce lasagna hawaiian, Chicago style pan white pizza pork pineapple bacon thin crust. Ricotta hand tossed lasagna, stuffed bbq sauce pineapple thin crust fresh tomatoes melted cheese.
Pizza ipsum dolor amet buffalo sauce anchovies mushrooms, NY style peppers melted cheese platter burnt mouth. Steak white garlic green bell peppers bbq sauce thin crust pepperoni string cheese deep crust party bbq. Pan pizza deep crust extra sauce platter burnt mouth peppers. Philly chicken burnt mouth beef chicken and bacon, bbq rib pie mozzarella hand tossed sauteed onions stuffed.</p>

<p>Peppers black olives lasagna, extra sauce white garlic steak pie stuffed beef sausage stuffed crust meat lovers bbq marinara deep crust. Buffalo sauce pineapple bacon chicken and bacon NY style anchovies pork spinach stuffed thin crust philly chicken party. Extra sauce lasagna hawaiian, Chicago style pan white pizza pork pineapple bacon thin crust. Ricotta hand tossed lasagna, stuffed bbq sauce pineapple thin crust fresh tomatoes melted cheese.Pizza ipsum dolor amet buffalo sauce anchovies mushrooms, NY style peppers melted cheese platter burnt mouth. Steak white garlic green bell peppers bbq sauce thin crust pepperoni string cheese deep crust party bbq. Pan pizza deep crust extra sauce platter burnt mouth peppers. Philly chicken burnt mouth beef chicken and bacon, bbq rib pie mozzarella hand tossed sauteed onions stuffed.</p>

<p>Peppers black olives lasagna, extra sauce white garlic steak pie stuffed beef sausage stuffed crust meat lovers bbq marinara deep crust. Buffalo sauce pineapple bacon chicken and bacon NY style anchovies pork spinach stuffed thin crust philly chicken party. Extra sauce lasagna hawaiian, Chicago style pan white pizza pork pineapple bacon thin crust. Ricotta hand tossed lasagna, stuffed bbq sauce pineapple thin crust fresh tomatoes melted cheese.Pizza ipsum dolor amet buffalo sauce anchovies mushrooms, NY style peppers melted cheese platter burnt mouth. Steak white garlic green bell peppers bbq sauce thin crust pepperoni string cheese deep crust party bbq. Pan pizza deep crust extra sauce platter burnt mouth peppers. Philly chicken burnt mouth beef chicken and bacon, bbq rib pie mozzarella hand tossed sauteed onions stuffed.</p>

<p>Peppers black olives lasagna, extra sauce white garlic steak pie stuffed beef sausage stuffed crust meat lovers bbq marinara deep crust. Buffalo sauce pineapple bacon chicken and bacon NY style anchovies pork spinach stuffed thin crust philly chicken party. Extra sauce lasagna hawaiian, Chicago style pan white pizza pork pineapple bacon thin crust. Ricotta hand tossed lasagna, stuffed bbq sauce pineapple thin crust fresh tomatoes melted cheese.Pizza ipsum dolor amet buffalo sauce anchovies mushrooms, NY style peppers melted cheese platter burnt mouth. Steak white garlic green bell peppers bbq sauce thin crust pepperoni string cheese deep crust party bbq. Pan pizza deep crust extra sauce platter burnt mouth peppers. Philly chicken burnt mouth beef chicken and bacon, bbq rib pie mozzarella hand tossed sauteed onions stuffed.</p>

<p>Peppers black olives lasagna, extra sauce white garlic steak pie stuffed beef sausage stuffed crust meat lovers bbq marinara deep crust. Buffalo sauce pineapple bacon chicken and bacon NY style anchovies pork spinach stuffed thin crust philly chicken party. Extra sauce lasagna hawaiian, Chicago style pan white pizza pork pineapple bacon thin crust. Ricotta hand tossed lasagna, stuffed bbq sauce pineapple thin crust fresh tomatoes melted cheese.Pizza ipsum dolor amet buffalo sauce anchovies mushrooms, NY style peppers melted cheese platter burnt mouth. Steak white garlic green bell peppers bbq sauce thin crust pepperoni string cheese deep crust party bbq. Pan pizza deep crust extra sauce platter burnt mouth peppers. Philly chicken burnt mouth beef chicken and bacon, bbq rib pie mozzarella hand tossed sauteed onions stuffed.</p>

<p>Peppers black olives lasagna, extra sauce white garlic steak pie stuffed beef sausage stuffed crust meat lovers bbq marinara deep crust. Buffalo sauce pineapple bacon chicken and bacon NY style anchovies pork spinach stuffed thin crust philly chicken party. Extra sauce lasagna hawaiian, Chicago style pan white pizza pork pineapple bacon thin crust. Ricotta hand tossed lasagna, stuffed bbq sauce pineapple thin crust fresh tomatoes melted cheese.Pizza ipsum dolor amet buffalo sauce anchovies mushrooms, NY style peppers melted cheese platter burnt mouth. Steak white garlic green bell peppers bbq sauce thin crust pepperoni string cheese deep crust party bbq. Pan pizza deep crust extra sauce platter burnt mouth peppers. Philly chicken burnt mouth beef chicken and bacon, bbq rib pie mozzarella hand tossed sauteed onions stuffed.</p>

<p>Peppers black olives lasagna, extra sauce white garlic steak pie stuffed beef sausage stuffed crust meat lovers bbq marinara deep crust. Buffalo sauce pineapple bacon chicken and bacon NY style anchovies pork spinach stuffed thin crust philly chicken party. Extra sauce lasagna hawaiian, Chicago style pan white pizza pork pineapple bacon thin crust. Ricotta hand tossed lasagna, stuffed bbq sauce pineapple thin crust fresh tomatoes melted cheese.Pizza ipsum dolor amet buffalo sauce anchovies mushrooms, NY style peppers melted cheese platter burnt mouth. Steak white garlic green bell peppers bbq sauce thin crust pepperoni string cheese deep crust party bbq. Pan pizza deep crust extra sauce platter burnt mouth peppers. Philly chicken burnt mouth beef chicken and bacon, bbq rib pie mozzarella hand tossed sauteed onions stuffed.</p>

<p>Peppers black olives lasagna, extra sauce white garlic steak pie stuffed beef sausage stuffed crust meat lovers bbq marinara deep crust. Buffalo sauce pineapple bacon chicken and bacon NY style anchovies pork spinach stuffed thin crust philly chicken party. Extra sauce lasagna hawaiian, Chicago style pan white pizza pork pineapple bacon thin crust. Ricotta hand tossed lasagna, stuffed bbq sauce pineapple thin crust fresh tomatoes melted cheese.Pizza ipsum dolor amet buffalo sauce anchovies mushrooms, NY style peppers melted cheese platter burnt mouth. Steak white garlic green bell peppers bbq sauce thin crust pepperoni string cheese deep crust party bbq. Pan pizza deep crust extra sauce platter burnt mouth peppers. Philly chicken burnt mouth beef chicken and bacon, bbq rib pie mozzarella hand tossed sauteed onions stuffed.</p>

<p>Peppers black olives lasagna, extra sauce white garlic steak pie stuffed beef sausage stuffed crust meat lovers bbq marinara deep crust. Buffalo sauce pineapple bacon chicken and bacon NY style anchovies pork spinach stuffed thin crust philly chicken party. Extra sauce lasagna hawaiian, Chicago style pan white pizza pork pineapple bacon thin crust. Ricotta hand tossed lasagna, stuffed bbq sauce pineapple thin crust fresh tomatoes melted cheese.Pizza ipsum dolor amet buffalo sauce anchovies mushrooms, NY style peppers melted cheese platter burnt mouth. Steak white garlic green bell peppers bbq sauce thin crust pepperoni string cheese deep crust party bbq. Pan pizza deep crust extra sauce platter burnt mouth peppers. Philly chicken burnt mouth beef chicken and bacon, bbq rib pie mozzarella hand tossed sauteed onions stuffed.</p>

<p>Peppers black olives lasagna, extra sauce white garlic steak pie stuffed beef sausage stuffed crust meat lovers bbq marinara deep crust. Buffalo sauce pineapple bacon chicken and bacon NY style anchovies pork spinach stuffed thin crust philly chicken party. Extra sauce lasagna hawaiian, Chicago style pan white pizza pork pineapple bacon thin crust. Ricotta hand tossed lasagna, stuffed bbq sauce pineapple thin crust fresh tomatoes melted cheese.Pizza ipsum dolor amet buffalo sauce anchovies mushrooms, NY style peppers melted cheese platter burnt mouth. Steak white garlic green bell peppers bbq sauce thin crust pepperoni string cheese deep crust party bbq. Pan pizza deep crust extra sauce platter burnt mouth peppers. Philly chicken burnt mouth beef chicken and bacon, bbq rib pie mozzarella hand tossed sauteed onions stuffed.</p>

<p>Peppers black olives lasagna, extra sauce white garlic steak pie stuffed beef sausage stuffed crust meat lovers bbq marinara deep crust. Buffalo sauce pineapple bacon chicken and bacon NY style anchovies pork spinach stuffed thin crust philly chicken party. Extra sauce lasagna hawaiian, Chicago style pan white pizza pork pineapple bacon thin crust. Ricotta hand tossed lasagna, stuffed bbq sauce pineapple thin crust fresh tomatoes melted cheese.Pizza ipsum dolor amet buffalo sauce anchovies mushrooms, NY style peppers melted cheese platter burnt mouth. Steak white garlic green bell peppers bbq sauce thin crust pepperoni string cheese deep crust party bbq. Pan pizza deep crust extra sauce platter burnt mouth peppers. Philly chicken burnt mouth beef chicken and bacon, bbq rib pie mozzarella hand tossed sauteed onions stuffed.</p>

<p>Peppers black olives lasagna, extra sauce white garlic steak pie stuffed beef sausage stuffed crust meat lovers bbq marinara deep crust. Buffalo sauce pineapple bacon chicken and bacon NY style anchovies pork spinach stuffed thin crust philly chicken party. Extra sauce lasagna hawaiian, Chicago style pan white pizza pork pineapple bacon thin crust. Ricotta hand tossed lasagna, stuffed bbq sauce pineapple thin crust fresh tomatoes melted cheese.Pizza ipsum dolor amet buffalo sauce anchovies mushrooms, NY style peppers melted cheese platter burnt mouth. Steak white garlic green bell peppers bbq sauce thin crust pepperoni string cheese deep crust party bbq. Pan pizza deep crust extra sauce platter burnt mouth peppers. Philly chicken burnt mouth beef chicken and bacon, bbq rib pie mozzarella hand tossed sauteed onions stuffed.</p>

<p>Peppers black olives lasagna, extra sauce white garlic steak pie stuffed beef sausage stuffed crust meat lovers bbq marinara deep crust. Buffalo sauce pineapple bacon chicken and bacon NY style anchovies pork spinach stuffed thin crust philly chicken party. Extra sauce lasagna hawaiian, Chicago style pan white pizza pork pineapple bacon thin crust. Ricotta hand tossed lasagna, stuffed bbq sauce pineapple thin crust fresh tomatoes melted cheese.Pizza ipsum dolor amet buffalo sauce anchovies mushrooms, NY style peppers melted cheese platter burnt mouth. Steak white garlic green bell peppers bbq sauce thin crust pepperoni string cheese deep crust party bbq. Pan pizza deep crust extra sauce platter burnt mouth peppers. Philly chicken burnt mouth beef chicken and bacon, bbq rib pie mozzarella hand tossed sauteed onions stuffed.</p>

<p>Peppers black olives lasagna, extra sauce white garlic steak pie stuffed beef sausage stuffed crust meat lovers bbq marinara deep crust. Buffalo sauce pineapple bacon chicken and bacon NY style anchovies pork spinach stuffed thin crust philly chicken party. Extra sauce lasagna hawaiian, Chicago style pan white pizza pork pineapple bacon thin crust. Ricotta hand tossed lasagna, stuffed bbq sauce pineapple thin crust fresh tomatoes melted cheese.Pizza ipsum dolor amet buffalo sauce anchovies mushrooms, NY style peppers melted cheese platter burnt mouth. Steak white garlic green bell peppers bbq sauce thin crust pepperoni string cheese deep crust party bbq. Pan pizza deep crust extra sauce platter burnt mouth peppers. Philly chicken burnt mouth beef chicken and bacon, bbq rib pie mozzarella hand tossed sauteed onions stuffed.</p>

<p>Peppers black olives lasagna, extra sauce white garlic steak pie stuffed beef sausage stuffed crust meat lovers bbq marinara deep crust. Buffalo sauce pineapple bacon chicken and bacon NY style anchovies pork spinach stuffed thin crust philly chicken party. Extra sauce lasagna hawaiian, Chicago style pan white pizza pork pineapple bacon thin crust. Ricotta hand tossed lasagna, stuffed bbq sauce pineapple thin crust fresh tomatoes melted cheese.Pizza ipsum dolor amet buffalo sauce anchovies mushrooms, NY style peppers melted cheese platter burnt mouth. Steak white garlic green bell peppers bbq sauce thin crust pepperoni string cheese deep crust party bbq. Pan pizza deep crust extra sauce platter burnt mouth peppers. Philly chicken burnt mouth beef chicken and bacon, bbq rib pie mozzarella hand tossed sauteed onions stuffed.</p>

<p>Peppers black olives lasagna, extra sauce white garlic steak pie stuffed beef sausage stuffed crust meat lovers bbq marinara deep crust. Buffalo sauce pineapple bacon chicken and bacon NY style anchovies pork spinach stuffed thin crust philly chicken party. Extra sauce lasagna hawaiian, Chicago style pan white pizza pork pineapple bacon thin crust. Ricotta hand tossed lasagna, stuffed bbq sauce pineapple thin crust fresh tomatoes melted cheese.Pizza ipsum dolor amet buffalo sauce anchovies mushrooms, NY style peppers melted cheese platter burnt mouth. Steak white garlic green bell peppers bbq sauce thin crust pepperoni string cheese deep crust party bbq. Pan pizza deep crust extra sauce platter burnt mouth peppers. Philly chicken burnt mouth beef chicken and bacon, bbq rib pie mozzarella hand tossed sauteed onions stuffed.</p>

<p>Peppers black olives lasagna, extra sauce white garlic steak pie stuffed beef sausage stuffed crust meat lovers bbq marinara deep crust. Buffalo sauce pineapple bacon chicken and bacon NY style anchovies pork spinach stuffed thin crust philly chicken party. Extra sauce lasagna hawaiian, Chicago style pan white pizza pork pineapple bacon thin crust. Ricotta hand tossed lasagna, stuffed bbq sauce pineapple thin crust fresh tomatoes melted cheese.Pizza ipsum dolor amet buffalo sauce anchovies mushrooms, NY style peppers melted cheese platter burnt mouth. Steak white garlic green bell peppers bbq sauce thin crust pepperoni string cheese deep crust party bbq. Pan pizza deep crust extra sauce platter burnt mouth peppers. Philly chicken burnt mouth beef chicken and bacon, bbq rib pie mozzarella hand tossed sauteed onions stuffed.</p>

<p>Peppers black olives lasagna, extra sauce white garlic steak pie stuffed beef sausage stuffed crust meat lovers bbq marinara deep crust. Buffalo sauce pineapple bacon chicken and bacon NY style anchovies pork spinach stuffed thin crust philly chicken party. Extra sauce lasagna hawaiian, Chicago style pan white pizza pork pineapple bacon thin crust. Ricotta hand tossed lasagna, stuffed bbq sauce pineapple thin crust fresh tomatoes melted cheese.</p>]]></content><author><name>Cleo Parka</name><email>your-email@email.com</email></author><category term="jekyll" /><category term="update" /><summary type="html"><![CDATA[Pizza ipsum dolor amet buffalo sauce anchovies mushrooms, NY style peppers melted cheese platter burnt mouth. Steak white garlic green bell peppers bbq sauce thin crust pepperoni string cheese deep crust party bbq. Pan pizza deep crust extra sauce platter burnt mouth peppers. Philly chicken burnt mouth beef chicken and bacon, bbq rib pie mozzarella hand tossed sauteed onions stuffed.]]></summary></entry><entry><title type="html">Maths Example with Mathjax</title><link href="https://cleoparka.de/maths-example/" rel="alternate" type="text/html" title="Maths Example with Mathjax" /><published>2021-06-17T00:57:49+02:00</published><updated>2021-06-17T00:57:49+02:00</updated><id>https://cleoparka.de/maths-example</id><content type="html" xml:base="https://cleoparka.de/maths-example/"><![CDATA[<p>Below is an example of maths using mathjax.</p>

<p>Any page needing maths should start with the frontmatter:</p>

<figure class="highlight"><pre><code class="language-markdown" data-lang="markdown">usemathjax: true</code></pre></figure>

\[\begin{align*}
y = y(x,t) &amp;= A e^{i\theta} \\
&amp;= A (\cos \theta + i \sin \theta) \\
&amp;= A (\cos(kx - \omega t) + i \sin(kx - \omega t)) \\
&amp;= A\cos(kx - \omega t) + i A\sin(kx - \omega t)  \\
&amp;= A\cos \Big(\frac{2\pi}{\lambda}x - \frac{2\pi v}{\lambda} t \Big) + i A\sin \Big(\frac{2\pi}{\lambda}x - \frac{2\pi v}{\lambda} t \Big)  \\
&amp;= A\cos \frac{2\pi}{\lambda} (x - v t) + i A\sin \frac{2\pi}{\lambda} (x - v t)
\end{align*}\]

<p>Inline maths can be written with the <code class="language-plaintext highlighter-rouge">\\(</code> and <code class="language-plaintext highlighter-rouge">\\)</code> characters, producing inline maths
such as \(\delta(t) \xrightarrow{\mathscr{F}} 1\).</p>

<p>The above is accomplished with thanks to <a href="https://alanduan.me/random/mathjax/">Alan Duan</a> and <a href="https://webdocs.cs.ualberta.ca/~zichen2/blog/coding/setup/2019/02/17/how-to-add-mathjax-support-to-jekyll.html.">Zichen Vincent Zhang</a>.</p>]]></content><author><name>Cleo Parka</name><email>your-email@email.com</email></author><category term="jekyll" /><category term="update" /><summary type="html"><![CDATA[Below is an example of maths using mathjax.]]></summary></entry><entry><title type="html">Welcome to Jekyll!</title><link href="https://cleoparka.de/welcome-to-jekyll/" rel="alternate" type="text/html" title="Welcome to Jekyll!" /><published>2020-08-29T04:29:20+02:00</published><updated>2020-08-29T04:29:20+02:00</updated><id>https://cleoparka.de/welcome-to-jekyll</id><content type="html" xml:base="https://cleoparka.de/welcome-to-jekyll/"><![CDATA[<p>You’ll find this post in your <code class="language-plaintext highlighter-rouge">_posts</code> directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run <code class="language-plaintext highlighter-rouge">jekyll serve</code>, which launches a web server and auto-regenerates your site when a file is updated.</p>

<p>Jekyll requires blog post files to be named according to the following format:</p>

<p><code class="language-plaintext highlighter-rouge">YEAR-MONTH-DAY-title.MARKUP</code></p>

<p>Where <code class="language-plaintext highlighter-rouge">YEAR</code> is a four-digit number, <code class="language-plaintext highlighter-rouge">MONTH</code> and <code class="language-plaintext highlighter-rouge">DAY</code> are both two-digit numbers, and <code class="language-plaintext highlighter-rouge">MARKUP</code> is the file extension representing the format used in the file. After that, include the necessary front matter. Take a look at the source for this post to get an idea about how it works.</p>

<p>Jekyll also offers powerful support for code snippets:</p>

<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="k">def</span> <span class="nf">print_hi</span><span class="p">(</span><span class="nb">name</span><span class="p">)</span>
  <span class="nb">puts</span> <span class="s2">"Hi, </span><span class="si">#{</span><span class="nb">name</span><span class="si">}</span><span class="s2">"</span>
<span class="k">end</span>
<span class="n">print_hi</span><span class="p">(</span><span class="s1">'Tom'</span><span class="p">)</span>
<span class="c1">#=&gt; prints 'Hi, Tom' to STDOUT.</span></code></pre></figure>

<p>Check out the <a href="https://jekyllrb.com/docs/home">Jekyll docs</a> for more info on how to get the most out of Jekyll. File all bugs/feature requests at <a href="https://github.com/jekyll/jekyll">Jekyll’s GitHub repo</a>. If you have questions, you can ask them on <a href="https://talk.jekyllrb.com/">Jekyll Talk</a>.</p>]]></content><author><name>Cleo Parka</name><email>your-email@email.com</email></author><category term="jekyll" /><category term="update" /><summary type="html"><![CDATA[You’ll find this post in your _posts directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run jekyll serve, which launches a web server and auto-regenerates your site when a file is updated.]]></summary></entry><entry><title type="html">Cara ribet memperbarui forked repo</title><link href="https://cleoparka.de/cara-memperbarui-fork-repository/" rel="alternate" type="text/html" title="Cara ribet memperbarui forked repo" /><published>2020-01-28T19:00:00+01:00</published><updated>2020-01-28T19:00:00+01:00</updated><id>https://cleoparka.de/cara-memperbarui-fork-repository</id><content type="html" xml:base="https://cleoparka.de/cara-memperbarui-fork-repository/"><![CDATA[<p>Berawal dari saya pengen memperbarui repo yang tua dari suatu organisasi, niatnya pengen rumat ulang nih, ternyata dari orginal reponya ada update, sekalian buat artikel deh, lebih kurang gambaranya seperti ini.</p>

<figure>
<img src="/cara-memperbarui-fork-repository/repo.png" alt="ilustrasi repo yang mau diupdate" />
<figcaption>Fig 1. Gambaran ribetnya.</figcaption>
</figure>

<p>Ada dua cara untuk memperbarui forked repository menggunakan web interface yang disediakan oleh github tapi ribet, atau melalui terminal yang lebih ribet lagi.</p>

<h3 id="melalui-github-boring-way-">Melalui Github (boring way) 💻</h3>

<ol>
  <li>Buka repo yang hasil fork di Github.</li>
  <li>Klik <strong>Pull Requests</strong> di sebelah kanan, lalu <strong>New Pull Request</strong>.</li>
  <li>Akan memunculkan hasil compare antara repo upstream dengan repo kamu(forked repo), dan jika menyatakan “There isn’t anything to compare.”, tekan link <strong>switching the base</strong>, yang mana sekarang repo kamu(forked repo) akan dibalik menjadi base repo dan repo upstream menjadi head repo.</li>
  <li>Tekan <strong>Create Pull Request</strong>, beri judul pull request, Tekan <strong>Send Pull Request</strong>.</li>
  <li>Tekan <strong>Merge Pull Request</strong> dan <strong>Confirm Merge</strong>.</li>
</ol>

<p>* <em>pastikan kamu tidak merubah apapun pada forked repo, supaya melakukan merge secara otomatis, kalo tidak ya paling2 konflik.</em></p>

<h3 id="melalui-terminal-️">Melalui terminal ⌨️</h3>

<p>Tambahkan remote alamat repository yang aslinya disini tak beri nama <code class="language-plaintext highlighter-rouge">upstream</code>., ganti <code class="language-plaintext highlighter-rouge">ORIGINAL_OWNER</code> dan <code class="language-plaintext highlighter-rouge">ORIGINAL_REPO</code> dengan alamat repo aslimu.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>git add remote upstream git@github.com:ORIGINAL_OWNER/ORIGINAL_REPO.git
<span class="nv">$ </span>git remote <span class="nt">-v</span>
<span class="o">&gt;</span> origin    git@github.com:piharpi/www.git <span class="o">(</span>fetch<span class="o">)</span> <span class="c"># forked repo</span>
<span class="o">&gt;</span> origin    git@github.com:piharpi/www.git <span class="o">(</span>push<span class="o">)</span> <span class="c"># forked repo</span>
<span class="o">&gt;</span> upstream    git@github.com:ORIGINAL_OWNER/ORIGINAL_REPO.git <span class="o">(</span>fetch<span class="o">)</span> <span class="c"># upstream repo / original repo</span>
<span class="o">&gt;</span> upstream    git@github.com:ORIGINAL_OWNER/ORIGINAL_REPO.git <span class="o">(</span>push<span class="o">)</span> <span class="c"># upstream repo / original repo</span>
</code></pre></div></div>

<p>Checkout ke local branch <code class="language-plaintext highlighter-rouge">master</code>.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>git checkout master
<span class="o">&gt;</span> Switched to branch <span class="s1">'master'</span>
</code></pre></div></div>

<p>Jika sudah, Merge local repo dengan remote <code class="language-plaintext highlighter-rouge">upstream/master</code>.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>git merge upstream/master
</code></pre></div></div>

<p>Terakhir push local repo ke remote <code class="language-plaintext highlighter-rouge">origin</code>.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>git add <span class="nt">-A</span>
<span class="nv">$ </span>git commit <span class="nt">-m</span> <span class="s2">"updating origin repo"</span> <span class="o">&amp;&amp;</span> git push <span class="nt">-u</span> origin master
</code></pre></div></div>

<p>Selamat mencoba cara ribet ini, semoga bisa dipahami, saya sendiri lebih senang melalui terminal, klo ada yang ribet kenapa cari yang mudah.</p>

<h5 id="resources">Resources</h5>

<ul>
  <li><a href="https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/syncing-a-fork">Syncing a fork</a></li>
  <li><a href="https://rick.cogley.info/post/update-your-forked-repository-directly-on-github/#top">Update your fork directly on Github</a></li>
</ul>]]></content><author><name>Cleo Parka</name><email>your-email@email.com</email></author><category term="tips" /><category term="git" /><category term="software" /><summary type="html"><![CDATA[Ada dua cara untuk memperbarui forked repository menggunakan web interface yang disediakan oleh github tapi ribet, atau melalui terminal yang lebih ribet lagi.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://cleoparka.de/cara-memperbarui-fork-repository/repo.png" /><media:content medium="image" url="https://cleoparka.de/cara-memperbarui-fork-repository/repo.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">How this site was born 👶</title><link href="https://cleoparka.de/how-this-site-was-made/" rel="alternate" type="text/html" title="How this site was born 👶" /><published>2018-09-28T04:45:47+02:00</published><updated>2018-09-28T04:45:47+02:00</updated><id>https://cleoparka.de/how-this-site-was-made</id><content type="html" xml:base="https://cleoparka.de/how-this-site-was-made/"><![CDATA[<p>The website was made using Jekyll the one of open source static sites generator, and using my own simple theme, I called <a href="https://github.com/piharpi/klise">klisé</a>.</p>

<hr />

<p>All the services are free, source code the site was placed on my <a href="https://github.com/piharpi/mahendrata.now.sh">github</a> repository and intergration with <del><a href="https://netlify.com">netlify</a></del> service, another service that you can use is <a href="https://pages.github.com/">github page</a> for hosting your own static site.</p>

<hr />

<h4 id="lets-do-this">Let’s do this</h4>

<p>So, before we start create a site, you need some tools, you can self paced for how to installing each tools, on this guide i’m just want to show you how to install jekyll and deploying in netlify, but make sure you have each tools below.</p>

<h4 id="prerequisites">Prerequisites</h4>

<p>Requirements before we doing magic show.</p>

<ul>
  <li><a href="https://www.ruby-lang.org/en/downloads/">Ruby</a> programming language</li>
  <li><a href="https://git-scm.com">Git</a> (version control)</li>
  <li><a href="https://netlify.com">Netlify</a> and <a href="https://github.com">Github</a> account</li>
  <li><a href="https://bundler.io">Bundler</a></li>
</ul>

<h4 id="installation">Installation</h4>

<p>First, you need some <a href="https://www.staticgen.com/">SSG</a>, there are many kind ssg, but in case i’m using Jekyll cause i’m already familiar with it, open your terminal and type command on below</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>bundle <span class="nb">install </span>jekyll <span class="c"># installing jekyll in your machine</span>
<span class="nv">$ </span>jekyll new my-site <span class="o">&amp;&amp;</span> <span class="nb">cd </span>my-site <span class="c"># create new jekyll project</span>
<span class="nv">$ </span>jekyll s <span class="c"># run jekyll server</span>
</code></pre></div></div>

<p>Now, jekyll is running on your local machine, open your browser and go to <code class="language-plaintext highlighter-rouge">localhost:4000</code> is default address from jekyll, press <kbd>CTRL</kbd> + <kbd>C</kbd> to stop the jekyll server.</p>

<h4 id="adding-remote-repository">Adding remote repository</h4>

<p>Before we adding remote repository, you must have <a href="https://github.com/new">github</a> repository, if already have repository, just add github remote address to your local folder, with the following commands</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>git init <span class="c"># initializing project folder</span>
<span class="nv">$ </span>git remote add origin https://github.com/YOUR-USERNAME/YOUR-REPO.git <span class="c"># change UPPERCASE with your own!</span>
<span class="nv">$ </span>git add <span class="nt">-A</span> <span class="o">&amp;&amp;</span> git commit <span class="nt">-m</span> <span class="s2">"Initialize"</span> <span class="o">&amp;&amp;</span> git push <span class="nt">-u</span> origin master <span class="c"># push code to github</span>
</code></pre></div></div>

<p>Now check your github repository, make sure the files is uploaded correctly.</p>

<h4 id="deploying-to-netlify">Deploying to netlify</h4>

<p>Go <a href="https://netlify.com">netlify</a> dashboard, and following this step.</p>

<ol>
  <li>click <code class="language-plaintext highlighter-rouge">new site from git</code>, then choose <code class="language-plaintext highlighter-rouge">Github</code>.</li>
  <li>then choose your repository where is the jekyll sources uploaded.</li>
  <li>netlify smart enough to configuring, we just need’s are hosting’s are hosting’s are hosting’s are hosting to click <code class="language-plaintext highlighter-rouge">Deploy site button</code>.</li>
</ol>

<p>Wait for moment, and voila..! your site’s are hosting and using <code class="language-plaintext highlighter-rouge">.netlify.com</code> tld, if your website wants to look professional, just buy a domain from your favorite domain store. or if you the first time, I advice using namecheap.com<em>(isn’t sponsor)</em> *based on my experienced it provides good service and have various TLDs.</p>

<p>So, what you waiting for, just create your own website for free.</p>]]></content><author><name>Cleo Parka</name><email>your-email@email.com</email></author><category term="blog" /><category term="netlify" /><category term="jekyll" /><category term="github" /><summary type="html"><![CDATA[All the services are free, a source code this site placed on github repository and intergration with netlify service, another service that you can use is github page for hosting your own static site.]]></summary></entry><entry><title type="html">Python Notes from Intro to Machine Learning</title><link href="https://cleoparka.de/python-notes-from-Intro-to-machine-learning/" rel="alternate" type="text/html" title="Python Notes from Intro to Machine Learning" /><published>2018-04-14T05:00:00+02:00</published><updated>2018-04-14T05:00:00+02:00</updated><id>https://cleoparka.de/python-notes-from-Intro-to-machine-learning</id><content type="html" xml:base="https://cleoparka.de/python-notes-from-Intro-to-machine-learning/"><![CDATA[<p><strong>This article is for Demo purpose</strong></p>

<p>The article was originally on <a href="https://github.com/risan/risanb.com/blob/master/content/posts/python-notes-from-intro-to-machine-learning/index.md">this repo</a></p>

<p>I rarely use Python. I only have one repository at Github that is written in Python: <a href="https://github.com/risan/iris-flower-classifier">iris-flower-classifier</a>. And it was written two years ago!</p>

<p>A few days ago I took this free course from Udacity: <a href="https://eu.udacity.com/course/intro-to-machine-learning--ud120">Intro to Machine Learning</a>. The machine learning related codes are quite easy to grasp since it simply uses the <a href="http://scikit-learn.org/">scikit-learn</a> modules. But most of the supporting Python modules that are provided by this course were like a black-box to me. I had no idea how to download a file in Python or what’s the difference between a list, a tuple and a dictionary.</p>

<p>That’s why I decided to read all of the provided Python modules and implement it myself. I ended up refactor most of the code so it’s easier to understand: <a href="https://github.com/risan/intro-to-machine-learning">github.com/risan/intro-to-machine-learning</a>.</p>

<p>So here are some notes and snippets of Python that I’ve been collecting so far (I’m not even halfway through the course 😝). Also, note that the codes here are still using Python version 2.7.</p>

<h3 id="example-table-overflow-table">Example Table overflow-table</h3>

<div class="overflow-table">

  <table>
    <thead>
      <tr>
        <th style="text-align: left">Markdown</th>
        <th style="text-align: left">HTML</th>
        <th style="text-align: center">Rendered Output</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td style="text-align: left"><code class="language-plaintext highlighter-rouge">[Example Link](#link)</code></td>
        <td style="text-align: left"><code class="language-plaintext highlighter-rouge">&lt;a href="#link"&gt;Example Link&lt;/a&gt;</code></td>
        <td style="text-align: center"><a href="#Link">Example Link</a></td>
      </tr>
      <tr>
        <td style="text-align: left"><code class="language-plaintext highlighter-rouge">_Be Italic_</code></td>
        <td style="text-align: left"><code class="language-plaintext highlighter-rouge">&lt;em&gt;Be Italic&lt;em/&gt;</code></td>
        <td style="text-align: center"><em>Be Italic</em></td>
      </tr>
      <tr>
        <td style="text-align: left"><code class="language-plaintext highlighter-rouge">**Be Bold**</code></td>
        <td style="text-align: left"><code class="language-plaintext highlighter-rouge">&lt;strong&gt;Be Italic&lt;strong/&gt;</code></td>
        <td style="text-align: center"><strong>Be Bold</strong></td>
      </tr>
    </tbody>
  </table>

</div>

<p>*) <em>resize to see difference</em></p>

<h3 id="example-table-without-overflow">Example Table without-overflow</h3>

<table>
  <thead>
    <tr>
      <th style="text-align: left">Markdown</th>
      <th style="text-align: left">HTML</th>
      <th style="text-align: center">Rendered Output</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="text-align: left"><code class="language-plaintext highlighter-rouge">[Example Link](#link)</code></td>
      <td style="text-align: left"><code class="language-plaintext highlighter-rouge">&lt;a href="#link"&gt;Example Link&lt;/a&gt;</code></td>
      <td style="text-align: center"><a href="#Link">Example Link</a></td>
    </tr>
    <tr>
      <td style="text-align: left"><code class="language-plaintext highlighter-rouge">_Be Italic_</code></td>
      <td style="text-align: left"><code class="language-plaintext highlighter-rouge">&lt;em&gt;Be Italic&lt;em/&gt;</code></td>
      <td style="text-align: center"><em>Be Italic</em></td>
    </tr>
    <tr>
      <td style="text-align: left"><code class="language-plaintext highlighter-rouge">**Be Bold**</code></td>
      <td style="text-align: left"><code class="language-plaintext highlighter-rouge">&lt;strong&gt;Be Italic&lt;strong/&gt;</code></td>
      <td style="text-align: center"><strong>Be Bold</strong></td>
    </tr>
  </tbody>
</table>

<p>*) <em>resize to see difference</em></p>

<h3 id="main-entry-file">Main Entry File</h3>

<p>Suppose our Python project is stored in <code class="language-plaintext highlighter-rouge">/foo/bar</code> directory. And this application has one file that serves as the single entry point. We can name this file <code class="language-plaintext highlighter-rouge">__main__.py</code> so we can run this project simply be referencing its directory path:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Referencing its directory.</span>
<span class="nv">$ </span>python /foo/bar

<span class="c"># It's equivalent to this.</span>
<span class="nv">$ </span>python /foo/bar/__main__.py
</code></pre></div></div>

<h3 id="import-python-module-dynamically">Import Python Module Dynamically</h3>

<p>Suppose we would like to import a Python module dynamically based on a variable value. We can achieve this through the <a href="https://docs.python.org/2/library/functions.html#__import__"><code class="language-plaintext highlighter-rouge">__import__</code></a> function:</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">module_name</span> <span class="o">=</span> <span class="sh">"</span><span class="s">numpy</span><span class="sh">"</span>

<span class="nf">__import__</span><span class="p">(</span><span class="n">module_name</span><span class="p">)</span>
</code></pre></div></div>

<h3 id="multiple-returns-in-python">Multiple Returns in Python</h3>

<p>In Python, it’s possible for a function or a method to return multiple values. We can do this simply by separating each return value by a comma:</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">test</span><span class="p">():</span>
    <span class="k">return</span> <span class="mi">100</span><span class="p">,</span> <span class="sh">"</span><span class="s">foo</span><span class="sh">"</span>

<span class="n">someNumber</span><span class="p">,</span> <span class="n">someString</span> <span class="o">=</span> <span class="nf">test</span><span class="p">()</span>
</code></pre></div></div>

<h3 id="importing-modules-outside-of-the-directory">Importing Modules Outside of the Directory</h3>

<p>In order to import a module from outside of the directory, we need to add that module’s directory path into the current file with <code class="language-plaintext highlighter-rouge">sys.path.append</code>. Suppose we have the following directory structure:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>|--foo
| |-- bar.py
|
|-- tools
| |-- speak_yoda.py
</code></pre></div></div>

<p>If we want to use the <code class="language-plaintext highlighter-rouge">speak_yoda.py</code> module within the <code class="language-plaintext highlighter-rouge">bar.py</code>, we can do the following:</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># /foo/bar.py
</span><span class="kn">import</span> <span class="n">os</span>

<span class="c1"># Use relative path to tools directory.
</span><span class="n">sys</span><span class="p">.</span><span class="n">path</span><span class="p">.</span><span class="nf">append</span><span class="p">(</span><span class="sh">"</span><span class="s">../tools</span><span class="sh">"</span><span class="p">)</span>

<span class="kn">import</span> <span class="n">speak_yoda</span>
</code></pre></div></div>

<p>However, this won’t work if we run the <code class="language-plaintext highlighter-rouge">baz.py</code> file from outside of its <code class="language-plaintext highlighter-rouge">foo</code> directory:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># It works inside of the /foo directory.</span>
<span class="nv">$ </span><span class="nb">cd</span> /foo
<span class="nv">$ </span>python bar.py

<span class="c"># But it won't work if the code runs from outside of /foo directory.</span>
<span class="nv">$ </span>python foo/bar.py
</code></pre></div></div>

<p>To solve this problem we can refer to the <code class="language-plaintext highlighter-rouge">tools</code> directory using its absolute path.</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># /foo/bar.py
</span><span class="kn">import</span> <span class="n">os</span>
<span class="kn">import</span> <span class="n">sys</span>

<span class="c1"># Get the directory name for this file.
</span><span class="n">current_dirname</span> <span class="o">=</span> <span class="n">os</span><span class="p">.</span><span class="n">path</span><span class="p">.</span><span class="nf">dirname</span><span class="p">(</span><span class="n">os</span><span class="p">.</span><span class="n">path</span><span class="p">.</span><span class="nf">realpath</span><span class="p">(</span><span class="n">__file__</span><span class="p">))</span>

<span class="c1"># Use the absolute path to the tools directory
</span><span class="n">tools_path</span> <span class="o">=</span> <span class="n">os</span><span class="p">.</span><span class="n">path</span><span class="p">.</span><span class="nf">abspath</span><span class="p">(</span><span class="n">os</span><span class="p">.</span><span class="n">path</span><span class="p">.</span><span class="nf">join</span><span class="p">(</span><span class="n">dirname</span><span class="p">,</span> <span class="sh">"</span><span class="s">../tools</span><span class="sh">"</span><span class="p">))</span>
<span class="n">sys</span><span class="p">.</span><span class="n">path</span><span class="p">.</span><span class="nf">append</span><span class="p">(</span><span class="n">tools_path</span><span class="p">)</span>

<span class="kn">import</span> <span class="n">speak_yoda</span>
</code></pre></div></div>

<h2 id="output">Output</h2>

<h3 id="print-the-emojis">Print The Emojis</h3>

<p>It turns out you can’t just print an emoji or any other Unicode characters to the console. You need to specify the encoding type beforehand:</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># coding: utf8
</span>
<span class="nf">print</span><span class="p">(</span><span class="sh">"</span><span class="s">😅</span><span class="sh">"</span><span class="p">)</span>
</code></pre></div></div>

<h3 id="pretty-print">Pretty Print</h3>

<p>We can use the <code class="language-plaintext highlighter-rouge">pprint</code> module to pretty-print Python data structure with a configurable indentation:</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="n">pprint</span>
<span class="n">pp</span> <span class="o">=</span> <span class="n">pprint</span><span class="p">.</span><span class="nc">PrettyPrinter</span><span class="p">(</span><span class="n">indent</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>

<span class="n">pp</span><span class="p">.</span><span class="nf">pprint</span><span class="p">(</span><span class="n">people</span><span class="p">)</span>
</code></pre></div></div>

<h2 id="working-with-pathname">Working with Pathname</h2>

<p>Read more about pathname manipulations in the <a href="https://docs.python.org/2/library/os.path.html"><code class="language-plaintext highlighter-rouge">os.path</code> documentation</a>.</p>

<h3 id="get-filename-from-url">Get Filename From URL</h3>

<p>Suppose the last segment of the URL contains a filename that we would like to download. We can extract this filename with the following code:</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="n">os</span>
<span class="kn">from</span> <span class="n">urlparse</span> <span class="kn">import</span> <span class="n">urlparse</span>

<span class="n">url</span> <span class="o">=</span> <span class="sh">"</span><span class="s">https://example.com/foo.txt</span><span class="sh">"</span>

<span class="n">url_components</span> <span class="o">=</span> <span class="nf">urlparse</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>

<span class="n">filename</span> <span class="o">=</span> <span class="n">os</span><span class="p">.</span><span class="n">path</span><span class="p">.</span><span class="nf">basename</span><span class="p">(</span><span class="n">url_components</span><span class="p">.</span><span class="n">path</span><span class="p">)</span> <span class="c1"># foo.txt
</span></code></pre></div></div>

<h3 id="check-if-file-exists">Check if File Exists</h3>

<p>To check whether the given file path exists or not:</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="n">os</span>

<span class="n">is_exists</span> <span class="o">=</span> <span class="n">os</span><span class="p">.</span><span class="n">path</span><span class="p">.</span><span class="nf">isfile</span><span class="p">(</span><span class="sh">"</span><span class="s">foo.txt</span><span class="sh">"</span><span class="p">)</span>
</code></pre></div></div>

<h3 id="create-a-directory-if-it-does-not-exists">Create a Directory if It Does Not Exists</h3>

<p>To create a directory only if it does not exist:</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="n">os</span>
<span class="kn">import</span> <span class="n">errno</span>

<span class="k">try</span><span class="p">:</span>
    <span class="n">os</span><span class="p">.</span><span class="nf">makedirs</span><span class="p">(</span><span class="n">directory_path</span><span class="p">)</span>
<span class="k">except</span> <span class="nb">OSError</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span>
    <span class="k">if</span> <span class="n">e</span><span class="p">.</span><span class="n">errno</span> <span class="o">!=</span> <span class="n">errno</span><span class="p">.</span><span class="n">EEXIST</span><span class="p">:</span>
        <span class="k">raise</span>
</code></pre></div></div>

<h2 id="working-with-files">Working with Files</h2>

<h3 id="downloading-a-file">Downloading a File</h3>

<p>We can use the <code class="language-plaintext highlighter-rouge">urllib</code> module to download a file in Python. The first argument is the file URL that we would like to download. The second argument is the optional filename that will be used to store the file.</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="n">urllib</span>

<span class="n">urllib</span><span class="p">.</span><span class="nf">urlretrieve</span><span class="p">(</span><span class="sh">"</span><span class="s">https://example.com/foo.txt</span><span class="sh">"</span><span class="p">,</span> <span class="sh">"</span><span class="s">foo.txt</span><span class="sh">"</span><span class="p">)</span>
</code></pre></div></div>

<h3 id="extracting-tar-file">Extracting Tar File</h3>

<p>There’s a built-in <code class="language-plaintext highlighter-rouge">tarfile</code> module that we can use to work with Tar file in Python. To extract the <code class="language-plaintext highlighter-rouge">tar.gz</code> file we can use the following code:</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="n">tarfile</span>

<span class="c1"># Open the file.
</span><span class="n">tfile</span> <span class="o">=</span> <span class="n">tarfile</span><span class="p">.</span><span class="nf">open</span><span class="p">(</span><span class="sh">"</span><span class="s">foo.tar.gz</span><span class="sh">"</span><span class="p">)</span>

<span class="c1"># Extract the file to the given path.
</span><span class="n">tfile</span><span class="p">.</span><span class="nf">extractall</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
</code></pre></div></div>

<p>We can pass the <code class="language-plaintext highlighter-rouge">mode</code> argument to the <code class="language-plaintext highlighter-rouge">open</code> method. By default, the <code class="language-plaintext highlighter-rouge">mode</code> would be <code class="language-plaintext highlighter-rouge">r</code>—reading mode with transparent compression. There are also other mode options that we can use:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">r:gz</code>: Reading mode with gzip compression.</li>
  <li><code class="language-plaintext highlighter-rouge">r:</code>: Reading mode without compression.</li>
  <li><code class="language-plaintext highlighter-rouge">a</code>: Appending mode without compression.</li>
  <li><code class="language-plaintext highlighter-rouge">w</code>: Writting mode without compression.</li>
  <li>Checkout other available options in <a href="https://docs.python.org/2/library/tarfile.html">tarfile documentation</a>.</li>
</ul>

<h2 id="working-with-list">Working with List</h2>

<h3 id="generate-a-list-of-random-numbers">Generate a List of Random Numbers</h3>

<p>Use the <code class="language-plaintext highlighter-rouge">for..in</code> syntax to generate a list of random numbers in a one-liner style.</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="n">random</span>

<span class="c1"># Initialize internal state of random generator.
</span><span class="n">random</span><span class="p">.</span><span class="nf">seed</span><span class="p">(</span><span class="mi">42</span><span class="p">)</span>

<span class="c1"># Generate random points.
</span><span class="n">randomNumbers</span> <span class="o">=</span> <span class="p">[</span><span class="n">random</span><span class="p">.</span><span class="nf">random</span><span class="p">()</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nf">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">10</span><span class="p">)]</span>
<span class="c1"># [0.6394267984578837, 0.025010755222666936, 0.27502931836911926, ...]
</span></code></pre></div></div>

<h3 id="pair-values-from-two-lists">Pair Values from Two Lists</h3>

<p>The built-in <code class="language-plaintext highlighter-rouge">zip</code> function can pair values from two lists. However, this <code class="language-plaintext highlighter-rouge">zip</code> function will return a list of tuples instead. To get a list of value pairs, we can combine it with <code class="language-plaintext highlighter-rouge">for..in</code> syntax:</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">coordinates</span> <span class="o">=</span> <span class="p">[[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</span><span class="p">,</span><span class="n">y</span> <span class="ow">in</span> <span class="nf">zip</span><span class="p">([</span><span class="mi">5</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span><span class="mi">15</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">])]</span>
<span class="c1"># [[5, 0], [10, 1], [15, 0]]
</span></code></pre></div></div>

<h3 id="splitting-a-list">Splitting a List</h3>

<p>We can easily split a list in Python by specifying the starting index and it’s ending index. Note that the ending index is excluded from the result.</p>

<p>We can also specify a negative index. And also note that both of these indices are optional!</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">a</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">]</span>

<span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">3</span><span class="p">]</span>  <span class="c1"># 0,1,2
</span><span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="mi">3</span><span class="p">]</span>  <span class="c1"># 1,2
</span><span class="n">a</span><span class="p">[</span><span class="mi">2</span><span class="p">:]</span>   <span class="c1"># 2,3,4,5
</span><span class="n">a</span><span class="p">[:</span><span class="mi">3</span><span class="p">]</span>   <span class="c1"># 0,1,2
</span><span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="o">-</span><span class="mi">2</span><span class="p">]</span> <span class="c1"># 0,1,2,3
</span><span class="n">a</span><span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">:]</span>  <span class="c1"># 4,5
</span><span class="n">a</span><span class="p">[:]</span>    <span class="c1"># 0,1,2,3,4,5
</span></code></pre></div></div>

<h3 id="filtering-a-list-in-one-line">Filtering a List In One Line</h3>

<p>We can easily filter a list in Python by combining the <code class="language-plaintext highlighter-rouge">for..in</code> and the <code class="language-plaintext highlighter-rouge">if</code> syntax together:</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">numbers</span> <span class="o">=</span> <span class="nf">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">11</span><span class="p">)</span>

<span class="c1"># Filter even numbers only.
</span><span class="p">[</span><span class="n">numbers</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nf">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nf">len</span><span class="p">(</span><span class="n">numbers</span><span class="p">))</span> <span class="k">if</span> <span class="n">numbers</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">0</span><span class="p">]</span>
<span class="c1"># [2, 4, 6, 8, 10]
</span></code></pre></div></div>

<h3 id="sorting-a-list-in-ascending-order">Sorting a List in Ascending Order</h3>

<p>In Python, we can sort a list in ascending order simply by calling the <code class="language-plaintext highlighter-rouge">sort</code> method like so:</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">people</span> <span class="o">=</span> <span class="p">[</span><span class="sh">"</span><span class="s">John</span><span class="sh">"</span><span class="p">,</span> <span class="sh">"</span><span class="s">Alice</span><span class="sh">"</span><span class="p">,</span> <span class="sh">"</span><span class="s">Poe</span><span class="sh">"</span><span class="p">]</span>
<span class="n">people</span><span class="p">.</span><span class="nf">sort</span><span class="p">()</span>
<span class="nf">print</span><span class="p">(</span><span class="n">people</span><span class="p">)</span> <span class="c1"># ["Alice", "John", "Poe"]
</span></code></pre></div></div>

<h3 id="using-filter-function-with-a-list">Using Filter Function with a List</h3>

<p>Just like its name, we can use the <code class="language-plaintext highlighter-rouge">filter</code> function to filter out our list:</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">numbers</span> <span class="o">=</span> <span class="nf">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">11</span><span class="p">)</span>

<span class="n">even_numbers</span> <span class="o">=</span> <span class="nf">filter</span><span class="p">(</span><span class="k">lambda</span> <span class="n">number</span><span class="p">:</span> <span class="n">number</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">0</span><span class="p">,</span> <span class="n">numbers</span><span class="p">)</span>
<span class="c1"># [2, 4, 6, 8, 10]
</span></code></pre></div></div>

<p>We can break the above statement into two parts:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">lambda number: statement</code>: The first part is the function that we would like to run to every item on the list. <code class="language-plaintext highlighter-rouge">number</code> is the variable name we’d like to use in this function to refer to a single item from the <code class="language-plaintext highlighter-rouge">numbers</code> list. The following function body must evaluate to truthy/falsy value—falsy means the current item will be removed from the final result.</li>
  <li><code class="language-plaintext highlighter-rouge">numbers</code>: The second parameter is the list that we’d like to filter.</li>
</ul>

<h3 id="using-reduce-with-a-list-of-dictionary">Using Reduce with a List of Dictionary</h3>

<p>We can use the <code class="language-plaintext highlighter-rouge">reduce</code> function to calculate the total of a particular key in a list of a dictionary:</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">items</span> <span class="o">=</span> <span class="p">[{</span><span class="n">value</span><span class="p">:</span><span class="mi">10</span><span class="p">},</span> <span class="p">{</span><span class="n">value</span><span class="p">:</span><span class="mi">20</span><span class="p">},</span> <span class="p">{</span><span class="n">value</span><span class="p">:</span><span class="mi">50</span><span class="p">}]</span>

<span class="c1"># Calculate the total of value key.
</span><span class="n">totalValues</span> <span class="o">=</span> <span class="nf">reduce</span><span class="p">(</span><span class="k">lambda</span> <span class="n">total</span><span class="p">,</span> <span class="n">item</span><span class="p">:</span> <span class="n">total</span> <span class="o">+</span> <span class="n">item</span><span class="p">[</span><span class="sh">"</span><span class="s">value</span><span class="sh">"</span><span class="p">],</span> <span class="n">items</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="c1"># 80
</span></code></pre></div></div>

<p>It can be broken down into 4 parts:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">lambda total</code>: It’s the variable name that we’d like to use in the function body to refer to the carried or the accumulative value that will finally be returned.</li>
  <li><code class="language-plaintext highlighter-rouge">item: statement</code>: <code class="language-plaintext highlighter-rouge">item</code> is the name of the variable we’d like to use within the function body to refer to the single item in the <code class="language-plaintext highlighter-rouge">items</code> list. The following function body will be executed in order to define the accumulative value of <code class="language-plaintext highlighter-rouge">total</code> for the next iteration.</li>
  <li><code class="language-plaintext highlighter-rouge">items</code>: It’s the list of item that we would like to “reduce”.</li>
  <li><code class="language-plaintext highlighter-rouge">0</code>: The last parameter is optional and it’s the initial accumulative value for the first iteration.</li>
</ul>

<p>We can also use this <code class="language-plaintext highlighter-rouge">reduce</code> function to find a single item from the list. Here’s an example of code to find the person with the biggest <code class="language-plaintext highlighter-rouge">total_payments</code> within the given list of <code class="language-plaintext highlighter-rouge">people</code> dictionary.</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">people</span> <span class="o">=</span> <span class="p">[</span>
    <span class="p">{</span><span class="sh">"</span><span class="s">name</span><span class="sh">"</span><span class="p">:</span> <span class="sh">"</span><span class="s">John</span><span class="sh">"</span><span class="p">,</span> <span class="sh">"</span><span class="s">total_payments</span><span class="sh">"</span><span class="p">:</span> <span class="mi">100</span><span class="p">},</span>
    <span class="p">{</span><span class="sh">"</span><span class="s">name</span><span class="sh">"</span><span class="p">:</span> <span class="sh">"</span><span class="s">Alice</span><span class="sh">"</span><span class="p">,</span> <span class="sh">"</span><span class="s">total_payments</span><span class="sh">"</span><span class="p">:</span> <span class="mi">1000</span><span class="p">},</span>
    <span class="p">{</span><span class="sh">"</span><span class="s">name</span><span class="sh">"</span><span class="p">:</span> <span class="sh">"</span><span class="s">Poe</span><span class="sh">"</span><span class="p">,</span> <span class="sh">"</span><span class="s">total_payments</span><span class="sh">"</span><span class="p">:</span> <span class="mi">800</span><span class="p">}</span>
<span class="p">]</span>

<span class="n">person_biggest_total_payments</span> <span class="o">=</span> <span class="nf">reduce</span><span class="p">(</span><span class="k">lambda</span> <span class="n">paid_most</span><span class="p">,</span> <span class="n">person</span><span class="p">:</span> <span class="n">person</span> <span class="k">if</span> <span class="n">person</span><span class="p">[</span><span class="sh">"</span><span class="s">total_payments</span><span class="sh">"</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">paid_most</span><span class="p">[</span><span class="sh">"</span><span class="s">total_payments</span><span class="sh">"</span><span class="p">]</span> <span class="k">else</span> <span class="n">paid_most</span><span class="p">,</span> <span class="n">people</span><span class="p">,</span> <span class="p">{</span> <span class="sh">"</span><span class="s">total_payments</span><span class="sh">"</span><span class="p">:</span> <span class="mi">0</span> <span class="p">})</span>
<span class="c1"># {'name': 'Alice', 'total_payments': 1000}
</span></code></pre></div></div>

<h2 id="working-with-dictionary">Working with Dictionary</h2>

<h3 id="loop-through-dictionary">Loop Through Dictionary</h3>

<p>We can use the <code class="language-plaintext highlighter-rouge">itervalues</code> method to loop through a dictionary:</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">for</span> <span class="n">person</span> <span class="ow">in</span> <span class="n">people</span><span class="p">.</span><span class="nf">itervalues</span><span class="p">():</span>
    <span class="nf">print</span><span class="p">(</span><span class="n">person</span><span class="p">[</span><span class="sh">"</span><span class="s">email_address</span><span class="sh">"</span><span class="p">])</span>
</code></pre></div></div>

<p>We can also use the <code class="language-plaintext highlighter-rouge">iteritems</code> method if we want to access the key too:</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">for</span> <span class="n">person</span> <span class="ow">in</span> <span class="n">people</span><span class="p">.</span><span class="nf">iteritems</span><span class="p">():</span>
    <span class="nf">print</span><span class="p">(</span><span class="n">person</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="sh">"</span><span class="s">: </span><span class="sh">"</span> <span class="o">+</span> <span class="n">person</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="sh">"</span><span class="s">email_address</span><span class="sh">"</span><span class="p">])</span>
</code></pre></div></div>

<h3 id="calculate-total-of-particular-dictionary-key">Calculate Total of Particular Dictionary Key</h3>

<p>Suppose we would like to calculate the total amount of <code class="language-plaintext highlighter-rouge">salary</code> key on a <code class="language-plaintext highlighter-rouge">people</code> dictionary. We can extract the <code class="language-plaintext highlighter-rouge">salary</code> key and use the <code class="language-plaintext highlighter-rouge">sum</code> function to get the total:</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">total_salary</span> <span class="o">=</span> <span class="nf">sum</span><span class="p">([</span><span class="n">person</span><span class="p">[</span><span class="sh">"</span><span class="s">salary</span><span class="sh">"</span><span class="p">]</span> <span class="k">for</span> <span class="n">person</span> <span class="ow">in</span> <span class="n">people</span><span class="p">.</span><span class="nf">itervalues</span><span class="p">()])</span>
</code></pre></div></div>

<h2 id="working-with-numpy">Working with Numpy</h2>

<h3 id="numpy-create-range-of-values-with-the-given-interval">Numpy Create Range of Values with The Given Interval</h3>

<p>Use the <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html"><code class="language-plaintext highlighter-rouge">arange</code></a> method to create an array with an evenly spaced interval.</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="n">numpy</span> <span class="k">as</span> <span class="n">np</span>

<span class="n">np</span><span class="p">.</span><span class="nf">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="c1"># array([0,1,2,3,4])
</span>
<span class="n">np</span><span class="p">.</span><span class="nf">arange</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">)</span>
<span class="c1"># array([1. , 1.5, 2. , 2.5, 3. , 3.5])
</span></code></pre></div></div>

<h3 id="numpy-create-coordinate-matrices-from-coordinate-vectors">Numpy Create Coordinate Matrices from Coordinate Vectors</h3>

<p>We can use the Numpy <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.meshgrid.html"><code class="language-plaintext highlighter-rouge">meshgrid</code></a> method to make coordinate matrices from one-dimentional coordinate arrays.</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="n">numpy</span> <span class="k">as</span> <span class="n">np</span>

<span class="n">np</span><span class="p">.</span><span class="nf">meshgrid</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">7</span><span class="p">])</span>
<span class="c1"># [
#   array([[1,2,3], [1,2,3]]),
#   array([[0,0,0], [7,7,7]])
# ]
</span></code></pre></div></div>

<h3 id="flatten-numpy-array">Flatten Numpy Array</h3>

<p>When we have a multi-dimensional Numpy array, we can easily flatten it with the <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ravel.html"><code class="language-plaintext highlighter-rouge">ravel</code></a> method:</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="n">numpy</span> <span class="k">as</span> <span class="n">np</span>

<span class="n">arr</span> <span class="o">=</span> <span class="n">np</span><span class="p">.</span><span class="nf">array</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">]])</span>
<span class="n">arr</span><span class="p">.</span><span class="nf">ravel</span><span class="p">()</span>
<span class="c1"># array([1, 2, 3, 4])
</span></code></pre></div></div>

<h3 id="pairing-array-values-with-second-axis">Pairing Array Values with Second Axis</h3>

<p>We can use Numpy <code class="language-plaintext highlighter-rouge">c_</code> function to pair array values with another array that will be it’s second axis. Read the <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.c_.html"><code class="language-plaintext highlighter-rouge">numpy.c_</code> documentation</a>.</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="n">numpy</span> <span class="k">as</span> <span class="n">np</span>

<span class="n">x</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">]</span>
<span class="n">y</span> <span class="o">=</span> <span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mi">20</span><span class="p">]</span>

<span class="n">np</span><span class="p">.</span><span class="n">c_</span><span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">]</span>
<span class="c1"># array([1,10], [2,20])
</span></code></pre></div></div>

<h3 id="generate-coordinates-across-the-grid">Generate Coordinates Across The Grid</h3>

<p>With the knowledge of Numpy <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html"><code class="language-plaintext highlighter-rouge">arange</code></a>, <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.meshgrid.html"><code class="language-plaintext highlighter-rouge">meshgrid</code></a>, <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ravel.html"><code class="language-plaintext highlighter-rouge">ravel</code></a> and <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.c_.html"><code class="language-plaintext highlighter-rouge">c_</code></a> methods, we can easily generate an evenly spaced coordinates across the grid so we can pass it to the classifier and plot the decision surface.</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="n">numpy</span> <span class="k">as</span> <span class="n">np</span>

<span class="c1"># Generate an evenly spaced coordinates.
</span><span class="n">x_points</span><span class="p">,</span> <span class="n">y_points</span> <span class="o">=</span> <span class="n">np</span><span class="p">.</span><span class="nf">meshgrid</span><span class="p">(</span><span class="n">np</span><span class="p">.</span><span class="nf">arange</span><span class="p">(</span><span class="n">x_min</span><span class="p">,</span> <span class="n">x_max</span><span class="p">,</span> <span class="n">step</span><span class="p">),</span> <span class="n">np</span><span class="p">.</span><span class="nf">arange</span><span class="p">(</span><span class="n">y_min</span><span class="p">,</span> <span class="n">y_max</span><span class="p">,</span> <span class="n">step</span><span class="p">))</span>

<span class="c1"># Pair the x and y points.
</span><span class="n">test_coordinates</span> <span class="o">=</span> <span class="n">np</span><span class="p">.</span><span class="n">c_</span><span class="p">[</span><span class="n">x_points</span><span class="p">.</span><span class="nf">ravel</span><span class="p">(),</span> <span class="n">y_points</span><span class="p">.</span><span class="nf">ravel</span><span class="p">()]</span>
</code></pre></div></div>

<h2 id="plotting-the-data">Plotting the Data</h2>

<h3 id="plot-the-surface-decision">Plot The Surface Decision</h3>

<p>We can pass an evenly spaced coordinates across the grid to the classifier to predict the output on each of that coordinate. We can then use <a href="https://matplotlib.org/api/pyplot_api.html"><code class="language-plaintext highlighter-rouge">matplotlib.pyplot</code></a> to plot the surface decision.</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="n">matplotlib.pyplot</span> <span class="k">as</span> <span class="n">plt</span>
<span class="kn">import</span> <span class="n">pylab</span> <span class="k">as</span> <span class="n">pl</span>

<span class="c1"># Pass coordinates across the grid.
</span><span class="n">predicted_labels</span> <span class="o">=</span> <span class="n">classifier</span><span class="p">.</span><span class="nf">predict</span><span class="p">(</span><span class="n">test_coordinates</span><span class="p">)</span>

<span class="c1"># Don't forget to reshape the output array dimension.
</span><span class="n">predicted_labels</span> <span class="o">=</span> <span class="n">predicted_labels</span><span class="p">.</span><span class="nf">reshape</span><span class="p">(</span><span class="n">x_points</span><span class="p">.</span><span class="n">shape</span><span class="p">)</span>

<span class="c1"># Set the axes limit.
</span><span class="n">plt</span><span class="p">.</span><span class="nf">xlim</span><span class="p">(</span><span class="n">x_points</span><span class="p">.</span><span class="nf">min</span><span class="p">(),</span> <span class="n">x_points</span><span class="p">.</span><span class="nf">max</span><span class="p">())</span>
<span class="n">plt</span><span class="p">.</span><span class="nf">ylim</span><span class="p">(</span><span class="n">y_points</span><span class="p">.</span><span class="nf">min</span><span class="p">(),</span> <span class="n">y_points</span><span class="p">.</span><span class="nf">max</span><span class="p">())</span>

<span class="c1"># Plot the decision boundary with seismic color map.
</span><span class="n">plt</span><span class="p">.</span><span class="nf">pcolormesh</span><span class="p">(</span><span class="n">x_points</span><span class="p">,</span> <span class="n">y_points</span><span class="p">,</span> <span class="n">predicted_labels</span><span class="p">,</span> <span class="n">cmap</span> <span class="o">=</span> <span class="n">pl</span><span class="p">.</span><span class="n">cm</span><span class="p">.</span><span class="n">seismic</span><span class="p">)</span>
</code></pre></div></div>

<p>The classifier output would be a one-dimensional array, so don’t forget to <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html"><code class="language-plaintext highlighter-rouge">reshape</code></a> it back into a two-dimensional array before plotting. The <code class="language-plaintext highlighter-rouge">cmap</code> is an optional parameter for the color map. Here we use the <code class="language-plaintext highlighter-rouge">seismic</code> color map from <code class="language-plaintext highlighter-rouge">pylab</code> module. It has the red-blue colors.</p>

<h3 id="scatter-plot">Scatter Plot</h3>

<p>We need to separate the test points based on its predicted label (the speed). So we can plot the test points with two different colors.</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># Separate fast (label = 0) &amp; slow (label = 1) test points.
</span><span class="n">grade_fast</span> <span class="o">=</span> <span class="p">[</span><span class="n">features_test</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nf">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nf">len</span><span class="p">(</span><span class="n">features_test</span><span class="p">))</span> <span class="k">if</span> <span class="n">labels_test</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">]</span>
<span class="n">bumpy_fast</span> <span class="o">=</span> <span class="p">[</span><span class="n">features_test</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nf">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nf">len</span><span class="p">(</span><span class="n">features_test</span><span class="p">))</span> <span class="k">if</span> <span class="n">labels_test</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">]</span>
<span class="n">grade_slow</span> <span class="o">=</span> <span class="p">[</span><span class="n">features_test</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nf">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nf">len</span><span class="p">(</span><span class="n">features_test</span><span class="p">))</span> <span class="k">if</span> <span class="n">labels_test</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">]</span>
<span class="n">bumpy_slow</span> <span class="o">=</span> <span class="p">[</span><span class="n">features_test</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nf">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nf">len</span><span class="p">(</span><span class="n">features_test</span><span class="p">))</span> <span class="k">if</span> <span class="n">labels_test</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">]</span>

<span class="c1"># Plot the test points based on its speed.
</span><span class="n">plt</span><span class="p">.</span><span class="nf">scatter</span><span class="p">(</span><span class="n">grade_fast</span><span class="p">,</span> <span class="n">bumpy_fast</span><span class="p">,</span> <span class="n">color</span> <span class="o">=</span> <span class="sh">"</span><span class="s">b</span><span class="sh">"</span><span class="p">,</span> <span class="n">label</span> <span class="o">=</span> <span class="sh">"</span><span class="s">fast</span><span class="sh">"</span><span class="p">)</span>
<span class="n">plt</span><span class="p">.</span><span class="nf">scatter</span><span class="p">(</span><span class="n">grade_slow</span><span class="p">,</span> <span class="n">bumpy_slow</span><span class="p">,</span> <span class="n">color</span> <span class="o">=</span> <span class="sh">"</span><span class="s">r</span><span class="sh">"</span><span class="p">,</span> <span class="n">label</span> <span class="o">=</span> <span class="sh">"</span><span class="s">slow</span><span class="sh">"</span><span class="p">)</span>

<span class="c1"># Show the plot legend.
</span><span class="n">plt</span><span class="p">.</span><span class="nf">legend</span><span class="p">()</span>

<span class="c1"># Add the axis labels.
</span><span class="n">plt</span><span class="p">.</span><span class="nf">xlabel</span><span class="p">(</span><span class="sh">"</span><span class="s">grade</span><span class="sh">"</span><span class="p">)</span>
<span class="n">plt</span><span class="p">.</span><span class="nf">ylabel</span><span class="p">(</span><span class="sh">"</span><span class="s">bumpiness</span><span class="sh">"</span><span class="p">)</span>

<span class="c1"># Show the plot.
</span><span class="n">plt</span><span class="p">.</span><span class="nf">show</span><span class="p">()</span>
</code></pre></div></div>

<p>If we want to save the plot into an image, we can use the <code class="language-plaintext highlighter-rouge">savefig</code> method instead:</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">plt</span><span class="p">.</span><span class="nf">savefig</span><span class="p">(</span><span class="sh">'</span><span class="s">scatter_plot.png</span><span class="sh">'</span><span class="p">)</span>
</code></pre></div></div>

<h2 id="dealing-with-data">Dealing with Data</h2>

<h3 id="deserializing-python-object">Deserializing Python Object</h3>

<p>We can use <a href="https://docs.python.org/2/library/pickle.html"><code class="language-plaintext highlighter-rouge">pickle</code></a> module for serializing and deserializing Python object. There’s also the <code class="language-plaintext highlighter-rouge">cPickle</code>—the faster C implementation. We use both of these modules to deserialize the email text and author list.</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="n">pickle</span>
<span class="kn">import</span> <span class="n">cPickle</span>

<span class="c1"># Unpickling or deserializing the texts.
</span><span class="n">texts_file_handler</span> <span class="o">=</span> <span class="nf">open</span><span class="p">(</span><span class="n">texts_file</span><span class="p">,</span> <span class="sh">"</span><span class="s">r</span><span class="sh">"</span><span class="p">)</span>
<span class="n">texts</span> <span class="o">=</span> <span class="n">cPickle</span><span class="p">.</span><span class="nf">load</span><span class="p">(</span><span class="n">texts_file_handler</span><span class="p">)</span>
<span class="n">texts_file_handler</span><span class="p">.</span><span class="nf">close</span><span class="p">()</span>

<span class="c1"># Unpickling or deserializing the authors.
</span><span class="n">authors_file_handler</span> <span class="o">=</span> <span class="nf">open</span><span class="p">(</span><span class="n">authors_file</span><span class="p">,</span> <span class="sh">"</span><span class="s">r</span><span class="sh">"</span><span class="p">)</span>
<span class="n">authors</span> <span class="o">=</span> <span class="n">pickle</span><span class="p">.</span><span class="nf">load</span><span class="p">(</span><span class="n">authors_file_handler</span><span class="p">)</span>
<span class="n">authors_file_handler</span><span class="p">.</span><span class="nf">close</span><span class="p">()</span>
</code></pre></div></div>

<h3 id="split-data-for-training-and-testing">Split Data for Training and Testing</h3>

<p>We can use the built-in <a href="http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html"><code class="language-plaintext highlighter-rouge">train_test_split</code></a> function from scikit-learn to split the data both for training and testing.</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">from</span> <span class="n">sklearn.model_selection</span> <span class="kn">import</span> <span class="n">train_test_split</span>

<span class="n">features_train</span><span class="p">,</span> <span class="n">features_test</span><span class="p">,</span> <span class="n">labels_train</span><span class="p">,</span> <span class="n">labels_test</span> <span class="o">=</span> <span class="nf">train_test_split</span><span class="p">(</span><span class="n">texts</span><span class="p">,</span> <span class="n">authors</span><span class="p">,</span> <span class="n">test_size</span> <span class="o">=</span> <span class="mf">0.1</span><span class="p">,</span> <span class="n">random_state</span> <span class="o">=</span> <span class="mi">42</span><span class="p">)</span>
</code></pre></div></div>

<p>The <code class="language-plaintext highlighter-rouge">test_size</code> argument is the proportion of data to split into the test, in our case we split 10% for testing.</p>

<h3 id="vectorized-the-strings">Vectorized the Strings</h3>

<p>When working with a text document, we need to vectorize the strings into a list of numbers so it’s easier and more efficient to process. We can use the <a href="http://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.TfidfVectorizer.html"><code class="language-plaintext highlighter-rouge">TfidfVectorizer</code></a> class to vectorize the strings into a matrix of TF-IDF features.</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">from</span> <span class="n">sklearn.feature_extraction.text</span> <span class="kn">import</span> <span class="n">TfidfVectorizer</span>

<span class="n">vectorizer</span> <span class="o">=</span> <span class="nc">TfidfVectorizer</span><span class="p">(</span><span class="n">sublinear_tf</span> <span class="o">=</span> <span class="bp">True</span><span class="p">,</span> <span class="n">max_df</span> <span class="o">=</span> <span class="mf">0.5</span><span class="p">,</span> <span class="n">stop_words</span> <span class="o">=</span> <span class="sh">"</span><span class="s">english</span><span class="sh">"</span><span class="p">)</span>
<span class="n">features_train_transformed</span> <span class="o">=</span> <span class="n">vectorizer</span><span class="p">.</span><span class="nf">fit_transform</span><span class="p">(</span><span class="n">features_train</span><span class="p">)</span>
<span class="n">features_test_transformed</span> <span class="o">=</span> <span class="n">vectorizer</span><span class="p">.</span><span class="nf">transform</span><span class="p">(</span><span class="n">features_test</span><span class="p">)</span>
</code></pre></div></div>

<p>Word with a frequency higher than the <code class="language-plaintext highlighter-rouge">max_df</code> will be ignored. Stop words are also ignored—stop words are the most common words in a language (e.g. a, the, has).</p>

<h3 id="feature-selection">Feature Selection</h3>

<p>Text can have a lot of features thus it may slow to compute. We can use scikit <a href="http://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.SelectPercentile.html"><code class="language-plaintext highlighter-rouge">SelectPercentile</code></a> class to select only the important features.</p>

<div class="language-py highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">selector</span> <span class="o">=</span> <span class="nc">SelectPercentile</span><span class="p">(</span><span class="n">f_classif</span><span class="p">,</span> <span class="n">percentile</span> <span class="o">=</span> <span class="mi">10</span><span class="p">)</span>
<span class="n">selector</span><span class="p">.</span><span class="nf">fit</span><span class="p">(</span><span class="n">features_train_transformed</span><span class="p">,</span> <span class="n">labels_train</span><span class="p">)</span>
<span class="n">selected_features_train_transformed</span> <span class="o">=</span> <span class="n">selector</span><span class="p">.</span><span class="nf">transform</span><span class="p">(</span><span class="n">features_train_transformed</span><span class="p">).</span><span class="nf">toarray</span><span class="p">()</span>
<span class="n">selected_features_test_transformed</span> <span class="o">=</span> <span class="n">selector</span><span class="p">.</span><span class="nf">transform</span><span class="p">(</span><span class="n">features_test_transformed</span><span class="p">).</span><span class="nf">toarray</span><span class="p">()</span>
</code></pre></div></div>

<p>The <code class="language-plaintext highlighter-rouge">percentile</code> is the percentage of features that we’d like to select based on its highest score.</p>

<p><strong>This article is for Demo purpose</strong></p>

<p>The article was originally on <a href="https://github.com/risan/risanb.com/blob/master/content/posts/python-notes-from-intro-to-machine-learning/index.md">this repo</a></p>]]></content><author><name>Cleo Parka</name><email>your-email@email.com</email></author><category term="python" /><category term="machine-learning" /><summary type="html"><![CDATA[Notes and code snippets of Python that I've been collecting so far throughout the "Intro to Machine Learning" course.]]></summary></entry></feed>