0% found this document useful (0 votes)
35 views3 pages

50 Essential Python Library Questions

The document contains a series of questions related to various Python libraries used in data science, including NumPy, Pandas, Matplotlib, Scikit-learn, Statsmodels, TensorFlow, and PyTorch. Each section covers fundamental concepts, functionalities, and differences between methods and libraries. The questions aim to assess knowledge on data manipulation, visualization, machine learning, and deep learning techniques.

Uploaded by

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

50 Essential Python Library Questions

The document contains a series of questions related to various Python libraries used in data science, including NumPy, Pandas, Matplotlib, Scikit-learn, Statsmodels, TensorFlow, and PyTorch. Each section covers fundamental concepts, functionalities, and differences between methods and libraries. The questions aim to assess knowledge on data manipulation, visualization, machine learning, and deep learning techniques.

Uploaded by

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

Python Libraries Questions

🧮 NumPy (Numerical Python)


1.​ What is NumPy? Why is it used in data science?​

2.​ How is a NumPy array different from a Python list?​

3.​ How do you create a NumPy array from a list or range?​

4.​ What are broadcasting rules in NumPy?​

5.​ How do you compute the mean, median, and standard deviation using NumPy?​

6.​ What is the difference between [Link](), [Link](), and [Link]()?​

📊 Pandas (Data Manipulation)


7.​ What is a DataFrame in Pandas?​

8.​ How do you read a CSV file using Pandas?​

9.​ How do you handle missing data in a DataFrame?​

10.​What is the difference between loc[] and iloc[]?​

11.​How do you group data in Pandas (groupby)?​

12.​How do you merge or join two DataFrames?​

13.​How can you remove duplicates from a DataFrame?​

📈 Matplotlib & Seaborn (Data Visualization)


14.​How do you create a line plot or bar plot using Matplotlib?​
15.​What is the difference between [Link]() and [Link]()?​

16.​How do you visualize missing data using Seaborn?​

17.​How can you create a correlation heatmap in Seaborn?​

18.​What is the role of [Link]() in Matplotlib?​

🤖 Scikit-learn (Machine Learning)


19.​What are the steps to train a machine learning model in Scikit-learn?​

20.​How do you split your dataset into training and testing sets?​

21.​What is the use of StandardScaler() in Scikit-learn?​

22.​How do you evaluate a classification model in Scikit-learn?​

23.​What is the difference between fit() and transform()?​

24.​How do you perform cross-validation using Scikit-learn?​

📊 Statsmodels (Statistical Modeling)


25.​What is the difference between Scikit-learn and Statsmodels?​

26.​How do you perform linear regression using Statsmodels?​

27.​What is the use of the .summary() function in Statsmodels?​


🤖 TensorFlow / PyTorch (Deep Learning)
28.​What is TensorFlow used for in data science?​

29.​How do you define a simple neural network using Keras (in TensorFlow)?​

30.​What is the difference between PyTorch and TensorFlow?​

Common questions

Powered by AI

Broadcasting in NumPy refers to how operations between arrays of different shapes are handled. When performing operations on NumPy arrays, if their dimensions do not match, NumPy attempts to 'broadcast' the smaller array across the larger one so that they can be compatible shape-wise. This is particularly useful in vectorized operations which allow for efficient computation without the need for explicit looping in Python code . Broadcasting adheres to specific rules: dimensions are compared from the trailing dimensions and must either be the same size or one of them must be 1 . This feature is essential for performing arithmetic operations even when arrays have different shapes.

Performing linear regression using Statsmodels involves several steps. First, the necessary libraries are imported, and the data is prepared. A key step is adding a constant to the independent variables to account for the intercept in the regression model. The OLS (Ordinary Least Squares) method is used to fit the model by calling OLS() with the dependent variable and the independent variables as arguments. The fitted model is then obtained by calling .fit() on the OLS object. The typical outputs to evaluate include the regression coefficients, p-values, R-squared value, and confidence intervals, which are obtained via the .summary() function . These provide insights into the model's performance and the significance of the predictors.

