Loading

Quipoin Menu

Learn • Practice • Grow

python-for-ai / What is Scikit-learn?
interview

Q1. You need to build a machine learning model to predict house prices based on features like area, bedrooms. Which Python library would you use? What submodule contains regression models?
Scikit-learn (sklearn) is the go-to library. For regression: from sklearn.linear_model import LinearRegression. It provides consistent API: .fit(), .predict(), .score(). Also includes preprocessing, cross-validation, metrics.

Q2. Load the iris dataset from sklearn.datasets. Print its feature names and target names. Convert to DataFrame for easier viewing.
from sklearn.datasets import load_iris
iris = load_iris()
print(iris.feature_names)
print(iris.target_names)
import pandas as pd
df = pd.DataFrame(iris.data, columns=iris.feature_names)
df[''target''] = iris.target
This loads built-in datasets for practice.

Q3. Why is scikit-learn preferred for classical machine learning over implementing algorithms from scratch?
Scikit-learn provides optimized, well-tested implementations, consistent API, extensive documentation, and integration with other scientific Python libraries. It includes tools for model selection, preprocessing, and pipelines, saving development time and reducing errors.

Q4. You have a classification problem. Which scikit-learn models would you try first? Name three.
LogisticRegression, DecisionTreeClassifier, RandomForestClassifier, KNeighborsClassifier, SVC (support vector classifier). Start with simple models (logistic regression) then ensemble methods.

Q5. The scikit-learn API follows fit/predict pattern. Write a simple linear regression fitting X (2D) and y (1D) then predicting on new data.
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
This is standard across all models.