|
a |
|
b/Code.py |
|
|
1 |
#commit test |
|
|
2 |
|
|
|
3 |
|
|
|
4 |
import pandas as pd |
|
|
5 |
from sklearn.model_selection import train_test_split |
|
|
6 |
from sklearn.preprocessing import StandardScaler |
|
|
7 |
from sklearn.svm import SVC |
|
|
8 |
from sklearn.ensemble import RandomForestClassifier |
|
|
9 |
from sklearn.metrics import accuracy_score, classification_report |
|
|
10 |
import warnings |
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
# Load the dataset |
|
|
16 |
data = pd.read_excel("C:/Users/manoj kumar/Downloads/modified_dataset.xlsx") |
|
|
17 |
|
|
|
18 |
# Separate features and target variable |
|
|
19 |
X = data[['Age', 'Gender', 'OutdoorJob', 'OutdoorActivities', 'SmokingHabit', |
|
|
20 |
'Humidity', 'Pressure', 'Temperature', 'UVIndex', 'WindSpeed']] |
|
|
21 |
y = data['ACTScore'] # Assuming 'ACTScore' is the target variable |
|
|
22 |
|
|
|
23 |
# Split data into train and test sets |
|
|
24 |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) |
|
|
25 |
|
|
|
26 |
# Standardize features |
|
|
27 |
scaler = StandardScaler() |
|
|
28 |
X_train_scaled = scaler.fit_transform(X_train) |
|
|
29 |
X_test_scaled = scaler.transform(X_test) |
|
|
30 |
|
|
|
31 |
# Train Support Vector Machine (SVM) classifier |
|
|
32 |
svm_clf = SVC(kernel='linear', random_state=42) |
|
|
33 |
svm_clf.fit(X_train_scaled, y_train) |
|
|
34 |
|
|
|
35 |
# Train Random Forest classifier |
|
|
36 |
rf_clf = RandomForestClassifier(n_estimators=100, random_state=42) |
|
|
37 |
rf_clf.fit(X_train_scaled, y_train) |
|
|
38 |
|
|
|
39 |
# Predictions |
|
|
40 |
svm_pred = svm_clf.predict(X_test_scaled) |
|
|
41 |
rf_pred = rf_clf.predict(X_test_scaled) |
|
|
42 |
|
|
|
43 |
# Evaluate models |
|
|
44 |
print("Support Vector Machine Classifier:") |
|
|
45 |
print("Accuracy:", accuracy_score(y_test, svm_pred)) |
|
|
46 |
print("Classification Report:") |
|
|
47 |
print(classification_report(y_test, svm_pred)) |
|
|
48 |
|
|
|
49 |
print("\nRandom Forest Classifier:") |
|
|
50 |
print("Accuracy:", accuracy_score(y_test, rf_pred)) |
|
|
51 |
print("Classification Report:") |
|
|
52 |
|
|
|
53 |
# Print classification report |
|
|
54 |
print(classification_report(y_test, rf_pred)) |
|
|
55 |
|