The main differences between Statsmodels and Scikit-learn lie in their focus and capabilities. Statsmodels is primarily designed for statistical modeling and testing, providing detailed summaries and testing capabilities, which include p-values, confidence intervals, and extensive results about model parameters. It is typically used in contexts where a statistical interpretation is needed. Scikit-learn, however, focuses more on machine learning and predictive analytics, offering extensive tools for model training, validation, and integration with other machine learning components but without as deep statistical testing abilities . The choice between these depends on whether the task prioritizes explainability and statistical insight (Statsmodels) or predictive performance (Scikit-learn).

Scikit-learn facilitates cross-validation through functions like cross_val_score(), which systematically splits the dataset into k subsets or 'folds'. Each fold is used once as a validation while the k-1 remaining folds form the training set. This process is important as it helps assess how the results of a statistical analysis will generalize to an independent dataset. Cross-validation is a robust method to ensure that the model is not overfitting, as it averages the performance across several different training and validation splits rather than relying on a single partition, thus providing a more reliable estimation of model performance .

Training a machine learning model in Scikit-learn typically involves several steps. First, the dataset is split into a training set and a testing set to evaluate the model's performance. Data preprocessing is conducted, which might include scaling features, encoding categorical variables, or handling missing data. Next, a model is selected, and its hyperparameters are set. The model is then trained using the fit() method on the training data. After training, the model's performance is evaluated on the test set using appropriate metrics like accuracy, precision, or recall, depending on the model's purpose . These steps ensure the model can generalize to new, unseen data.

The main difference between loc[] and iloc[] in Pandas lies in how they index the DataFrame. loc[] is label-based, meaning it is used to access a group of rows and columns by labels or a boolean array. iloc[], in contrast, is integer-location based; it is used to access rows and columns by their integer index, similar to how Python's list indexing works . These methods are crucial for selecting specific data efficiently and controlling data manipulation at both high-level and granular levels. Loc is particularly useful when dealing with data that has indices like dates or categorical data.

A Pandas DataFrame enhances data manipulation by providing a tabular data structure with labeled axes (rows and columns), which is more powerful than a simple list or array. It supports heterogeneous data types across columns, similar to a spreadsheet or SQL table. Key advantages include the ability to handle large datasets, data alignment and integrated operations such as aggregation, filtering, and pivoting. It simplifies data cleaning and preparation with methods to handle missing data, and its integration with other libraries allows for seamless analysis and visualization . Unlike lists or arrays, DataFrames provide a multitude of built-in functions which optimize data manipulation tasks.

The function np.empty() differs from np.zeros() and np.ones() in that it creates an array without initializing its elements. This means the values in an np.empty() array are unpredictable and contain whatever values currently exist at the memory location. This can be useful when the user knows they will immediately overwrite the elements, saving some initialization time compared to filling the array with default zeros or ones . np.empty() is typically used for performance reasons when the initial values are not important or will be changed immediately.

StandardScaler() in Scikit-learn plays a crucial role in data preprocessing by standardizing features by removing the mean and scaling to unit variance. It is particularly used when the input data may have varying scales which could adversely affect the performance of machine learning models, especially those based on distance metrics like SVM or k-NN. StandardScaler() ensures that all features have the same scale, which is often necessary for achieving optimal model performance . It is typically applied before training the model on the dataset.

plt.plot() and plt.scatter() serve different purposes in Matplotlib. plt.plot() is typically used for plotting lines by connecting a sequence of data points with a line, making it ideal for situations where displaying trends over intervals or time is needed. plt.scatter(), on the other hand, creates a scatter plot of individual data points, showing the relationship between two variables without connecting them, which is particularly useful for identifying patterns such as clusters or outliers . The choice between the two methods depends on the underlying data relationship one aims to visualize.

You might also like