# A first function. Find the length of a list.
a_list = [1, 2, 3]
len(a_list)

len({"a": [1, 2, 3], "b": 4})

"""
Explanation: Functions
Overview

Data basics
Theory of types
Basic types
Composite types: Tuples, lists and dictionaries
Functions
range() function
read and write files
Flow control, part 1
If
for

Function Basics

A function has 0 or more inputs and returns 0 or more outputs.
A python function is called (executed) by placing "(", ")" after the function name with the list of arguments.
End of explanation
"""


range(3)

"""
Explanation: Builtin Functions
Functions that are supplied in the python base.
len()
Takes an object as input and returns an integer.
range()
Takes an integer as input and outputs a list of successive integers starting with 0 to the length specified as an argument.
End of explanation
"""


# Experiment with the builtin function all
all([1, "first", 3.4])

any([False, False])

list(range(3))

fd = open("t.txt", "w")

fd.write("a line")

fd.close()

!ls -l

help(fd)

"""
Explanation: Notice that Python (in the newest versions, e.g. 3+) has an object type that is a range.  This saves memory and speeds up calculations vs. an explicit representation of a range as a list - but it can be automagically converted to a list on the fly by Python.  To show the contents as a list we can use the type case like with the tuple above.
Sometimes, in older Python docs, you will see xrange.  This used the range object back in Python 2 and range returned an actual list.  Beware of this!
End of explanation
"""


data = [1, 2, 3, 4]

import numpy as np
np.mean(data)

np.median(data)

arr = np.array(data)
arr

np.reshape(arr, (2,2))

np.std(data)

"""
Explanation: Packages with functions

A package is a collection of reusable python codes.
To get access to a package you must:
Install the package (e.g., using pip)
Your code must import the package, which then becomes a python object.

numpy
Package of codes for numerical processing in python.
End of explanation
"""


from pandas import read_csv
from pandas.plotting import scatter_matrix
from matplotlib import pyplot
from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import StratifiedKFold
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import SVC

"""
Explanation: How do you find out what's in a package?
Python's Data Science Ecosystem
In addition to Python's built-in modules like the math module we explored above, there are also many often-used third-party modules that are core tools for doing data science with Python. Some of the most important ones are:
numpy: Numerical Python
Numpy is short for "Numerical Python", and contains tools for efficient manipulation of arrays of data. If you have used other computational tools like IDL or MatLab, Numpy should feel very familiar.
scipy: Scientific Python
Scipy is short for "Scientific Python", and contains a wide range of functionality for accomplishing common scientific tasks, such as optimization/minimization, numerical integration, interpolation, and much more. We will not look closely at Scipy today, but we will use its functionality later in the course.
pandas: Labeled Data Manipulation in Python
Pandas is short for "Panel Data", and contains tools for doing more advanced manipulation of labeled data in Python, in particular with a columnar data structure called a Data Frame. If you've used the R statistical language (and in particular the so-called "Hadley Stack"), much of the functionality in Pandas should feel very familiar.
matplotlib: Visualization in Python
Matplotlib started out as a Matlab plotting clone in Python, and has grown from there in the 15 years since its creation. It is the most popular data visualization tool currently in the Python data world (though other recent packages are starting to encroach on its monopoly).
Machine Learning Exploration
End of explanation
"""


