Tuesday, October 24, 2023

2023 Cognitive Class – Data Science with Scala Answers (Updated)

By , in All Courses Answers IBM on .

2023 – 2024 Cognitive Class – Data Science with Scala Answers

Module 1: Basic Statistics and Data Types

1. You import MLlib’s vectors from ?

  1. org.apache.spark.mllib.TF
  2. org.apache.spark.mllib.numpy
  3. org.apache.spark.mllib.linalg
  4. org.apache.spark.mllib.pandas

2. Select the types of distributed Matrices :

  1. RowMatrix
  2. IndexedRowMatrix
  3. CoordinateMatrix

3. How would you caculate the mean of the following ?

val observations: RDD[Vector] = sc.parallelize(Array(
Vectors.dense(1.0, 2.0),
Vectors.dense(4.0, 5.0),
Vectors.dense(7.0, 8.0)))
val summary: MultivariateStatisticalSummary = Statistics.colStats(observations)

  1. summary.normL1
  2. summary.numNonzeros
  3. summary.mean
  4. summary.normL2

4. what task does the following lines of code?

import org.apache.spark.mllib.random.RandomRDDs._
val million = poissonRDD(sc, mean=1.0, size=1000000L, numPartitions=10)

  1. Calculate the variance
  2. calculate the mean
  3. generate random samples
  4. Calculate the variance

5. MLlib uses the compressed sparse column format for sparse matrices, as Such it only keeps the non-zero entrees?

  1. True
  2. False

Module 2: Preparing Data

1. WFor a dataframe object the method describe calculates the ?

  1. count
  2. mean
  3. standard deviation
  4. max
  5. min
  6. all of the above

2. What line of code drops the rows that contain null values, select the best answer ?

  1. val dfnan = df.withColumn(“nanUniform”, halfTonNaN(df(“uniform”)))
  2. dfnan.na.replace(“uniform”, Map(Double.NaN -> 0.0))
  3. dfnan.na.drop(minNonNulls = 3)
  4. dfnan.na.fill(0.0)

3. What task does the following lines of code perform ?

val lr = new LogisticRegression()
lr.setMaxIter(10).setRegParam(0.01)
val model1 = lr.fit(training)

  1. perform one hot encoding
  2. Train a linear regression model
  3. Train a Logistic regression model
  4. Perform PCA on the data

4. The StandardScaleModel transforms the data such that ?

  1. each feature has a max value of 1
  2. each feature is Orthogonal
  3. each feature to have a unit standard deviation and zero mean
  4. each feature has a min value of -1

Module 3: Feature Engineering

1. Spark ML works with?

  1. tensors
  2. vectors
  3. dataframes
  4. lists

2. the function IndexToString() performs One hot encoding?

  1. True
  2. False

3. Principal Component Analysis is Primarily used for ?

  1. to convert categorical variables to integers
  2. to predict discrete values
  3. dimensionality reduction

4. one import set prior to using PCA is ?

  1. normalizing your data
  2. making sure every feature is not correlated
  3. taking the log for your data
  4. subtracting the mean

 Module 4: Fitting a Model

1. You can use decision trees for ?

  1. regression
  2. classification
  3. classification and regression
  4. data normalization

2. the following lines of code: val Array(trainingData, testData) = data.randomSplit(Array(0.7, 0.3))

  1. split the data into training and testing data
  2. train the model
  3. use 70% of the data for testing
  4. use 30% of the data for training
  5. make a prediction

3. in the Random Forest Classifier constructor .setNumTrees() ?

  1. sets the max depth of trees
  2. sets the minimum number of classes before a split
  3. set the number of trees

4. Elastic net regularization uses ?

  1. L0-norm
  2. L1-norm
  3. L2-norm
  4. a convex combination of the L1 norm and L2 norm

 Module 5: Pipeline and Grid Search

1. what task does the following code perform: withColumn(“paperscore”, data(“A2”) * 4 + data(“A”) * 3) ?

  • add 4 colunms to A2
  • add 3 colunms to A1
  • add 4 to each elment in colunm A2
  • assign a higher weight to A2 and A journals

2. In an estimator ?

  1. there is no need to call the method fit
  2. fit function is called
  3. transform fuction is only called

3. Which is not a valid type of Evaluator in MLlib?

  1. RegressionEvaluator
  2. MultiClassClassificationEvaluator
  3. MultiLabelClassificationEvaluator
  4. BinaryClassificationEvaluator
  5. All are valid

4. In the following lines of code, the last transform in the pipeline is a:

val rf = new RandomForestClassifier().setFeaturesCol(“assembled”).setLabelCol(“status”).setSeed(42)
import org.apache.spark.ml.Pipeline
val pipeline = new Pipeline().setStages(Array(value_band_indexer,category_indexer,label_indexer,assembler,rf))

  1. principal component analysis
  2. Vector Assembler
  3. String Indexer
  4. Vector Assembler
  5. Random Forest Classifier

Final Exam Answers

1. What is not true about labeled points?

  1. They associate sparse vectors with a corresponding label/response
  2. They associate dense vectors with a corresponding label/response
  3. They are used in unsupervised machine learning algorithms
  4. All are true
  5. None are true

2. Which is true about column pointers in sparse matrices?

  1. By themselves, they do not represent the specific physical location of a value in the matrix
  2. They never repeat values
  3. They have the same number of values as the number of columns
  4. All are true
  5. None are true

3. What is the name of the most basic type of distributed matrix?

  1. CoordinateMatrix
  2. IndexedRowMatrix
  3. SparseMatrix
  4. SimpleMatrix
  5. RowMatrix

4. A perfect correlation is represented by what value?

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

5. A MinMaxScaler is a transformer which:

  1. Rescales each feature to a specific range
  2. Takes no parameters
  3. Makes zero values remain untransformed
  4. All are true
  5. None are true

6. Which is not a supported Random Data Generation distribution?

  1. Poisson
  2. Uniform
  3. Exponential
  4. Delta
  5. Normal

7. Sampling without replacement means:

  1. The expected number of times each element is chosen is randomized
  2. The expected size of the sample is a fraction of the RDDs size
  3. The expected number of times each element is chosen
  4. The expected size of the sample is unknown
  5. The expected size of the sample is the same as the RDDs size

8. What are the supported types of hypothesis testing?

  1. Pearson’s Chi-Squared Test for goodness of fit
  2. Pearson’s Chi-Squared Test for independence
  3. Kolmogorov-Smirnov test for equality of distribution
  4. All are supported
  5. None are supported

9. For Kernel Density Estimation, which kernel is supported by Spark?

  1. KDEMultivariate
  2. KDEUnivariate
  3. Gaussian
  4. KernelDensity
  5. All are supported

10. Which DataFrames statistics method computes the pairwise frequency table of the given columns?

  1. freqItems()
  2. cov()
  3. crosstab()
  4. pairwiseFreq()
  5. corr()

11. Which is not true about the fill method for DataFrame NA functions?

  1. It is used for replacing NaN values
  2. It is used for replacing nil values
  3. It is used for replacing null values
  4. All are true
  5. None are true

12. Which transformer listed below is used for Natural Language processing?

  1. StandardScaler
  2. OneHotEncoder
  3. ElementwiseProduct
  4. Normalizer
  5. None are used for Natural Language processing

13. Which is true about the Mahalanobis Distance?

  1. It is a scale-variant distance
  2. It does not take into account the correlations of the dataset
  3. It is measured along each Principle Component axis
  4. It is a multi-dimensional generalization of measuring how many standard deviations a point is away from the median
  5. It has units of distance

14. Which is true about OneHotEncoder?

  1. It must be told which column to create for its output
  2. It creates a Sparse Vector
  3. It must be told which column is its input
  4. All are true
  5. None are true

15. Principle Component Analysis is:

  1. Is never used for feature engineering
  2. Used for supervised machine learning
  3. A dimension reduction technique
  4. All are true
  5. None are true

16. MLlib’s implementation of decision trees:

  1. Supports only multiclass classification
  2. Does not support regressions
  3. Partitions data by rows, allowing distributed training
  4. Supports only continuous features
  5. None are true

17. Which is not a tunable of SparkML decision trees?

  1. maxBins
  2. maxMemoryInMB
  3. minInstancesPerNode
  4. minDepth
  5. minInfoGain

18. Which is true about Random Forests?

  1. They support non-categorical features
  2. They combine many decision trees in order to reduce the risk of overfitting
  3. They do not support regression
  4. They only support binary classification
  5. None are true

19. When comparing Random Forest versus Gradient-Based Trees, what must you consider?

  1. How the number of trees affects the outcome
  2. Depth of Trees
  3. Parallelization abilities
  4. All of these
  5. None of these

20. Which is not a valid type of Evaluator in MLlib?

  1. MultiLabelClassificationEvaluator
  2. RegressionEvaluator
  3. BinaryClassificationEvaluator
  4. MultiClassClassificationEvaluator
  5. All are valid