✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.
Question 4 (25 marks)
4.1 Write a pseudo code/ algorithm for the K-means clustering algorithm.(10)
4.2 Explain why accuracy is not always the ideal metric for model evaluation (5)
4.3 Use Table 4.3 to answer the following questions:
Table 4.3
· age: Patient age (years).
· blood_pressure: Systolic blood pressure (mmHg)
· cholesterol: Serum cholesterol level (mg/dL)
· has_disease: Binary target indicating if the patient has the disease (1 = yes, 0 = no)
Complete the following code to show a Python code snippet to train the decision tree and logistic regression models for making predictions.
import pandas as pd
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report, confusion_matrix
# Load the data in the dataframe
data = {
"age": [40, 55, 60, 45, 50, 35, 70, 65, 54, 75],
"blood_pressure": [120, 140, 130, 135, 142, 110, 160, 150, 138, 170],
"cholesterol": [200, 210, 250, 240, 190, 180, 260, 210, 225, 280],
"has_disease": [0, 1, 0, 1, 0, 0, 1, 1, 0, 1]
}
df = pd.DataFrame(data)
# Split into features (X) and target (y)
X = df[["age", "blood_pressure", "cholesterol"]]
y = df["has_disease"]
# Dataset split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
# Code for training the Decision tree and make predictions (5)
………………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………………
# Code for training the Logistic regression and make predictions (5)
………………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………………
Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!