background preloader

Machine learning en python

Facebook Twitter

The Python “with” Statement by Example. Python’s with statement was first introduced five years ago, in Python 2.5.

The Python “with” Statement by Example

It’s handy when you have two related operations which you’d like to execute as a pair, with a block of code in between. The classic example is opening a file, manipulating the file, then closing it: with open('output.txt', 'w') as f: f.write('Hi there! ') The above with statement will automatically close the file after the nested block of code. (Continue reading to see exactly how the close occurs.) Here’s another example. This code sample uses a Context object (“cairo context”) to draw six rectangles, each with a different rotation.

Cr.translate(68, 68) for i in xrange(6): cr.save() cr.rotate(2 * math.pi * i / 6) cr.rectangle(-25, -60, 50, 40) cr.stroke() cr.restore() That’s a fairly simple example, but for larger scripts, it can become cumbersome to keep track of which save goes with which restore, and to keep them correctly matched. Implementing the Context Manager as a Class Here’s the first approach.

Uh oh! More about interactive graphs using Python, d3.js, R, shiny, IPython, vincent, d3py, python-nvd3. I recently found this url The Big List of D3.js Examples.

More about interactive graphs using Python, d3.js, R, shiny, IPython, vincent, d3py, python-nvd3

As d3.js is getting popular - their website is pretty nice -, I was curious if I could easily use it through Python. After a couple of searches (many in fact), I discovered vincent and some others. It ended up doing a quick review. Every script was tested with Python 3. Contents: If you want to easily produce a html file including javascript (to publish it on your website for example), you only need to look at sections Graphs with Python and d3py, Graphs with IPython and nvd3. Use of IPython (qt)console The QtConsole looks like a command line window but is able to display images inline using matplotlib: You can enable it by using the following steps: Install pyqt (only once, Windows users can go there)Go to <Python folder>/Scripts and type ipython3 qtconsoleIn the console, type %matplotlib inline To test it is working, you can type and press enter: %load.

Python Tutorial: batch gradient descent algorithm - 2015. (Batch) gradient descent algorithm Gradient descent is an optimization algorithm that works by efficiently searching the parameter space, intercept(θ0) and slope(θ1) for linear regression, according to the following rule: θ:=θ−αδδθJ(θ).

Python Tutorial: batch gradient descent algorithm - 2015

Note that we used ':=' to denote an assign or an update. The J(θ) is known as the cost function and α is the learning rate, a free parameter. In this tutorial, we're going to use a least squares cost function defined as following: Twitter sentiment analysis using Python and NLTK. This post describes the implementation of sentiment analysis of tweets using Python and the natural language toolkit NLTK.

Twitter sentiment analysis using Python and NLTK

The post also describes the internals of NLTK related to this implementation. Background The purpose of the implementation is to be able to automatically classify a tweet as a positive or negative tweet sentiment wise. The classifier needs to be trained and to do that, we need a list of manually classified tweets. Let’s start with 5 positive tweets and 5 negative tweets. Basic Sentiment Analysis with Python. 01 nov 2012 [Update]: you can check out the code on Github In this post I will try to give a very introductory view of some techniques that could be useful when you want to perform a basic analysis of opinions written in english.

Basic Sentiment Analysis with Python

These techniques come 100% from experience in real-life projects. Develop Sentiment Analysis tool for your brand in 10 min - Textalytics. Have you ever tried to understand the buzz around your brand in social networks?

Develop Sentiment Analysis tool for your brand in 10 min - Textalytics

Simple metrics about the amount of friends or followers may matter, but what are they are actually saying? How do you extract insights from all those comments? At Textalytics, we are planning a series of tutorials to show you how you could use text analytics monitor your brand’s health. Today, we will talk about the fanciest feature: Sentiment Analysis. IPython Notebook PyAir analyse de l'air.

Text Processing in Python (a book) A couple of you make donations each month (out of about a thousand of you reading the text each week).

Text Processing in Python (a book)

Tragedy of the commons and all that... but if some more of you would donate a few bucks, that would be great support of the author. In a community spirit (and with permission of my publisher), I am making my book available to the Python community. Minor corrections can be made to later printings, and at the least errata noted on this website. Email me at <mertz@gnosis.cx> . A few caveats: (1) This stuff is copyrighted by AW (except the code samples which are released to the public domain). Data Structures and Algorithms with Object-Oriented Design Patterns in Python.