Getting started with a basic development environment for Python machine learning on Ubuntu can be a quick process. This short tutorial will cover the installation of the SciPY, Scikit-Learn, and Tensorflow libraries.
On Ubuntu 16.04, current steps to install Tensorflow and SciPy include:
sudo apt-get install python-pip python-dev
sudo -H pip3 install --upgrade pip
sudo -H pip3 install --upgrade scipy tensorflow theano scikit-learn algopy pandas
Then perform basic validation of your scipy install by displaying a basic Matlib plot:
""" Compute the maximum of a Bessel function and plot it. """
parser = argparse.ArgumentParser(usage=__doc__)
parser.add_argument("--order", type=int, default=3, help="order of Bessel function")
args = parser.parse_args()
f = lambda x: -special.jv(args.order, x)
sol = optimize.minimize(f, 1.0)
x = np.linspace(0, 10, 5000)
plt.plot(x, special.jv(args.order, x), '-', sol.x, -sol.fun, 'o')
plt.show() # Displays the image in matplotlib window
To ensure sklearn is installed, here’s another basic validation:
""" Classification using support-vector machine. """
iris = datasets.load_iris()
digits = datasets.load_digits()
print(digits.data)
clf = svm.SVC(gamma=0.001, C=100.)
clf.fit(digits.data[:-1], digits.target[:-1])
prediction = clf.predict(digits.data[-1:])
print(prediction)
The output of this predictor is the next digit in the series. For more on scikit-learn, see this tutorial.
To verify basic functionality in Tensorflow, here’s a [simple test program]((https://github.com/guydavis/python-ml-hello-world/blob/master/tensorflow_hello_world.py):
""" Tests basic functioning of Tensorflow module. """
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
With these useful ML tools installed, the next step is to complete many of the useful tutorials available for each.