ML Lab
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.tree import DecisionTreeClassifier, plot_tree
# Load the data
data = pd.read_csv("/PlayTennisData.csv")
# Prepare the data
X = data.drop('PlayTennis', axis=1)
y = data['PlayTennis']
X = pd.get_dummies(X)
y = y.map({'yes': 1, 'no': 0})
# Fit the Decision Tree Classifier
classifier = DecisionTreeClassifier(criterion='entropy')
classifier.fit(X, y)
# Plot the tree
plt.figure(figsize=(20, 10)) # Adjust the size as needed
plot_tree(classifier, filled=True, feature_names=X.columns, class_names=['no', 'yes'], rounded=True, fontsize=12)
plt.show()
#prog 9
import numpy as np
import matplotlib.pyplot as plt
from statsmodels.nonparametric.smoothers_lowess import lowess
from math import pi
# Generate sample data
n = 100
x = np.linspace(0, 2 * pi, n)
y = np.sin(x) + 0.3 * np.random.randn(n)
# Apply LOWESS
smoothed = lowess(y, x, frac=0.25, it=3)
# Plot results
plt.plot(x, y, 'r.', label='Data Points')
plt.plot(smoothed[:, 0], smoothed[:, 1], 'b-', label='LOWESS Fit')
plt.legend()
plt.show()
#3 program
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.tree import DecisionTreeClassifier, plot_tree
# Load the data
data = pd.read_csv("/PlayTennisData.csv")
# Prepare the data
X = data.drop('PlayTennis', axis=1)
y = data['PlayTennis']
X = pd.get_dummies(X)
y = y.map({'yes': 1, 'no': 0})
# Fit the Decision Tree Classifier
classifier = DecisionTreeClassifier(criterion='entropy')
classifier.fit(X, y)
# Plot the tree
plt.figure(figsize=(20, 10)) # Adjust the size as needed
plot_tree(classifier, filled=True, feature_names=X.columns, class_names=['no', 'yes'], rounded=True, fontsize=12)
plt.show()
.jpeg)
Comments
Post a Comment