DATA 110 Quiz 1 Content

5.0(1)
Studied by 3 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/111

encourage image

There's no tags or description

Looks like no tags are added yet.

112 Terms

1
New cards

Data

Pieces of Information

2
New cards

Structured Data Types

Tables; most common type of data; usually .csv files; rows are called observations and columns are called features

3
New cards

Semi-structured Data Types

Essentially somewhat structured data with some data; examples include html and xml

4
New cards

Unstructured Data Types

Includes images, videos and audio; text is usually in bag-of-words form

5
New cards

Bag-Of-Words

when python basically counts frequency of words to process the content; doesn’t consider word order and which words actually hold value but can process large amounts of data

6
New cards

Nominal Data

categorical data; uses labels or names; can be numeric or non-numeric (always nominal)

7
New cards

Ordinal Data

same concept as categorical data but follows ranking system; can be numeric or non-numeric

8
New cards

Interval Data

quantitative data for measurement; always numeric

9
New cards

Data Quality Issues

  • missing values

  • miscoded values

  • duplicate values

  • outliers

  • invalid values

  • date/time issues


10
New cards

Personally Identifiable Information (PII)

any info that can identify a specific person, either directly or indirectly; should be protected and remain classified

11
New cards

Direct Identifiers

You can tell who it is immediately; examples include full name, SSN, driver’s license #, passport #, etc.

12
New cards

Indirect (Quasi) Identifiers

combinations of these variables may inadvertently allow you to identify someone; examples include age, birth date

13
New cards

Methods to protect information

  • remove column

  • mask values

  • random IDs

  • hash identifiers (ids turned into undecipherable values)

  • aggregate

  • generalize

  • noise

  • synthetic data


14
New cards

programming/coding

writing instructions for the computer to complete a task

15
New cards

debugging

the process of finding mistakes and fixing the instructions

16
New cards

vibe coding

a software development workflow where you rely almost entirely on AI to write and refine code while you act as a guiding visionary

17
New cards

pros of vibe coding

  • lowers the barrier to entry for those w/minimal coding knowledge

  • speeds up the application development process even for experienced coders


18
New cards

cons of vibe coding

  • lack of deep understanding

  • inconsistent/inefficient code

  • hidden security vulnerabilities


19
New cards

compilers/interpreters

computer programmers that actually do the translation

20
New cards

packages

data sci. tools; have built-in types but you can make your own

21
New cards

string method

functions associated with a particular data type

22
New cards

capitalize()

‘professor balan’ → ‘Professor Balan’

23
New cards

lower()

‘Professor Balan’ → ‘professor balan’

24
New cards

upper()

‘Professor Balan’ → ‘PROFESSOR BALAN’

25
New cards

Importing Pandas and Defining a Function


import pandas as pd 
pd.read_csv('Name'.csv)
df_name=pd.read_csv('Name'.csv)
type(df_name)
df_name


26
New cards

Displays a Subset of the table

df_name.head()
df_name.tail()
df_name.sample()



27
New cards

Displays Info about the Table (like number of columns/rows, Python Data Types, etc.)

df_name.info()
df_name.shape()
df_name.dtypes()


28
New cards

Displays Descriptive Stats

df_name.describe()


29
New cards

Selecting a Column

df_name.column
df_name.['column']


30
New cards

Frequency Distribution for Categorical Columns (Counts for ea. Column)

df_name.column_title.value_counts()


31
New cards

Aggregation on Numerical Columns (Stats for ea. Column)

df_name.column_title.min()
df_name.column_title.max()
df_name.column_title.mean()
df_name.column_title.sum()


32
New cards

Selecting/Dropping Columns

df_name.filter(['column_name','column_name_1'])
df_name.drop(columns=['column_name'])

