Data Science Get Started

Getting started means installing NumPy, Pandas, Matplotlib, and scikit-learn, then wiring them together in one short script that goes from raw numbers to a plotted prediction.

Setting Up Your Environment

Install the core stack with a single pip command, ideally inside a virtual environment so versions don't clash with other projects: pip install numpy pandas matplotlib scikit-learn scipy.

Example

import numpy
import pandas
import matplotlib
import sklearn

print("numpy:", numpy.__version__)
print("pandas:", pandas.__version__)
print("matplotlib:", matplotlib.__version__)
print("scikit-learn:", sklearn.__version__)
  • numpy gives you the ndarray, the fast fixed-type array almost everything else is built on.
  • pandas gives you the DataFrame, a labeled table for loading and cleaning data.
  • matplotlib.pyplot gives you plotting functions like scatter and hist.
  • sklearn gives you ready-made model classes like LinearRegression with a fit/predict interface.

Your First End-to-End Script

A minimal data science script touches every stage of the pipeline at once: it holds data in arrays, computes a summary statistic, fits a simple model, and plots the result.

Example

import numpy as np
import matplotlib.pyplot as plt
from scipy import stats

# a tiny "dataset": hours studied and exam score
hours = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
scores = np.array([50, 55, 65, 70, 63, 72, 80, 84, 90, 95])

print("average score:", np.mean(scores))

slope, intercept, r, p, std_err = stats.linregress(hours, scores)
print("best-fit line: score =", round(slope, 2), "* hours +", round(intercept, 2))

plt.scatter(hours, scores)
plt.plot(hours, slope * hours + intercept)
plt.xlabel("Hours studied")
plt.ylabel("Exam score")
plt.show()
Note: Later chapters break each of these steps down individually - this script only shows how the pieces click together before you dig into any one of them.

How This Tutorial Is Organized

The chapters ahead move from describing a single column of numbers (distributions), to comparing two columns (scatter plots), to fitting lines and curves that predict one column from another (linear, polynomial, and multiple regression).

Note: Run each example in your own editor or notebook rather than just reading it - seeing the plot appear is what makes the statistics click.

By the end, you'll be able to take a raw pair of columns and decide, with evidence rather than a guess, whether one predicts the other.

Exercise: Data Science Get Started

Which Python library is primarily used for handling and analyzing tabular data?