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

pr5 AAM

The document contains a Python program that implements a decision tree classifier for a dataset related to playing conditions. It includes data preprocessing steps such as label encoding and splitting the dataset into training and testing sets. The program also predicts whether to play based on unique weather conditions using the trained model.

Uploaded by

Ishwari khebade
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)
4 views2 pages

pr5 AAM

The document contains a Python program that implements a decision tree classifier for a dataset related to playing conditions. It includes data preprocessing steps such as label encoding and splitting the dataset into training and testing sets. The program also predicts whether to play based on unique weather conditions using the trained model.

Uploaded by

Ishwari khebade
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 : Lisha Chintaman Talele

Roll No : 56
Class : TYAN

Practical No : 05 Write a python Programming code to implement decision tree for


classification using suitable data/dataset.

import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score

df=pd.read_csv("/content/drive/MyDrive/Decision_tree.csv")

print(df.head())

if "Sr.No" in df.columns:
df = df.drop(columns=["Sr.No"])

label_encoders = {}
for col in df.columns:
le = LabelEncoder()
df[col] = le.fit_transform(df[col])
label_encoders[col] = le

X = df.drop(columns=["Play"])
y = df["Play"]

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


random_state=42)

clf = DecisionTreeClassifier()
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)

# Predict "Play" for each unique weather condition


weather_values = df["Weather"].unique()
weather_predictions = {}

for weather in weather_values:


sample_input = X[X["Weather"] == weather].iloc[0:1] # Select a sample row
with the same weather
prediction = clf.predict(sample_input)[0] # Predict using the model
weather_predictions[label_encoders["Weather"].inverse_transform([weather])[
0]] = "Yes" if prediction == 1 else "No"

weather_predictions

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