ML Assignment 1 - Nageswar
ML Assignment 1 - Nageswar
ML Assignment 1 - Nageswar
MSC DS.
Subject ML
Assignment 1:
1. illustrate the K means clustering with a suitably identified choice of k for mall-data and
drawing inerfaces related to the resulting clusters
Answer:
import pandas as pd
data = pd.read_csv('Mall_Customers.csv')
# Applying K-means
data['Cluster'] = kmeans.fit_predict(X)
plt.figure(figsize=(10, 6))
label=f'Cluster {cluster}')
plt.legend()
plt.title('Customer Segments')
plt.show()
2. Illustrate and create decision tree for any data set and compare its performance.
Answer:
import pandas as pd
iris = load_iris()
X, y = iris.data, iris.target
clf = DecisionTreeClassifier(random_state=42)
clf.fit(X_train, y_train)
# Make predictions
y_pred = clf.predict(X_test)
# Evaluate performance
print(f"Accuracy: {accuracy:.2f}")
Answer:
import pandas as pd
import numpy as np
cancer = load_breast_cancer()
# Extract features and target
svc = SVC()
grid.fit(X_train, y_train)
best_C = grid.best_params_['C']
best_gamma = grid.best_params_['gamma']
best_svc.fit(X_train, y_train)
# Evaluate performance
y_pred = best_svc.predict(X_test)