Exploratory Data Analysis
- 52Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
Why are the os and pandas libraries used when preparing data in Spyder?
52 questions
- 1
Why are the
osandpandaslibraries used when preparing data in Spyder?Model answer
oscan change the working directory, whilepandasprovides tools for reading and working with data frames.Explanation
The working directory determines where files are accessed, and data read into Spyder can be handled as a pandas data frame.
- 2
What does
os.chdirdo, and what information does it need?Model answer
os.chdirchanges the working directory and needs the path to the directory to use.Explanation
Setting the working directory identifies the location from which the data file will be accessed.
- 3
How is a CSV file such as
Toyota.csvread into a pandas data frame, and what does settingindex_col=0do?Model answer
Use
pandas.read_csv; settingindex_col=0uses the first column as the data frame’s index.Explanation
The lecture reads the Toyota car data from a CSV file and assigns its first column as the index.
- 4
Why can question marks in the Toyota data be treated as missing values when the CSV is read?
Model answer
The question marks do not convey meaningful data, so they can be interpreted as missing values and converted to NaN.
Explanation
Representing them as NaN allows Python’s missing-value functions to be used rather than requiring special handling of question-mark strings.
- 5
How can a copy of a data frame protect the original data during analysis?
Model answer
Create a separate data frame using
.copy()and perform modifications on that copy.Explanation
The original remains available for comparison or verification while operations are performed on the new data frame.
- 6
Why might missing values be excluded from a frequency or two-way table?
Model answer
Excluding them ensures the table’s counts are based only on records with the required observed values.
Explanation
For a two-way table, a record must have observed values for both variables to contribute to a joint count.
- 7
What is a frequency table, and what kind of analysis can it support?
Model answer
A frequency table gives the count for each category of a categorical variable and supports univariate analysis of that variable.
Explanation
It shows how often each category occurs, providing a basic summary of one categorical variable.
- 8
What does
pandas.crosstabdo by default when given one categorical variable?Model answer
It produces a frequency table showing the count for each category of the variable.
Explanation
The lecture uses
pd.crosstabwith the variable supplied as the index to obtain category counts. - 9
How does a two-way table differ from a one-variable frequency table?
Model answer
A two-way table shows the frequency distribution for combinations of categories from two categorical variables.
Explanation
It can be used to examine the relationship between two categorical variables rather than summarize only one.
- 10
In the Toyota example, what do the values 0 and 1 in the
Automaticvariable represent?Model answer
Zero represents a manual gearbox, and one represents an automatic gearbox.
Explanation
The numerical codes indicate the two gearbox categories in the data.
- 11
How should a two-way table be arranged to show gearbox frequencies by fuel type?
Model answer
Place
Automaticas the index (rows) andFuel Typeas the columns.Explanation
This arrangement makes each row a gearbox category and each column a fuel-type category.
- 12
Why must a record have observed values for both variables to contribute to a two-way frequency table?
Model answer
Without both values, the record cannot be assigned to a specific combination of categories.
Explanation
A missing gearbox or fuel-type value prevents the record from contributing to a joint category count.
- 13
After missing fuel-type values are excluded, how many Toyota records remain, and how many were removed?
Model answer
There are 1,336 records remaining, meaning 100 of the original 1,436 records were removed.
Explanation
The difference between the original row count and the complete fuel-type row count is 100.
- 14
What are the fuel-type counts in the Toyota data after missing values are excluded, and which category is most common?
Model answer
The counts are 15 CNG, 144 diesel, and 1,177 petrol; petrol is the most common.
Explanation
The frequency table shows that petrol accounts for the largest number of the observed fuel-type records.
- 15
What relationship between gearbox and fuel type is evident in the Toyota two-way table?
Model answer
The table shows no automatic cars with CNG or diesel; the observed automatic cars have petrol fuel type.
Explanation
The automatic-gearbox row has zero counts for CNG and diesel and a count for petrol.
- 16
What is joint probability, and how can a two-way frequency table be converted to joint probabilities?
Model answer
Joint probability is the probability that two events occur together; normalize the two-way table to convert its counts to proportions.
Explanation
In
pd.crosstab, settingnormalize=Trueexpresses each cell as a proportion of the total table. - 17
In the Toyota example, how should the joint probability of a manual-gearbox CNG car be interpreted?
Model answer
It is the proportion of all included records that have both a manual gearbox and CNG fuel type; the example gives a value of 0.01.
Explanation
A joint-probability cell represents the simultaneous occurrence of the row and column categories.
- 18
What does the joint probability value 0.82 represent in the Toyota example?
Model answer
It represents the proportion of included records that have both a manual gearbox and petrol fuel type.
Explanation
The value belongs to the intersection of the manual-gearbox row and petrol-fuel column.
- 19
What is a marginal probability?
Model answer
It is the probability of one event or category without conditioning on a particular category of the other variable.
Explanation
A marginal probability summarizes one variable across all categories of the other variable.
- 20
How can marginal probabilities be displayed in a normalized two-way table?
Model answer
Set
normalize=Trueandmargins=True; the resulting row and column totals give the marginal probabilities.Explanation
The margins option adds totals, which appear as marginal probabilities when the table is normalized.
- 21
How should a marginal probability of 0.946895 for manual gearbox be interpreted in the Toyota example?
Model answer
It indicates that about 0.946895 of the included cars have a manual gearbox, across all fuel types.
Explanation
The row total combines the manual-gearbox counts over CNG, diesel, and petrol.
- 22
How should the marginal probability 0.88 for petrol be interpreted in the Toyota example?
Model answer
It indicates that about 0.88 of the included cars have petrol fuel, across both gearbox types.
Explanation
The column total combines petrol cars with manual and automatic gearboxes.
- 23
What should the sum of all probabilities in a normalized two-way table be?
Model answer
The total probability should be 1.
Explanation
The cells collectively account for all included outcomes in the table.
- 24
What is conditional probability?
Model answer
It is the probability of an event given that another event has already occurred.
Explanation
The condition specifies the subset of outcomes within which the probability is calculated.
- 25
How does normalizing a two-way table by its rows produce conditional probabilities?
Model answer
Setting
normalize='index'makes each row sum to 1, giving the distribution of column categories conditional on each row category.Explanation
Each row is interpreted as the condition, and its cells give probabilities within that row.
- 26
Given a manual gearbox in the Toyota example, what do the conditional probabilities 0.01 for CNG and 0.11 for diesel mean?
Model answer
Among cars with a manual gearbox, the probabilities of CNG and diesel fuel are 0.01 and 0.11, respectively.
Explanation
These are row-normalized probabilities conditioned on the gearbox being manual.
- 27
What does the row-normalized Toyota table indicate about fuel type among automatic cars?
Model answer
It assigns probability 1 to petrol and probability 0 to CNG and diesel.
Explanation
In the observed data, all automatic-gearbox cars have petrol fuel type.
- 28
How can a two-way table be normalized to find gearbox probabilities conditional on fuel type?
Model answer
Set
normalize='columns', making each column sum to 1.Explanation
Each fuel-type column then gives the distribution of gearbox categories among cars with that fuel type.
- 29
What does the column-normalized Toyota table indicate about gearbox type among CNG cars?
Model answer
The probability of a manual gearbox given CNG fuel type is 1 in the observed data.
Explanation
All observed CNG cars have manual gearboxes, so the automatic probability is 0.
- 30
How should the column-normalized probability 0.93 for manual gearbox among petrol cars be interpreted?
Model answer
Among cars with petrol fuel, the probability of a manual gearbox is 0.93.
Explanation
The value is conditional on petrol fuel because the table was normalized by columns.
- 31
Why should conclusions from the Toyota tables not automatically be generalized to other datasets?
Model answer
The observed counts and relationships depend on the particular records in the dataset and may differ in another dataset.
Explanation
The lecture’s interpretations describe the data at hand, not necessarily every population or sample.
- 32
What does correlation measure in this lecture?
Model answer
Correlation measures the strength of association between two numerical variables.
Explanation
It is presented as a way to examine relationships between numerical variables, in contrast to cross-tabulation for categorical variables.
- 33
What pattern in a scatter plot indicates a positive trend?
Model answer
The points tend to rise as one variable increases, showing that the other variable also tends to increase.
Explanation
For example, the lecture suggests that a heavier car may have a higher price.
- 34
What does a scatter plot with points spread without a discernible pattern suggest?
Model answer
It suggests little or no correlation between the two variables.
Explanation
Without a visible trend, changes in one variable do not show a consistent association with the other.
- 35
What range can a correlation value take, and what does a value near zero indicate?
Model answer
Correlation ranges from minus one to plus one; a value near zero indicates little or no correlation.
Explanation
The sign indicates direction, while the magnitude indicates the strength of the linear association described in the lecture.
- 36
How does the sign of a correlation distinguish positive from negative association?
Model answer
A positive value indicates that the variables tend to increase together, while a negative value indicates that one tends to decrease as the other increases.
Explanation
The sign gives the direction of the relationship, independently of whether its magnitude is large or small.
- 37
What does a correlation closer to plus one or minus one indicate?
Model answer
It indicates a stronger association; the sign identifies whether the association is positive or negative.
Explanation
Strong positive and strong negative correlations are both possible.
- 38
How does the lecture describe a correlation above 0.7?
Model answer
It describes a correlation above 0.7 as fair correlation between the numerical variables.
Explanation
This is the interpretation threshold stated in the lecture.
- 39
Why might car age and price have a strong negative correlation?
Model answer
As a car gets older, its price tends to decrease, producing a negative association.
Explanation
The lecture contrasts newer, higher-priced cars with older cars whose prices tend to be lower.
- 40
How does
DataFrame.corr()calculate correlations, and how does it handle missing values?Model answer
It calculates pairwise correlations between columns and excludes missing values from each calculation.
Explanation
Pairwise calculation means correlations are computed for pairs of variables rather than only for one selected pair.
- 41
Which correlation method is used by default in the lecture’s
correxample, and what does it assess?Model answer
The example uses Pearson correlation, which assesses the strength of association between numerical variables.
Explanation
The lecture identifies Pearson as the default method for the correlation calculation.
- 42
Which alternatives to Pearson correlation are mentioned for ordinal variables?
Model answer
Kendall rank correlation and Spearman rank correlation are mentioned.
Explanation
The lecture identifies these as alternative measures when working with ordinal variables.
- 43
Why should categorical columns be excluded when calculating Pearson correlations for numerical variables?
Model answer
Pearson correlation is being used to measure associations between numerical variables, so categorical columns are not part of that analysis.
Explanation
The lecture selects numerical columns and excludes columns with the object data type before calculating the matrix.
- 44
What does excluding object-type columns accomplish when selecting the Toyota numerical data?
Model answer
It removes categorical columns and retains the numerical variables for correlation analysis.
Explanation
The resulting data frame contains the columns treated as numerical in the lecture.
- 45
After categorical columns are excluded, what are the dimensions of the Toyota numerical data described in the lecture?
Model answer
It has 1,436 observations and 8 numerical variables.
Explanation
The original data had 10 variables, of which 8 were retained as numerical.
- 46
What is a correlation matrix, and what do its rows and columns represent?
Model answer
It is a table of pairwise correlations; its rows and columns correspond to the variables being compared.
Explanation
Each cell contains the correlation for the variable named by its row and the variable named by its column.
- 47
Why are the diagonal entries of a correlation matrix equal to 1?
Model answer
Each diagonal entry compares a variable with itself, and a variable is perfectly correlated with itself.
Explanation
Thus, the self-correlation for every variable is 1.
- 48
How should the Toyota correlation of minus 0.87 between price and age be interpreted?
Model answer
It indicates a strong negative association: as car age increases, price tends to decrease.
Explanation
The negative sign gives the direction, and the magnitude indicates a strong relationship in the example.
- 49
What does the negative correlation between kilometre reading and price imply in the Toyota example?
Model answer
Cars with higher kilometre readings tend to have lower prices.
Explanation
The lecture interprets greater distance travelled as being associated with a decrease in price.
- 50
How should the Toyota correlation of 0.58 between car weight and price be interpreted?
Model answer
It indicates a positive association: heavier cars tend to have higher prices in the data.
Explanation
A positive correlation means that the two variables tend to increase together.
- 51
What does the positive relationship between kilometre reading and car age indicate in the Toyota data?
Model answer
Older cars tend to have higher kilometre readings.
Explanation
The lecture interprets the positive association as cars generally accumulating more kilometres as they age.
- 52
How can a different correlation measure be selected when using the correlation function?
Model answer
Specify the desired measure using the function’s
methodargument.Explanation
The lecture notes that other correlation measures can be chosen by changing this argument.

Ask anything
We've read this whole study set, so questions about it get the best answers.