Code
Code
import numpy as np
from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.ensemble import RandomForestClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score, classification_report, confusion_mat
https://colab.research.google.com/drive/1YSaqI1S13jeRxk_Y9nE3-bjzLW_OETL3?usp=sharing 17/01/25, 12 19
Page 1 of 4
:
features = data.drop(columns=['target'])
labels = data['target']
--------------------------------------------------------------------
-------
NameError Traceback (most recent
call last)
<ipython-input-5-5943e81b0eae> in <cell line: 1>()
----> 1 features = data.drop(columns=['target'])
2 labels = data['target']
rf_model = RandomForestClassifier(random_state=42)
rf_model.fit(X_train, y_train)
rf_predictions = rf_model.predict(X_test)
print("Random Forest Results:")
print("Accuracy:", accuracy_score(y_test, rf_predictions))
print("Classification Report:\n", classification_report(y_test, rf_predictions))
https://colab.research.google.com/drive/1YSaqI1S13jeRxk_Y9nE3-bjzLW_OETL3?usp=sharing 17/01/25, 12 19
Page 2 of 4
:
Support Vector Machine (SVM) ClassiFer
svm_param_grid = {
'C': [0.1, 1, 10],
'gamma': ['scale', 'auto'],
'kernel': ['linear', 'rbf']
}
https://colab.research.google.com/drive/1YSaqI1S13jeRxk_Y9nE3-bjzLW_OETL3?usp=sharing 17/01/25, 12 19
Page 3 of 4
:
https://colab.research.google.com/drive/1YSaqI1S13jeRxk_Y9nE3-bjzLW_OETL3?usp=sharing 17/01/25, 12 19
Page 4 of 4
: