[b371c4]: / Code.py

Download this file

56 lines (39 with data), 1.7 kB

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