Loading the lesson...
In the print dialog, choose "Save as PDF" as the destination.
Fundamentals of Machine Learning, then hands-on NumPy, Pandas and Matplotlib
Fundamentals of ML
Linear & Logistic Regression
K-Nearest Neighbours
Model Evaluation & Selection
Support Vector Machines
Decision Trees, Naive Bayes, Neural Networks
Types of ML Problems
Supervised Learning
Unsupervised Learning
Reinforcement / Semi-Supervised
NumPy, Pandas, Matplotlib720+ open-source packages as a free environment/package managerimport module_name (for example math, random, os, datetime, csv).Numpy, Pandas, Matplotlib).import numpy as np # fundamental n-dimensional arrays
import pandas as pd # DataFrame: tabular data manipulation
import matplotlib.pyplot as plt # visualization
import scipy as sp # scientific computing, sparse matrices
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifierarr = np.array([0, 1, 2, 3, 4])
np.arange(0, 10) # array([0, 1, ..., 9])
np.arange(0, 10, 3) # array([0, 3, 6, 9])
np.zeros((5, 5)) # 5x5 array of 0.
np.ones((2, 4)) # 2x4 array of 1.
np.random.randint(0, 100, (3, 3)) # random 3x3 int array
np.linspace(0, 10, 6) # 6 evenly spaced values from 0 to 10arr2.max() # 95
arr2.min() # 9
arr2.mean() # 60.8
arr2.argmin() # index of the minimum
arr2.argmax() # index of the maximum
arr2.reshape(2, 5) # reshape a flat array into 2x5
mat = np.arange(0, 100).reshape(10, 10)
mat[row, col] # single element
mat[:, 0] # entire first column
mat[0:3, 0:3] # top-left 3x3 slicepandas.Seriespandas.DataFramestep_counts = pd.Series(step_data, name='steps')
step_counts.index = pd.date_range('20240329', periods=6)
print(step_counts['2024-04-01']) # access by label, like a dict
print(step_counts[3]) # access by position, like an array
activity_df = pd.DataFrame(joined_data,
index=pd.date_range('20240329', periods=6),
columns=['Walking', 'Cycling']).loc.ilocdata = pd.read_csv('Iris_Data.csv')
data.head() # first 5 rows
print(data.loc[2, ['sepal_length']]) # row labeled 2, one column
print(data.iloc[:5, :]) # first 5 rows, all columns
print(data.iloc[:, 0]) # first column, all rows# Filter rows with a boolean condition
print(data.loc[(data.sepal_width > 3.5)])
# Derive a new column from existing ones
data['sepal_area'] = data.sepal_length * data.sepal_width
# Count rows per category
group_sizes = data.groupby('species').size()SEM)print(data.petal_length.mean())
print(data.petal_length.median())
print(data.petal_length.std())
print(data.petal_length.var())
print(data.petal_length.sem())ax = plt.axes()
ax.hist(data.petal_length, bins=25)
ax.set(xlabel='Petal Length (cm)', ylabel='Frequency',
title='Distribution of Petal Lengths')
plt.plot(data.sepal_length, data.sepal_width, marker='o')
plt.title("Distribution of Petal Lengths")
plt.xlabel("Petal Length (cm)")
plt.ylabel("sepal_width")NumPy, Pandas, Matplotlib, scikit-learn, SciPy) make it the standard ML languageNumPy provides fast n-dimensional arrays with creation, reshaping, and indexing/slicing operationsPandas Series/DataFrame give labeled, spreadsheet-like data with .loc (label-based) and .iloc (position-based) selection, filtering, and groupingMatplotlib turns DataFrame columns into histograms and plots for quick visual explorationMahmoud Abas|ML Week01 Lab