{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Hands on Machine Learning for Materials Science\n", "\n", "This hands on is put together by Researchers on Project 20 of [Cine](http://cine.org.br/) \n", "\n", "The ideal participant is anyone who is interested in Machine Learning for Meterials Science research. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1+1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# The Anaconda Distribution of Python\n", "\n", "For this hands on, we recommend to install the Anaconda distribution of Python. The following section details the differences between the Anaconda distribution of Python and the version of Python you can download from Python.org\n", "\n", "## How is Anaconda different from Python?\n", "\n", "When you download Python from Python.org, you get the Python Interpreter, a little text editing program called IDLE and all of the Python Standard Library modules.\n", "\n", "The Python Interpreter is an application or program that runs your Python code. A program written in the Python programming language is run with the Python Interpreter. So Python corresponds to both the language that a program is written in as well as the application that runs the program.\n", "\n", "When you download the Anaconda distribution of Python from Anaconda.com, you get a Python Interpreter, the Anaconda Prompt (a command line program), Spyder (a code editor) and about 600 extra Python modules that aren't included in the Python Standard Library. The Anaconda distribution of Python also includes a program called Anaconda Navigator that allows you to launch Jupyter notebooks quickly.\n", "\n", "## Why download Anaconda, if I want to use is Python?\n", "\n", "Regardless if you download Python from Python.org or if you download Anaconda (with all the extra stuff it comes with) from Anaconda.com, you will be able to write and execute Python code. However, there are a couple of advantages to using the Anaconda distribution of Python.\n", "Anaconda includes Python plus about 600 additional Python packages\n", "\n", "The Anaconda distribution of Python is advantageous because it includes Python as well as about 600 additional Python packages. These additional packages are all free to install. The packages that come with Anaconda includes many of the most common Python packages use to solve problems. If you download Anaconda, you get Python including the Python Standard Library plus about 600 extra packages. If you download Python from Python.org, you just get Python and The Standard Library but no additional modules. You could install the extra modules that come with Anaconda (that don't come with plain old Python), but why not save a step (or about 600 steps) and just install Anaconda instead of installing about 600 different modules?\n", "Anaconda installs without administrator privileges\n", "\n", "Even if you don't have the ability to install programs on a computer, like a computer in a school computer lab, you can still download and use Anaconda. The Anaconda distribution of Python will also allow you to install additional modules from the Python package index (PyPI.org) and conda-forge (conda-forge.org), the conda package index.\n", "\n", "### Anaconda works on Many OS\n", "\n", "If you use MacOS/Linux, you probably already have Python installed on your computer. Most MacOS/Linux installations come with Python included. The problem is that the version of Python that comes with MacOS/Linux is old (usually legacy Python, Python 2) and the version of Python that comes with MacOS/Linux is locked up behind a set of administrator privileges. Because the pre-installed version of Python included with MacOS/Linux can require administrator privileges, you can have trouble with installation and run-time problems. Some things will seem to work fine, and then other things won't run at all, or you will keep getting asked for an administrator password over and over.\n", "\n", "Downloading and installing Anaconda (separate from the version of Python that came with MacOS/Linux) prevents most of the problems on MacOS/Linux caused by using the pre-installed version of Python.\n", "\n", "Windows users also benefit from Anaconda, as you don't have to configure \n", "\n", "### Anaconda makes package management and virtual environments easier\n", "\n", "Another advantage of Anaconda is that package management and virtual environments are a lot easier when you have Anaconda. Virtual environments and package handling might not seem to make a huge difference right now. If you just downloaded Anaconda for the first time, you are probably not dealing with package management and virtual environments yet. (It's OK if you don't even know what those two things are yet). After you write a couple of Python programs and start downloading a couple of extra modules from PyPI or conda-forge, dealing with package management and virtual environments becomes more critical." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction to Python\n", "\n", "## Why Python\n", "\n", "\n", "\n", "[Python](https://python.org/) is a general-purpose and popular programming language that is relatively easy to use and learn. It is a great choice as a first programming language. In fact, more and more university computer science departments over the world are centering their introductory courses around Python. Furthermore, it has several third party libraries that extends the language core with many new funcionalities, many of them for scientific computation.\n", "\n", "\n", "These page on [English](https://greenteapress.com/wp/think-python/) and [Portuguese](https://panda.ime.usp.br/pensepy/static/pensepy/) provide some more great reasons to use Python, along with resources for getting started and self learning material. A more technical tutorial can be found [here](https://docs.python.org/2/tutorial/index.html)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Jupyter Basics\n", "\n", "You are looking at a Jupyter Notebook, an interactive Python shell inside of a web browser. With it, you can run individual Python commands and immediately view their output. It's basically like the Matlab Desktop or Mathematica Notebook but for Python.\n", "\n", "### Starting Jupiter Notebooks\n", "\n", "1. Start the [Jupyter notebook](https://jupyter.org/) server on your local machine. For Mac/Linux users, at the Terminal:\n", "\n", " your-local-machine:~$ jupyter notebook\n", "\n", " For Windows users, open the application \"Jupyter Notebook\". Alternatively for Windows: open the application \"Anaconda Prompt\" and type in `jupyter notebook`.\n", "\n", " Jupyter should automatically open a new window in your web browser that resembles a directory tree.\n", "\n", "2. To open a new notebook, in the new window of your web browser, click on *New* near the top right to open a new notebook.\n", "\n", " - To rename the notebook, click on \"Untitled\" in the top left, and choose a different name.\n", " - Inside a cell, run `1+2`. Press `` on a cell to run that cell. Hopefully you get the output `3`.\n", " - Inside a cell, run `import scipy, sklearn, pandas`. Press `` to run the cell. If that runs without error, congratulations, you have the necessary libraries installed properly.\n", " - Try executing the content from inside this blank notebook.\n", "\n", "3. To close the Jupyter notebook,\n", "\n", " - Save the notebook. (Either use keyboard shortcut `s`, or \"File | Save\" in the top menu.)\n", " - Close the browser window.\n", " - If you opened the notebook from a prompt/shell as indicated in Step 1 above, from that shell, press `` twice to return to the prompt.\n", "\n", "Congratulations, you are now running a Jupyter notebook, and you can get started with the notebooks in this repository.\n", "\n", "After installing, if something doesn’t work, try closing the terminal or restarting the OS. Sometimes that can reset the necessary configurations." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Mixing text and code\n", "\n", "It is likely that you will want to enter actual text (non-code) in the notebook. To do this, click on a cell, and in the drop-down menu in the toolbar, select 'Markdown'. This is a specific type of syntax for writing text. You can just write text normally and press shift-enter to *render* it:\n", "\n", " This is some plain text\n", "\n", "To edit it, double click on the cell. You can also enter section headings using the following syntax:\n", "\n", " This is a title\n", " ===============\n", "\n", " This is a sub-title\n", " -------------------\n", "\n", "which will look like:\n", "\n", "This is a title\n", "===============\n", "\n", "This is a sub-title\n", "-------------------\n", "\n", "Finally, if you are familiar with LaTeX, you can enter equations using:\n", "\n", " $$E = m c^2$$\n", "\n", "on a separate line, or:\n", "\n", " The equation $p=h/\\lambda$ is very important\n", "\n", "to include it in a sentence. This will look like:\n", "\n", "$$E = m c^2$$\n", " \n", "The equation $p=h/\\lambda$ is very important\n", "\n", "For more information about using LaTeX for equations, see [this guide](http://en.wikibooks.org/wiki/LaTeX/Mathematics)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.4" } }, "nbformat": 4, "nbformat_minor": 4 }