0% found this document useful (0 votes)
261 views6 pages

Data Analysis with Python Exam Answers

This document contains questions from a data analysis with Python certification exam. It covers topics like data wrangling, exploratory data analysis, model development and evaluation. The questions test concepts like CSV files, dataframes, feature engineering, linear regression, and model performance metrics.

Uploaded by

Sloan Ian Ariff
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
261 views6 pages

Data Analysis with Python Exam Answers

This document contains questions from a data analysis with Python certification exam. It covers topics like data wrangling, exploratory data analysis, model development and evaluation. The questions test concepts like CSV files, dataframes, feature engineering, linear regression, and model performance metrics.

Uploaded by

Sloan Ian Ariff
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Answers Data Analysis with Python Cognitive Class

Clear My Certification September 18, 2020 Cognitive Class Leave a comment 11,862 Views

Module 1 – Introduction
Question 1: What does CSV stand for ?
 Comma Separated Values
 Car Sold values

 Car State values

 None of the above

Question 2: In the data set what represents an attribute or feature?


 Row

 Column
 Each element in the data set

Question 3: What is another name for the variable that we want to predict?
 Target
 Feature

 Dataframe

Question 4: What is the command to display the first five rows of a dataframe df?
 [Link]()
 [Link]()

Question 5: what command do you use to get the data type of each row of the dataframe df?

 [Link]
 [Link]()

 [Link]()

Question 6: How do you get a statistical summary of a dataframe df?


 [Link]()
 [Link]()

 df,tails()

Question 7: If you use the method describe() without changing any of the arguments you will get a statistical summary
of all the columns of type object?
 False
 True

Module 2 – Data Wrangling


Question 1: Consider the dataframe “df” what is the result of the following operation df[‘symbolling’] =
df[‘symbolling’] + 1?:
 Every element in the column “symbolling” will increase by one
 Every element in the row “symbolling” will increase by one

 Every element in the dataframe will increase by one

Question 2: Consider the dataframe “df”, what does the command [Link](columns={‘a’:’b’}) change about the
dataframe “df”
 rename column “a” of the dataframe to “b”
 rename the row “a” to “b”

 nothing as you must set the parameter “inplace =True “


Question 3: Consider the dataframe “df” , what is the result of the following operation df[‘price’] =
df[‘price’].astype(int) ?
 convert or cast the row ‘price’ to an integer value

 convert or cast the column ‘price’ to an integer value


 convert or cast the entire dataframe to an integer value

Question 4: Consider the column of the dataframe df[‘a’]. The colunm has been standardized. What is the standard
deviation of the values, i.e the result of applying the following operation df[‘a’].std() :
1
0

3

Question 5: Consider the column of the dataframe df[‘Fuel’], with two values ‘gas’ and’ diesel’. What will be the name
of the new colunms pd.get_dummies(df[‘Fuel’]) ?
 1 and 0

 Just diesel

 Just gas

 Gas and diesel


Question 6: What are the values of the new columns from part 5 a)
 1 and 0
 Just diesel

 Just gas

 Gas and diesel

Module 3 – Exploratory Data Analysis


Question 1: Consider the dataframe “df”. Which method provides the summary statistics?
 [Link]()
 [Link]()

 [Link]()

 [Link]()

Question 2: Consider the following dataframe:


df_test = df[‘body-style’, ‘price’]
The following operations is applied:
df_grp = df_test.groupby([‘body-style’], as_index=False).mean()
What are resulting values of df_grp[‘price’]:
 The average price for each body style
 The average price

 The average body style

Question 3: Correlation implies causation :


 False
 True

Question 4: What is the minimum possible value of Pearson’s Correlation :


1
 -100

 -1
Question 5: What is the Pearson correlation between variables X and Y, if X=Y:
 -1

1
0

X

Y

Module 4 – Model Development


Question 1: Let X be a dataframe with 100 rows and 5 columns, let y be the target with 100 samples,assuming all the
relevant libraries and data have been imported, the following line of code has been executed:
LR = LinearRegression()
[Link](X, y)
yhat = [Link](X)
How many samples does yhat contain :
5

 500

 100
0

Question 2: What value of R^2 (coefficient of determination) indicates your model performs best ?
 -100

 -1

0

1
Question 3: What statement is true about Polynomial linear regression
 Polynomial linear regression is not linear in any way

 Although the predictor variables of Polynomial linear regression are not linear the relationship between the
parameters or coefficients is linear.
 Polynomial linear regression uses wavelets

Question 4: The larger the mean square error, the better your model has performed
 False
 True

Question 5: Assume all the libraries are imported, y is the target and X is the features or dependent variables, consider
the following lines of code:
Input = [(‘scale’, StandardScaler()), (‘model’, LinearRegression())]
pipe = Pipeline(Input)
[Link](X,y)
ypipe = [Link](X)
What have we just done in the above code?
 Polynomial transform, Standardize the data, then perform a prediction using a linear regression model

 Standardize the data, then perform prediction using a linear regression model
 Polynomial transform then Standardize the data
Module 5 – Model Evaluation:
Question 1: In the following plot, the vertical access shows the mean square error andthe horizontal axis represents the
order of the polynomial. The red line represents the training error the blue line is the test error. What is the best order
of the polynomial given the possible choices in the horizontal axis?
2

8
 16

Question 2: What is the use of the “train_test_split” function such that 40% of the data samples will be utilized for
testing, the parameter “random_state” is set to zero, and the input variables for the features and targets are_data,
y_data respectively.
 train_test_split(x_data, y_data, test_size=0, random_state=0.4)

 train_test_split(x_data, y_data, test_size=0.4, random_state=0)


 train_test_split(x_data, y_data)

Question 3: What is the output of cross_val_score(lre, x_data, y_data, cv=2)?


 The predicted values of the test data using cross validation.

 The average R^2 on the test data for each of the two folds
 This function finds the free parameter alpha

Question 4: What is the code to create a ridge regression object “RR” with an alpha term equal 10
 RR=LinearRegression(alpha=10)

 RR=Ridge(alpha=10)
 RR=Ridge(alpha=1)

Question 5: What dictionary value would we use to perform a grid search for the following values of alpha: 1,10, 100.
No other parameter values should be tested
 alpha=[1,10,100]

 [{‘alpha’: [1,10,100]}]
 [{‘alpha’: [0.001,0.1,1, 10, 100, 1000,10000,100000,100000],’normalize’:[True,False]} ]

Data Analysis with Python Final Exam Answers


Question 1: Question 1: What does the following command do:
[Link](subset=[“price”], axis=0)
 Drop the “not a number” from the column price
 Drop the row price

 Rename the data frame price

Question 2: How would you provide many of the summery statistics for all the columns in the dataframe “df”:
 [Link](include = “all”)
 [Link]()

 type(df)

 [Link]

Question 3: How would you find the shape of the dataframe df


 [Link]()

 [Link]()

 type(df)
 [Link]
Question 4: What task does the following command to df.to_csv(“[Link]”) perform
 change the name of the column to “[Link]”

 load the data from a csv file called “A” into a dataframe

 Save the dataframe df to a csv file called “[Link]”


Question 5: What task does the following line of code perform:
df[‘peak-rpm’].replace([Link], 5,inplace=True)
 replace the not a number values with 5 in the column ‘peak-rpm’
 rename the column ‘peak-rpm’ to 5

 add 5 to the data frame

Question 6: What task does the following line of code perform:


df[‘peak-rpm’].replace([Link], 5,inplace=True)
 replace the not a number values with 5 in the column ‘peak-rpm’
 rename the column ‘peak-rpm’ to 5

 add 5 to the data frame

Question 7: How do you “one hot encode” the column ‘fuel-type’ in the dataframe df
 pd.get_dummies(df[“fuel-type”])
 [Link]([“fuel-type”])

 df[df[“fuel-type”])==1 ]=1

Question 8: What does the vertical axis in a scatter plot represent


 independent variable

 dependent variable
Question 9: What does the horizontal axis in a scatter plot represent
 independent variable
 dependent variable

Question 10: If we have 10 columns and 100 samples how large is the output of [Link]()
 10 x 100

 10 x 10
 100×100

 100×100

Question 11: what is the largest possible element resulting in the following operation “[Link]()”
 100

 1000

1
Question 12: if the Pearson Correlation of two variables is zero:
 the two variable have zero mean

 the two variables are not correlated


Question 13: if the p value of the Pearson Correlation is 1:
 the variables are correlated

 the variables are not correlated

 none of the above


Question 14: What does the following line of code do: lm = LinearRegression()
 fit a regression object lm

 create a linear regression object


 predict a value

Question 15: If the predicted function is:


Yhat = a + b1 X1 + b2 X2 + b3 X3 + b4 X4
The method is
 Polynomial Regression

 Multiple Linear Regression


Question 16: What steps do the following lines of code perform:
Input=[(‘scale’,StandardScaler()),(‘model’,LinearRegression())]
pipe=Pipeline(Input)
[Link](Z,y)
ypipe=[Link](Z)
 Standardize the data, then perform a polynomial transform on the features Z

 find the correlation between Z and y

 Standardize the data, then perform a prediction using a linear regression model using the features Z and
targets y
Question 17: What is the maximum value of R^2 that can be obtained
 10

1
0

Question 18: We create a polynomial feature as follows “PolynomialFeatures(degree=2)”, what is the order of the
polynomial
0

1

2
Question 19: You have a linear model the average R^2 value on your training data is 0.5, you perform a 100th order
polynomial transform on your data then use these values to train another model, your average R^2 is 0.99 which
comment is correct
 100-th order polynomial will work better on unseen data

 You should always use the simplest model

 the results on your training data is not the best indicator of how your model performs, you should use your test
data to get a beter idea
Question 20:You train a ridge regression model, you get a R^2 of 1 on your training data and you get a R^2 of 0 on
your validation data, what should you do:
 Nothing your model performs flawlessly on your test data
 your model is under fitting perform a polynomial transform

 your model is overfitting, increase the parameter alpha

Common questions

Powered by AI

The method recommended for summarizing dataframe statistics is 'df.describe()', which provides summary statistics such as mean, standard deviation, min, and max for numerical columns. Using 'df.describe(include = "all")' can also be applied to obtain summary statistics across all columns, including non-numerical ones .

The standard deviation of a standardized column in a dataframe is typically 1. This is because standardization transforms the data to have a mean of 0 and a standard deviation of 1 by scaling it appropriately. Evidence from the sources indicates that a standardized column in a dataframe (e.g., df['a']) results in std() returning a value of 1, confirming this behavior .

A zero in a Pearson correlation coefficient indicates no linear correlation between two variables, meaning changes in one variable do not predict changes in the other. The document reinforces this by stating that 'if the Pearson Correlation of two variables is zero, the two variables are not correlated', confirming the lack of linear association .

One hot encoding transforms categorical data by creating new binary columns for each category value, where each column indicates the presence (1) or absence (0) of a category value in the original column. For a column with values 'gas' and 'diesel', one hot encoding results in new columns named 'Gas' and 'Diesel', each containing either 0 or 1 to represent the presence of each fuel type .

If two variables share the same data, the Pearson correlation between them is 1. This implies a perfect positive correlation, as a change in one variable corresponds directly and exactly to a change in the other, exemplifying a perfect linear relationship .

The 'train_test_split' function divides a dataset into training and testing subsets, a process crucial for evaluating model performance. Key parameters include 'test_size', which specifies the proportion of data for testing (e.g., 40% with test_size=0.4), and 'random_state', which ensures reproducibility by setting a seed for random number generation (e.g., random_state=0).

Correlation does not imply causation. While correlation measures the strength and direction of a linear relationship between two variables, it does not indicate a cause-and-effect relationship. The document specifically states 'Correlation implies causation: False', emphasizing the distinction between the correlation and causality often mistaken in data interpretation .

Overfitting occurs when a model is excessively complex, such as using high-degree polynomial features, capturing noise rather than the underlying data pattern. This results in a model with high accuracy on training data but poor generalization to unseen data. The document suggests using simpler models or adjusting model parameters (e.g., increasing the alpha term in Ridge regression) to mitigate overfitting .

An R² value of 1 on training data with significantly lower performance on test data indicates overfitting—the model learns the training data intricacies but fails to generalize. The text suggests countering overfitting by increasing model complexity controls such as the alpha parameter in regularization techniques (e.g., Ridge regression), encouraging simpler patterns fitting better to test data .

A pipeline in Python data analysis streamlines the process of data transformation and model fitting by chaining multiple steps into a single process. According to the code snippet, a pipeline consisting of data standardization and linear regression prediction ('scale' and 'model') encapsulates these processes into a single object, ensuring consistent and reproducible data handling and model training .

Answers Data Analysis with Python Cognitive Class
Clear My Certification September 18, 2020 Cognitive Class Leave a comment 1
rename the row “a” to “b”
nothing as you must set the parameter “inplace =True “
Question 3: Consider the dataframe “df” ,
-100
-1
Question 5: What is the Pearson correlation between variables X and Y, if X=Y:
-1
1
0
X
Y
Module 4 – Model Dev
Module 5 – Model Evaluation:
Question 1: In the following plot, the vertical access shows the mean square error andthe horizo
df.shape
Question 4: What task does the following command to df.to_csv(“A.csv”) perform
change the name of the column to “A
Question 14: What does the following line of code do: lm = LinearRegression()
fit a regression object lm
create a linear re

You might also like