## Saturday, June 24, 2017

### Machine learning 12: Machine learning using scikit-learn (Workshop materials)

I am teaching a workshop on machine learning using scikit-learn at 2017 CDIPS Data Science Workshop, UC Berkeley. It covers the general idea of machine learning and a brief tour of different types of learning (regression, classification, clustering, dimensionality reduction) with examples written in scikit-learn. It is a 2-hour workshop, and you can find all the materials on Qingkai's Github.

## Monday, June 19, 2017

### My son is here for Father's day

Last weekend on June 17th, my son was born, just in time for the Father's day. He is 8 pounds 9 ounces (much heavier than my daughter was born).

My son looks like a thinker in the future.

class newBaby:
def __init__(self, name, weight):
self.name = name
self.weight = weight

def sayHello(self):
print('Hello world, I am %s'%self.name)

def showWeight(self):
print('I am %.1f pounds'%self.weight)

baby2 = newBaby('Fanqi', 9)
baby2.sayHello()
baby2.showWeight()
Hello world, I am Fanqi
I am 9.0 pounds

## Saturday, June 10, 2017

### Python: Using virtual environments

Many times, we find ourselves need to use some of the python packages that we don't want to install in our system or certain version. For example, with pandas updated to version 0.20.2, but you find out you have some old codes depend on the version 0.19.2. In this situation, using a virtual environment to manage it will be really handy. Or you find some cool python packages online, but they require Python 3 instead of 2. This week, I will write here what I usually do in these situations.

## Using Virtualenv

I usually use virtualenv to create an environment that isolated from my main python environment. As we mentioned in one situation, I have pandas version 0.20.2 installed in my python environment, but I want to use pandas version 0.19.2 in some of my old scripts.
# if you don't have virtualenv, you need to install it first
$pip install virtualenv # enter into your project folder$ cd path_to_old_project/
# create the virtual environment
$virtualenv venv # activate the virtual environment$ source venv/bin/activate

# after the activation, we should see a (venv) at the beginning of
# the terminal prompt indicating that we are working inside the
# virtual environment now.

# install the old package I need, i.e. pandas 0.19.2
$pip install pandas==0.19.2 When I work in my virtual environment, I usually add venv to my project's .gitignore file in case I accidentally commit all the virtual environment. After working in the virtual environment, to leave it:$ deactivate

## Using Python 3 to create virtual environment

If you are using Python 3, things will be easier, since you can create the virtual environment directly, for example: python3 -m venv /path/to/new/virtual/environment
$python3 -m venv venv$ source venv/bin/activate

## Managing Python 2 and 3 on MAC using conda

Sometimes, we want to have both Python 2 and 3 on our machine. Since I am using conda as the package manager, I also use it to manage different environments. On default, I am using Python 2.7, and I usually create and activate Python 3 environment this way:
# create an environment that have Python 3 installed
$conda create -n py3 python=3 # start the Python 3 environment$ source activate py3
# You can use the following to check different environment
$conda info -e ## Create Python 3 environment using Virtualenv The other way is to use Virtualenv to create a Python 3 environment.$ virtualenv -p python3 env
\$ source ./env/bin/activate

## Saturday, June 3, 2017

### Guitar: Happy birthday to you

My daughter and I were singing together for her birthday. It was fun, and now she really like to sing with me whenever I play guitar. I hope one day, she will play and I sing along, not long ^)^