(The functions don’t change the original file. If you want to reuse the update file, you'll need to assign it to a new name.)

#example 
uncbb_filtered=uncbb.filter(['NAME','PTS'])
#creates new file 
uncbb=uncbb.filter(['NAME','PTS'])
#changes original file 


33
New cards

Indexing

x: str='pickles'
print x[0]
print x[len(x)-1] 

allows us to identify the location of a character or group of characters w/in a string

34
New cards

Slicing

x: str='pickles'
print x[2:5]
print x[2:3:5]

allows us to access/extract a substring from a string

35
New cards

Working w/ Columns

df.filter()
df.drop()


36
New cards

Boolean Indexing

#example 
uncbb_guards=uncbb[uncbb['POS']=='G']
print(uncbb_guards)

returns a table w/only the rows for which the corresponding bool is True

  • and (&) → both conditions must be True

  • or (|) → at least one of the conditions must be True

  • not (~) → condition is NOT True


37
New cards

Group-By

getting information about one variable within the confines of another variable (ex. total number of baggage complaints per airline)

#example
df.groupby('airlines')['complaints'].sum()
#the function is determining the sum of complaints based on the airline 
df.groupby('key')['variable_to_analyze'].operation()


38
New cards

Functions for Missing Values

#pulling up the basic info about the dataset
df.info()
#calculates the total number of missing values 
df.isna().sum()
#calculates the percentage of missin values 
df.isna().sum()*100
#drops all missing values 
df.dropna()
#replaces missing values with smth else lik mean or mode or unknown for categorical data
df.fillna()

(Could use filter function but most ideal for smaller data sets)

39
New cards

Pythons Tools for Data Viz

Matplotlib, Seaborn, Altair

40
New cards

Matplotlib

like a car engine for making graphs and charts

import matplotlib.pyplot as plt 


41
New cards

Seaborn

the dashboard that Matplotlib has under the hood

import seaborn as sns 


42
New cards

Function of Data Viz

  • depends on whether data is categorical (nominal/ordinal) and numerical (interval)

  • should convey the most amount of information in the smallest amount of time with the least amount of ink and space


43
New cards

Frequency Distributions

used to summarize categorical variables; lists unique values of the variable w/ their frequency (value_counts)

#example 
lot_count = df['LotConfig'].value_counts()
print(lot_count)


44
New cards

Bar Charts

#example
plt.figure()
sns.barplot(x=lot_count.index, y=lot_count.values)
plt.ylabel('Number of Homes')
plt.xlabel('Lot Configuration')
plt.xticks(rotation=20)
plt.title('Distribution of Lot Configuration')
plt.show()


45
New cards

Distributions of Single Categorical Variable

Bar Charts and Pie Charts

46
New cards

Distributions of Single Numeric Variable

  • can be represented by histograms and box plots

  • can be described as center, spread, location and skewness (the shape of the data)


47
New cards

Histograms

  • data values are places into distinct, inclusive, equivalent bins

  • seaborn chooses bin width based on range of data displayed

  • height of the bar represents the # of observations in the bin

#example
plt.figure()
sns.histplot(data=df, x='Sales Price')
plt.title('Distributions of Sales Price')
plt.xlabel('Sales Price ($)')
plt.ylabel('Frequency')
plt.show()


48
New cards

Boxplots

  • good for representing 5-Number Summary (Min, Q1, Med, Q2, Max)

  • Visualizes IQR of data and the spread

plt.figure()
sns.boxplots(data=df, y='SalesPrice")
plt.title("Distributions of Sales Price")
plt.ylabel('Sales Price ($)')
plt.show()


49
New cards

Displaying Relationships

  • For Categorical vs. Numeric Data → Comparative Boxplots

  • For Numeric vs. Numeric → Scatterplots

  • For Categorical vs. Categorical → Heatmaps


50
New cards

Comparative Boxplots

#example
plt.figure()
sns.boxplot(data=df, x='LotConfig', y='SalePrice')
plt.title('Distribution of Sales Price by Lot Configuration')
plt.xlabel("Lot Configuration")
plt.ylabel("Sales Price ($)")
plt.show()


51
New cards

Scatterplots

#example
plt.figure()
sns.scatterplot(data=df, x='Lot Area', y='SalesPrice')
plt.title('Lot Size vs. Sale Price')
plt.xlabel('Lot Size in Sq. Ft.')
plt.ylabel('Sale Price ($)')
plt.show()


52
New cards

Heatmaps

  • assigns colors to values and cells are painted w/such

  • visually displays patterns, gradients, and outliers

#example method 1
ct=pd.crosstab(df["BldgType"],df["CentralAir"])

plt.figure()
sns.heatmap(ct,annot=True,fmt="d",cmap="Blues")
plt.title("Heatmap of Building vs Central Air")
plt.xlabel("Central Air")
plt.ylabel('Building Type')
plt.show()

#example method 2 

ct_percent=pd.crosstab(df["BldgType'], df["CentralAir"], normalize="index")*100

sns.heatmap(ct_precent, annot=true, fmt="0.1f", cmap="Blues")
plt.title("Heatmap of Bulding Type vs. Central Air")
plt.xlabel("Central Air")
plt.ylabel("Building Type")
plt.show()


53
New cards

Crosstabulation

  • basically indicating overlap

  • rows=categories of variable A

  • columns=categories of variable B

  • cell value= count/percentage of observations w/that combo of both variables A and B

  • cell color= the value mapped onto the color scale


54
New cards

Population

All items of interest

  • Frequently very large; sometimes infinite

  • Described by parameters


55
New cards

Sample

A set of data drawn from the population

  • Potentially very large but less than the population

  • Described by statistics


56
New cards

Statistical Inference

Process of making an estimate, prediction or decision about a population based on a sample

57
New cards

Sampling

Process of selecting a subset of units from a population

58
New cards

Representative Sample

A selection that reflects the characteristics of the population

59
New cards

Sampling is important for both…

data collection and analysis!

60
New cards

Non-probabilistic Sampling

When the selection process is not fully random

  • (Ex.) Twitter Poll


61
New cards

Probabilistic Sampling

When the selection process is truly random

  • (Ex.) Gallup poll


62
New cards

Methods of Non-Probabilistic Sampling

  • Convenience Sampling

  • Volunteer Sampling

  • Judgmental Sampling


63
New cards

Sampling Bias

When some participants/samples are more likely to be chosen over others

64
New cards

Types of Sampling Bias

  • Undercoverage/Exclusion Bias

  • Self-selection/Voluntary response Bias

  • Non-response/Participation Bias

  • Survivorship Bias


65
New cards

Methods of Probabilistic Sampling

  • Simple Random Sampling

  • Stratified Random Sampling


66
New cards

Arguments FOR Sampling

  • Resource Constraints

  • Diminishing Returns

  • Faster Iteration and Prototyping

  • Algorithm Scaling Constraints

  • Spurious Correlation


67
New cards

Arguments AGAINST Sampling

  • Lost signal/bias risk

  • Selection bias

  • Overconfidence/false precision

  • Artifacts of data heterogeneity (full data might reveal patterns/whatnot unseen by sample)


68
New cards

Statistical Inference Process

  1. Population determined with a mean mew

  2. A simple random sample of n elements is selected from the population

  3. The sample data provide a value for the sample mean x-bar

  4. The value of x-bar is used to make inferences about the value of mew


69
New cards

Sampling Distribution

The distribution of the sample statistic

70
New cards

Sampling Error

Error resulting from using a sample statistic to estimate a popultion parameter

71
New cards

Sampling Distribution of the Mean (X-bar)

  • The distribution of the means for samples of the same sample size and variable

  • As the sample sizes increase, the closer they are to the population mean and the lower the sampling error

  • Standard Deviation= (Stan. Dev. of X) / (Sq. Root of Sample Size)


72
New cards

Central Limit Theorem


If X is a normally distributed, random variable →

Sample Mean = Pop. Mean

Sample Stan. Dev. = (Pop. Stan. Dev.) / (Sq. Root of Sample Size)


73
New cards

Hypothesis Testing

An inference used to make decisions/judgements about the value of a parameter based on a statistic

74
New cards

Null Hypothesis (Ho)

What we currently believe to be true

  • Historically accepted/most recent values

  • Status Quo


75
New cards

Alternative Hypothesis (Ha)

What we’re trying to evaluate based on the sample data

  • Whether or not the data shows a certain thing?

  • Challenges the null hypothesis


76
New cards

Hypothesis Testing Process

  • State the null and alternative hypotheses

  • Define a test statistic

  • Compute the value of the test statistic

  • Assess the evidence (using p-values)

  • State your conclusion (in non-technical terms)


77
New cards

P-Value

Probability of obtaining a value more extreme than the value of the test statistic (where “more extreme” is determined by the form of the alternative hypothesis)

  • Establish a significance level a

  • Reject the null hypothesis if the p-value is less that a

  • Fail to reject the null hypothesis if the p-value is greater than a


78
New cards

Finding p-value with Python

# Perform a one-sample t-test 
#The null hypothesis is that the mean is equal to 90000
#The alternative hypothesis is that the mean is less than 90000
t-statistic, p-value = ttest_1samp(df_admin['Salary'}, popmean=90000, alternative='less')
#Report the p-value 
print(f"The p-value for the one-sample t-test is: {p_value:.4f}")


79
New cards

A/B Testing

  • Two-Sample Hypothesis Tests

  • Evidence-based/Data-Driven decision making

  • Reduces risk

  • Continuous improvement

  • Measures real user behavior


80
New cards

How does A/B Testing work?

  • A/B testing is comparing two scenarios:

    • Option A (often a control version)

    • Option B (alternative version)

  • Two separate samples of subjects are selected

  • One sample gets Option A and the other gets Option B

  • Outcome of interest is measure for each group


81
New cards

The function of A/B testing….

to understand if the observable differences between two groups is really significant and just due to random chance.

  • Ho: no diff. in outcome between the groups

  • Ha: diff. in outcome between the groups


82
New cards

Artificial Intelligence (AI)

Applies logic and analysis to interpret, support, and automate resulting decisions and actions

83
New cards

Generative AI

Creates new content by learning from patterns in data

84
New cards

Predictive AI

Systems based on machine learning models made for specific tasks based on structured data

  • Designed to leverage historical data to perform specific prediction tasks efficiently

  • Uses supervised and unsupervised machine learning algorithms

  • Relies primarily on structured data


85
New cards

Supervised MLM

Trained on historical data that includes a known (or labelled) outcomes

86
New cards

Classification (A part of Supervised MLM)

Outcomes are binary or categorical

87
New cards

Regression (A part of Supervised MLM)

Outcomes are numeric

88
New cards

Unsupervised MLM

Trained on historical data that does NOT include known (or labelled) outcomes

89
New cards

Reinforcement (A part of Unsupervised MLM)

System learns by trial and error, receiving feedback, and adjusting its actions to maximize success

90
New cards

The goal of supervised learning…

Estimating a function f(x)

91
New cards

Prediction Error

f(x) - f_hat(x)

92
New cards

Components of Error

  • Bias Error

  • Variance Error

  • Irreducible (Random) Error


93
New cards

Total Error Equation

Bias² + Variance + Irreducible Error

94
New cards

Bias

When an algorithm is hindered from learning the true signal from a dataset; may result in underfitting

95
New cards

Low Bias Model

  • Fewer assumptions about the functional form of the model

  • (Ex.) classification trees, support vector machines, k-nearest neighbor


96
New cards

High Bias Model

  • More assumptions about the functional form of the model

  • (Ex.) linear regression, logistic regression


97
New cards

Variance

Refers to an algorithm’s sensitivity to a specific set of data; may result in overfitting

98
New cards

Low Variance

  • Small changes to the fitted model when the training set changes

  • (Ex.) Linear regression, logistic regression


99
New cards

High Variance

  • Large changes to the fitted model when the training set changes

  • (Ex.) Classification Trees, Support Vector Machines, K-Nearest Neighbor


100
New cards

Overfitting

The model being too complex