Skilled data analysts are some of the most sought-after professionals in the world. The average Data Analyst salary in the United States is $79,616 as of, but the salary range typically falls between $69,946 and $88,877. Follow along and learn 54 most common Data Analyst interview questions and answers covering SQL, Data Processing, Statistics, Python and Pandas skills to pass your new Machine Learning and Data Science interview.
Preprocessing describes the process of cleaning and converting a 'raw' (i.e. unprocessed) dataset into a clean dataset.
Possible preprocessing steps are:
In a typical machine learning pipeline, we perform feature selection after completing feature engineering.
The workflow of a typical data mining application contains the following phases:
DataFrame.iterrows is a generator which yields both the index and row (as a Series):
import pandas as pd
df = pd.DataFrame({'c1': [10, 11, 12], 'c2': [100, 110, 120]})
for index, row in df.iterrows():
print(row['c1'], row['c2'])10 100
11 110
12 120Given a Weather table, write a SQL query to find all dates' Ids with higher temperatures compared to their previous (yesterday's) dates.
+---------+------------------+------------------+
| Id(INT) | RecordDate(DATE) | Temperature(INT) |
+---------+------------------+------------------+
| 1 | 2015-01-01 | 10 |
| 2 | 2015-01-02 | 25 |
| 3 | 2015-01-03 | 20 |
| 4 | 2015-01-04 | 30 |
+---------+------------------+------------------+For example, return the following Ids for the above Weather table:
+----+
| Id |
+----+
| 2 |
| 4 |
+----+The solution is to join the table to itself when the dates differ by one day (DATEDIFF() function) and make sure that the temperature is higher than the previous date.
SELECT W1.ID
FROM WEATHER W1 INNER JOIN WEATHER W2 ON DATEDIFF(W1.RecordDate, W2.RecordDate) = 1
WHERE W1.Temperature > W2.TemperatureData mining works by using various algorithms and techniques to turn large volumes of data into useful information. Here are some of the most common ones:
A common way to cross-validate is to divide the dataset into training, validation, and testing where:
A measure of central tendency is a single value that attempts to describe a set of data by identifying the central position within that set of data. In the simplest of terms, it attempts to find a single value that best represents an entire distribution of scores.
Mean, Median and Mode are average values or central tendency of a numerical data set.
The normal distribution is the most important probability distribution in statistics because it fits many natural phenomena. For example, heights, blood pressure, measurement error, and IQ scores follow the normal distribution. It is also known as the Gaussian distribution and the bell curve.
Normal distributions have the following features:
Normalization is basically to design a database schema such that duplicate and redundant data is avoided. If the same information is repeated in multiple places in the database, there is the risk that it is updated in one place but not the other, leading to data corruption.
There is a number of normalization levels from 1. normal form through 5. normal form. Each normal form describes how to get rid of some specific problem.
By having a database with normalization errors, you open the risk of getting invalid or corrupt data into the database. Since data "lives forever" it is very hard to get rid of corrupt data when first it has entered the database.
68 - 95 - 99.7 rule for Normal Distribution?The rule states that 68%, 95%, and 99.7% of the values lie within one, two, and three standard deviations of the mean, respectively.
c which changes the scale (for example from nanometers to kilometers).x are transformed into f(x) (where f is a measurable, typically continuous, function) much that they look normally distributed.Data definition language (DDL) commands are the commands which are used to define the database. CREATE, ALTER, DROP and TRUNCATE are some common DDL commands.
Data manipulation language (DML) commands are commands which are used for manipulation or modification of data. INSERT, UPDATE and DELETE are some common DML commands.
Simply put:
Examples of feature extraction:
Feature extraction involves a transformation of the features, which often is not reversible because some information is lost in the process of dimensionality reduction.
In general, it is safer to work on copies than on original DataFrames, except when you know that you won't be needing the original anymore and want to proceed with the manipulated version.
This is because in Pandas, indexing a DataFrame returns a reference to the initial DataFrame. Thus, changing the subset will change the initial DataFrame. Thus, you'd want to use the copy if you want to make sure the initial DataFrame shouldn't change.
Normally, you would still have some use for the original data frame to compare with the manipulated version, etc. Therefore, depending on the case it's a good practice to work on copies and merge at the end.
It's not recommended to perform K-NN on large datasets, given that the computational and memory cost can increase. To understand the reason why we should remember how the K-NN algorithm works:
So implement K-NN on a large dataset it is not only a bad decision to store a large amount of data but it is also computationally costly to keep calculating and sorting all the values. For that reason, K-NN is not recommended and another classification algorithm like Naive Bayes or SVM is preferred in such cases.
INNER JOIN ON vs WHERE clause (with multiple FROM tables)You can do:
SELECT
table1.this, table2.that, table2.somethingelse
FROM
table1, table2
WHERE
table1.foreignkey = table2.primarykey
AND (some other conditions)Or else:
SELECT
table1.this, table2.that, table2.somethingelse
FROM
table1 INNER JOIN table2
ON table1.foreignkey = table2.primarykey
WHERE
(some other conditions)What syntax would you choose and why?
INNER JOIN is ANSI syntax that you should use. INNER JOIN helps human readability, and that's a top priority. It can also be easily replaced with an OUTER JOIN whenever a need arises.
Implicit joins (with multiple FROM tables) become much much more confusing, hard to read, and hard to maintain once you need to start adding more tables to your query. The old syntax, with just listing the tables, and using the WHERE clause to specify the join criteria, is being deprecated in most modern databases.
A student received a grade of 82 on a final examination in mathematics for which the mean grade was 74 and the standard deviation was 12. On the final examination in physics, for which the mean grade was 65 and the standard deviation was 10, she received a grade of 72. On the final examination in biology, the student receive a grade of 91 biology where the mean grade was 88 and the standard deviation was 6. In which subject was her relative standing higher?
To answer this question we can use the standardized variable z, defined as
which measures the deviation of X from the mean, in terms of standard deviation s.
Therefore, the standardized scores are
Thus, the mathematics exam score was 0.67 standard deviations better than the class average; the biology score was 0.7 standard deviations better than the class average, and the physics score was only 0.5 standard deviations better than the class average. Therefore, even though the actual score on the physics exam was the lowest of the three exam scores, relative to the distribution of all class exam scores, the physics exam score was the highest relative grade.
We have a table
ID NAME EMAIL
1 John asd@asd.com
2 Sam asd@asd.com
3 Tom asd@asd.com
4 Bob bob@asd.com
5 Tom asd@asd.comI want is to get duplicates with the same email and name.
Simply group on both of the columns:
SELECT
name, email, COUNT(*) as CountOf
FROM
users
GROUP BY
name, email
HAVING
COUNT(*) > 1The whole point of having an index is to speed up search queries by essentially cutting down the number of records/rows in a table that need to be examined. An index is a data structure (most commonly a B- tree) that stores the values for a specific column in a table.
X is not low (for example, > 10%), you can create two variables: if X is not missing, = 0 if X is missing. is X is not missing, = 1 if X is missing.X increase by 1 unit. The meaning of coefficient of is the average change of response variable comparing X is missing and X = 0.X missing is low, deleting them from the analysis is a good approach.It aims to automatically construct task-specific distance metrics from (weakly) supervised data, in a machine learning manner. The learned distance metric can then be used to perform various tasks. So,e distance metrics examples:
Iteration in Pandas is an anti-pattern and is something you should only do when you have exhausted every other option. Iterating through pandas objects is generally slow. In many cases, iterating manually over the rows is not needed. You should not use any function with "iter" in its name for more than a few thousand rows or you will have to get used to a lot of waiting.
Do you want to print a DataFrame? Use DataFrame.to_string().
Do you want to compute something? In that case, search for methods in this order (list modified from here):
for loop)DataFrame.apply(): i) Reductions that can be performed in Cython, ii) Iteration in Python spaceDataFrame.itertuples() and iteritems()DataFrame.iterrows()iterrows and itertuples (both receiving many votes in answers to this question) should be used in very rare circumstances, such as generating row objects/nametuples for sequential processing, which is really the only thing these functions are useful for.
There are basic things you can do with any set of data:
Understanding data to identify errors is a whole different ball game, and it is very important.
For instance, you can have a rule that says a serial number must be present in a given data set and that serial number must be alphanumeric with a maximum string length of 255 and a minimum string length of 5.
The way I avoid problems is by leveraging the people around me. For small data sets, I can ask someone to review the data in it's entirety. For large ones, pulling a set of random samples and asking someone to do a sanity check on the data is more appropriate.
Further, questioning the source of the data and how well that data source can be trusted is imperative. I often have multiple conflicting sources of data and we create rules to determine the "source of truth". Sometimes one data set has great data in a given aspect, but other data sets are stronger in other areas.
In the first two cases, it is safe to remove the data with missing values depending upon their occurrences, while in the third case removing observations with missing values can produce a bias in the model.
Statistical tests work by calculating a test statistic – a number that describes how much the relationship between variables in your test differs from the null hypothesis of no relationship.
It then calculates a p-value (probability value). The p-value estimates how likely it is that you would see the difference described by the test statistic if the null hypothesis of no relationship were true.
If the value of the test statistic is more extreme than the statistic calculated from the null hypothesis, then you can infer a statistically significant relationship between the predictor and outcome variables.
If the value of the test statistic is less extreme than the one calculated from the null hypothesis, then you can infer no statistically significant relationship between the predictor and outcome variables.
It is the process of improving the performance of the database by adding redundant data.
In general, the normalization of a vector v with respect to a norm || . || is given by . This new vector y has the properties:
v, meaning that v is proportionate to y.Short answer:
When you have a large data set, it's recommended to split it into 3 parts:
Training set (60% of the original data set): This is used to build up our prediction algorithm. Our algorithm tries to tune itself to the quirks of the training data sets. In this phase we usually create multiple algorithms in order to compare their performances during the Cross-Validation Phase.
Cross-Validation set (20% of the original data set): This data set is used to compare the performances of the prediction algorithms that were created based on the training set. We choose the algorithm that has the best performance.
Test set (20% of the original data set): Now we have chosen our preferred prediction algorithm but we don't know yet how it's going to perform on completely unseen real-world data. So, we apply our chosen prediction algorithm on our test set in order to see how it's going to perform in the wild so we can have an idea about our algorithm's performance on unseen data.
INNER JOIN, OUTER JOIN, FULL OUTER JOIN?An inner join retrieve the matched rows only.
Whereas an outer join retrieve the matched rows from one table and all rows in other table ....the result depends on which one you are using:
Retrieve the matched rows only, that is, A intersect B.
SELECT *
FROM dbo.Students S
INNER JOIN dbo.Advisors A
ON S.Advisor_ID = A.Advisor_IDSelect all records from the first table, and any records in the second table that match the joined keys.
SELECT *
FROM dbo.Students S
LEFT JOIN dbo.Advisors A
ON S.Advisor_ID = A.Advisor_IDSelect all records from the second table, and any records in the first table that match the joined keys.
SELECT *
FROM dbo.Students S
FULL JOIN dbo.Advisors A
ON S.Advisor_ID = A.Advisor_IDBagging:
Boosting
Primary Key:
NULL - e.g. MySQL adds NOT NULLUnique Key:
NULL valuesNULL ; multiple rows can have NULL values and therefore may not be considered "unique"Difference between Primary Key and Unique key
print(df['Income'].skew())
df['Income'].describe()Q1 = df.quantile(0.25)
Q3 = df.quantile(0.75)
IQR = Q3 - Q1
print(IQR) it makes no sense to remove two correlated variables unless correlation = 1 or -1, in which case one of the variables is redundant.
You do not want to remove all correlated variables. It is only when the correlation is so strong that they do not convey extra information (see above). This is both a function of the strength of correlation, how much data you have, and whether any small difference between correlated variables tells you something about the outcome, after all.
The first two you can tell before you do any model, the final one not. So, it may be very reasonable to remove variables based on the combination of the first two considerations (i.e. even if the extra variables may in principle contain some useful information, you would not be able to tell given the strength of correlation and how much data you have) before you do any modeling/feature engineering. The final point can really only be assessed after doing some modeling.
TRUNCATE and DELETE operations effect Identity?Amazone runs the internet as we know it. Amazon Web Services (AWS) offers a comprehensive suite of machine learning (ML) services that cater to various needs and expertise levels. Follow along and learn the 23 most common AWS machine-learning intervi...
Azure Machine Learning (Azure ML) is a cloud-based service for creating and managing machine learning solutions. It’s designed to scale, distribute, and deploy machine learning models to the cloud. Follow along and learn the 23 most common Azure Mach...
Hadoop is an open-source big data processing framework. It leverages distributed computing to store and process large datasets in a fault-tolerant manner. According to recent reports, Apache Hadoop is one of the most sought-after big data skills with...