0% found this document useful (0 votes)
6 views2 pages

22ss02ca057 - AI Practical Exam

Uploaded by

glicmack
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

22ss02ca057 - AI Practical Exam

Uploaded by

glicmack
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Name: Prince Vekariya

En. No.: 22ss02ca057

Code:

import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
from sklearn.impute import SimpleImputer
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score

file_path = 'D:\Coding\exam\Student_Depression_Dataset.csv'
data = pd.read_csv(file_path)

data_cleaned = data.drop(columns=["id", "City", "Degree"])

categorical_columns = data_cleaned.select_dtypes(include="object").columns

label_encoders = {col: LabelEncoder() for col in categorical_columns}


for col in categorical_columns:
data_cleaned[col] =
label_encoders[col].fit_transform(data_cleaned[col].astype(str))

imputer = SimpleImputer(strategy="mean")
data_cleaned.iloc[:, :] = imputer.fit_transform(data_cleaned)

X = data_cleaned.drop(columns=["Depression"])
y = data_cleaned["Depression"]

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3,


random_state=42)

rf = RandomForestClassifier(n_estimators=200, max_depth=20, random_state=42)


rf.fit(X_train, y_train)

y_pred_rf = rf.predict(X_test)

accuracy_rf = accuracy_score(y_test, y_pred_rf)

print(accuracy_rf)

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy