Friday, October 27, 2023

# 2023 Cognitive Class – Data Analysis with Python Answers (Updated)

By , in on .

2023 – 2024 Cognitive Class – Data Analysis with Python Answers

### Module 1: Introduction

1. What does CSV stand for?

1. Comma Separated Values
2. Car Sold values
3. Car State values
4. None of the above

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

1. Row
2. Column
3. Each element in the data set

3. What is another name for the variable that we want to predict?

1. Target
2. Feature
3. Dataframe

4. What is the command to display the first five rows of a dataframe df?

2. df.tail()

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

1. df.dtypes
3. df.tail()

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

1. df.describe()
3. df,tails()

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?

1. False
2. True

### Module 2: Data Wrangling

1. Consider the dataframe “df” what is the result of the following operation df[‘symbolling’] = df[‘symbolling’] + 1?:

1. Every element in the column “symbolling” will increase by one
2. Every element in the row “symbolling” will increase by one
3. Every element in the dataframe will increase by one

2. Consider the dataframe “df”, what does the command df.rename(columns={‘a’:’b’}) change about the dataframe “df”

1. rename column “a” of the dataframe to “b”
2. rename the row “a” to “b”
3. nothing as you must set the parameter “inplace =True “

3. Consider the dataframe “df” , what is the result of the following operation df[‘price’] = df[‘price’].astype(int) ?

1. convert or cast the row ‘price’ to an integer value
2. convert or cast the column ‘price’ to an integer value
3. convert or cast the entire dataframe to an integer value

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. 1
2. 0
3. 3

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. 1 and 0
2. Just diesel
3. Just gas
4. Gas and diesel

6. What are the values of the new columns from part 5 a)

1. 1 and 0
2. Just diesel
3. Just gas
4. Gas and diesel

### Module 3: Exploratory Data Analysis

1. Consider the dataframe “df”. Which method provides the summary statistics?

1. df.describe()
3. df.tail()
4. df.summary()

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’]:

1. The average price for each body style
2. The average price
3. The average body style

3. Correlation implies causation :

1. False
2. True

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

1. 1
2. -100
3. -1

5. What is the Pearson correlation between variables X and Y, if X=Y:

1. -1
2. 1
3. 0
4. X
5. Y

### Module 4: Model Development

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()
LR.fit(X, y)
yhat = LR.predict(X)

How many samples does yhat contain :

1. 5
2. 500
3. 100
4. 0

2. What value of R^2 (coefficient of determination) indicates your model performs best ?

1. -100
2. -1
3. 0
4. 1

3. What statement is true about Polynomial linear regression

1. Polynomial linear regression is not linear in any way
2. Although the predictor variables of Polynomial linear regression are not linear the relationship between the parameters or coefficients is linear.
3. Polynomial linear regression uses wavelets

4. The larger the mean square error, the better your model has performed

1. False
2. True

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)
pipe.fit(X,y)
ypipe = pipe.predict(X)

What have we just done in the above code?

1. Polynomial transform, Standardize the data, then perform a prediction using a linear regression model
2. Standardize the data, then perform prediction using a linear regression model
3. Polynomial transform then Standardize the data

### Module 5: Model Evaluation

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?

1. 2
2. 8
3. 16

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.

1. train_test_split(x_data, y_data, test_size=0, random_state=0.4)
2. train_test_split(x_data, y_data, test_size=0.4, random_state=0)
3. train_test_split(x_data, y_data)

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

1. The predicted values of the test data using cross validation.
2. The average R^2 on the test data for each of the two folds
3. This function finds the free parameter alpha

4. What is the code to create a ridge regression object “RR” with an alpha term equal 10

1. RR=LinearRegression(alpha=10)
2. RR=Ridge(alpha=10)
3. RR=Ridge(alpha=1)

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

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

### Data Analysis with Python Final Exam Answers

1. What does the following command do:

df.dropna(subset=[“price”], axis=0)

1. Drop the “not a number” from the column price
2. Drop the row price
3. Rename the data frame price

2. How would you provide many of the summery statistics for all the columns in the dataframe “df”:

1. df.describe(include = “all”)
3. type(df)
4. df.shape

3. How would you find the shape of the dataframe df

1. df.describe()
3. type(df)
4. df.shape

4. What task does the following command to df.to_csv(“A.csv”) perform

1. change the name of the column to “A.csv”
2. load the data from a csv file called “A” into a dataframe
3. Save the dataframe df to a csv file called “A.csv”

5. What task does the following line of code perform:

df[‘peak-rpm’].replace(np.nan, 5,inplace=True)

1. replace the not a number values with 5 in the column ‘peak-rpm’
2. rename the column ‘peak-rpm’ to 5
3. add 5 to the data frame

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

df[‘peak-rpm’].replace(np.nan, 5,inplace=True)

1. replace the not a number values with 5 in the column ‘peak-rpm’
2. rename the column ‘peak-rpm’ to 5
3. add 5 to the data frame

7. How do you “one hot encode” the column ‘fuel-type’ in the dataframe df

1. pd.get_dummies(df[“fuel-type”])
2. df.mean([“fuel-type”])
3. df[df[“fuel-type”])==1 ]=1

8. What does the vertical axis in a scatter plot represent

1. independent variable
2. dependent variable

9. What does the horizontal axis in a scatter plot represent

1. independent variable
2. dependent variable

10. If we have 10 columns and 100 samples how large is the output of df.corr()

1. 10 x 100
2. 10 x 10
3. 100×100
4. 100×100

11. what is the largest possible element resulting in the following operation “df.corr()”

1. 100
2. 1000
3. 1

12. if the Pearson Correlation of two variables is zero:

1. the two variable have zero mean
2. the two variables are not correlated

13. if the p value of the Pearson Correlation is 1:

1. the variables are correlated
2. the variables are not correlated
3. none of the above

14. What does the following line of code do: lm = LinearRegression()

1. fit a regression object lm
2. create a linear regression object
3. predict a value

15. If the predicted function is:

Yhat = a + b1 X1 + b2 X2 + b3 X3 + b4 X4

The method is

1. Polynomial Regression
2. Multiple Linear Regression

16. What steps do the following lines of code perform:

Input=[(‘scale’,StandardScaler()),(‘model’,LinearRegression())]
pipe=Pipeline(Input)
pipe.fit(Z,y)
ypipe=pipe.predict(Z)

1. Standardize the data, then perform a polynomial transform on the features Z
2. find the correlation between Z and y
3. Standardize the data, then perform a prediction using a linear regression model using the features Z and targets y

17. What is the maximum value of R^2 that can be obtained

1. 10
2. 1
3. 0

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

1. 0
2. 1
3. 2

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

1. 100-th order polynomial will work better on unseen data
2. You should always use the simplest model
3. 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

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: