Programming

Linear Regression using Scipy

There are many approaches to perform linear regression (or least squares fit) in Python and libraries which support doing so. One approach I have come across, which I personally find advantegous, provide additional variables compared to other solutions. This post hereby intends to explain, through a simple example, how to utilize the library and the additional variables hereof.

Implementing Linear Regression

To perform linear regression, we will utilize both scipy and numpy as the two provide numerous advantages when used together. If in doubt, refer to the litterature at the end of the post to find the definition of a specific term.

Likewise, when the two libraries are combined, they additionally solve an issue when calculating the traversing line: if the slope of the line became less than zero, a calculation error occured.

The implementation, which can also be found on Github, is as follows:

Examples

Linear Regression using Scipy and Numpy with a positive slope where y = [5, 2, 2, 8, 6, 12, 14, 5, 10]

Linear Regression using Scipy and Numpy with an upwards slope where y = [5, 2, 2, 8, 6, 12, 14, 5, 10]

Linear Regression using Scipy and Numpy with a downwards slope where [15, 12, 12, 8, 9, 14, 10, 5, 9]

Linear Regression using Scipy and Numpy with a downwards slope where y = [15, 12, 12, 8, 9, 14, 10, 5, 9]

Litterature

Now, you may not be familiar with either correlation coefficients, p-valuesstandard devitiation or the sum of squared errors. Fortunately, much literature already exist in this matter:

Standard
Programming

Resolving VMWare Connectivity Issues having Upgraded to Windows 8.1

Having just upgraded to Windows 8.1, and using VMWare Player as my primary programming environment, a connectivity issue occured: my guest operating system no longer had internet access.

Resolving the VMWare Connectivity Issues

But fear not: the issue is not too difficult to solve should you already have come across it.

  1.  First, download VMWare Player
  2. Start the installation and click “Repair”
  3. Once the installation has finished, launch your guest operating system

Should you, despite all odds, still not have regained internet access for your guest operating system, try changing the connectivity settings for VMWare Player:

  1. Click “Player” in the top-left corner and go to –> “Manage” –> “Virtual Machine Settings”
  2. Then, in the “Network Adapter” settings group, “Network connection” is found in which you should change the connection to “NAT”
  3. If that still not works, try changing to “Bridged”

If that still not works, well, then I guess even I will not be of much help. Try either reinstalling or searching the forums.

Standard
Programming

Installing Python and Aptana Studio on Ubuntu 12.04

This blog post describes and illustrates, where needed, how to install Aptana Studio with Python 2.7 on Ubuntu 12.04. It will guide you through the following:

  1. Installing the prerequisites
  2. Installing Aptana Studio
  3. Installing Python 2.7
  4. Optional >> Installing Git

Before beginning, ponder upon the might of Python as described by xckd:

Learning Python

Installing Prerequisites

If you have created an image, I highly recommend installing all updates before proceeding.

1. Open the Update Manager and install all available updates

1.1. If the application is not available on your Launcher (or sidebar, if you will), simply open Dash Home and search for it here

2. Open a terminal
3. Install additional updates (copy-paste):

Having installed all of the available updates, our next step is to install Aptana Studio.

Installing Aptana Studio

I personally, in all essence, prefer Aptana Studio due to the high amount of customizability which the IDE provides. If you prefer, you can obviously install any other IDE of your choice, and proceed to installing Python. Alas, to install Aptana, follow the steps below:

1. Download Aptana from their website: http://aptana.com/products/studio3/download
2. Open a terminal
3. Navigate to Downloads (copy-paste):

4. Unzip Aptana Studio to /opt/ (copy-paste):

Note that:

  • <architecture> should be replaced with your system architecture (in my case, x86_64; i.e. 64-bit Ubuntu)
  • <version> should be replaced with the version of Aptana which you’ve downloaded (in my case, 3.4.2)

Now that you’ve extracted Aptana, your IDE is ready for use and can either be accessed by the folder itself, or by the following command:

Note that:

  • <version> should be replaced with the version of Aptana which you’ve downloaded (in my case, 3)

Install Python 2.7

Having installed our IDE, the next step is to install the Python 2.7 interpreter. Although, first some dependencies should be installed before install Python itself.

1. Open a terminal
2. Install the build essentials (copy-paste):

 3. Then, install the necessary libraries for installing Python (copy-paste):

 4. Navigate to Downloads (copy-paste):

5. Download Python 2.7 (copy-paste):

Note that:

  • If you wish to install another version of Python, simply navigate to the Python FTP site, find the version which suit your requirement, and thereafter copy the link of the tar.gz container and replace it with the one above.

6. Extract the archive (copy-paste):

7. Navigate to the extracted Python Directory:

 8. Lastly, we need to install Python which is a three step manouvre (copy-paste):

The Python Interpreter has now been installed, which you can test by entering the following in your terminal:

Congratulations! You have now compiled and installed Python 2.7 on Ubuntu 12.04.

Installing Additional Modules

At some point in the near future, you will most likely need to install additional modules. To ensure that you can do so although only requires little effort:

1. Install pip: a module for installing python modules (copy-paste):

Afterwards, whenever you wish to install a module, take for instance nltk, the basic use of pip is:

Optional >> Installing Git

If you wish to install Git, which is a popular choice for version control, the method is quite simple:

1. Open a terminal

2. Install Git (copy-paste):

 By now, Git has been installed, but you will need to add a .ssh key for verification purposes. A very simple guide, provided by Github, will explain you exactly how to do just that. At some point, you will although need to copy the contents of the key to your Github account, where a problem might occur as seen in the screenshot below:

Unable to clip contents

If you experience, this issue, simply follow the simple steps as provided in this guide:

1. Open a terminal

2. Copy the contents of the id_rsa.pub file by using gedit:

3. Now simply head over to GitHub and add your SSH key as mentioned in the guide provided by GitHub

Now you can continue following the guide provided by Github, and test that everything works out accordingly.

Discussion

Initially, I tried installing Aptana Studio 3.4.2 on a virtual machine running Ubuntu 13.10, but found that the menu in Aptana was no longer available. Trying to debug and solve the issue for several hours, even though a common answer was given on several forums, I was never able to accomodate for the problem. This meant that I personally reverted to Ubuntu 12.04, which, by now, works just fine.

References

Installing Python: http://askubuntu.com/questions/101591/how-do-i-install-python-2-7-2-on-ubuntu

Generating a SSH key: https://help.github.com/articles/generating-ssh-keys

Copying file contents: http://jetpackweb.com/blog/2009/09/23/pbcopy-in-ubuntu-command-line-clipboard/

Standard
Programming

Synchronising Google Calendar with Windows Phone 8

My main concern using a Windows Phone 8, is that Google has only promised compatibility until the end of 2013 for their services. This means, that the support will gradually be phased out, and currently, synchronisation options must be set up manually which is a hassle. Keeping those reasons in mind, this post intends to walk you through how I personally solved the issue.

It would obviously be way easier simply to switch to another provider, but I personally use nearly all the services Google provide and have been doing so for a long time.

Before Getting Started

The basic requirements to get started are as follows:

Synchronising Google Calendar with Windows Phone 8

First, you are ought to switch to a different user-agent (see the next section), which enables Chrome to behave as other user agents such as smartphones. After doing so, you simply select the calendars which you wish to synchronise; that’s it! This section will walk you through the steps in detail.

Notice that it will take some time before the calendar is actually be available on your phone.

Switching User Agents

First, click on the User-Agent Switcher in the top-most right corner of Chrome and select iOS –> iPhone as seen in Figure 1.

Switiching User Agents

Figure 1 – Switching the User-Agent to iOS

Configuring Your Synchronisation Options

After having selected a User Agent, the icon will change as seen in Figure 2:

Figure 2 - Before and After changing User Agents

Figure 2 – Before and After changing User Agents

This means, that you are now browsing as if you were using your smartphone. Now, simply browse to the following site:

https://m.google.com/sync/settings/iconfig/

You will now see the website as illustrated in Figure 3:

Figure 3 - Choosing Your Device

Figure 3 – Choosing Your Device

By now, simply select “WindowsPhone” which will redirect you to the most important part, namely synchronising your calendars (see Figure 4):

Figure 4 - Choosing Your Calendars

Figure 4 – Choosing Your Calendars

After having selected the calendars which you wish to synchronise to your Windows Phone device, simply click “Save” on the bottom of the screen. There you go! You are now synchronising your Google Calendars with your Smartphone.

As stated in the very start of the post, notice that it will take some time before the calendar is actually be available on your phone.

Enjoy!

// David

Standard