CARVIEW |
Select Language
HTTP/2 200
date: Fri, 10 Oct 2025 23:37:02 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=e50ac2039f9d4fc34c71312c924235247a395d53b7b81d2d5fbc1cac852b72dca%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22hu6V22FMrL1Mm9Yd5BGQqcXlh-HpO__T%22%3B%7D; HttpOnly; Path=/
cf-ray: 98c9f1792f79f470-BLR
ML Exp 6 - Pastebin.com
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- from sklearn.model_selection import train_test_split
- from sklearn.preprocessing import StandardScaler, LabelEncoder
- from sklearn.tree import DecisionTreeClassifier, plot_tree
- from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
- import matplotlib.pyplot as plt
- data = pd.read_csv("Social_Network_Ads.csv")
- le = LabelEncoder()
- data['Gender'] = le.fit_transform(data['Gender']) # Male=1, Female=0
- X = data[['Gender', 'Age', 'EstimatedSalary']]
- y = data['Purchased']
- X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
- scaler = StandardScaler()
- X_train = scaler.fit_transform(X_train)
- X_test = scaler.transform(X_test)
- id3 = DecisionTreeClassifier(criterion='entropy', random_state=42)
- id3.fit(X_train, y_train)
- # Predictions
- y_pred = id3.predict(X_test)
- print("Accuracy:", accuracy_score(y_test, y_pred))
- print("\nConfusion Matrix:\n", confusion_matrix(y_test, y_pred))
- print("\nClassification Report:\n", classification_report(y_test, y_pred))
- plt.figure(figsize=(20,12))
- plot_tree(
- id3,
- feature_names=['Gender','Age','EstimatedSalary'],
- class_names=['Not Purchased','Purchased'],
- fontsize=15,
- filled=True
- )
- plt.show()
- new_sample = pd.DataFrame({'Gender':[1], 'Age':[30], 'EstimatedSalary':[100000]})
- new_sample_scaled = scaler.transform(new_sample)
- prediction = id3.predict(new_sample_scaled)
- predicted_class = 'Purchased' if prediction[0]==1 else 'Not Purchased'
- print(f"The predicted purchase status for the new sample is {predicted_class}")
- https://jumpshare.com/s/qM5yLBS964qeCHauD2d2
Tags:
ML
Advertisement
Add Comment
Please, Sign In to add comment
-
⭐✅ MAKE $2500 IN 15 MIN⭐⭐⭐ O
JavaScript | 4 sec ago | 0.24 KB
-
⭐⭐⭐Swapzone.io Glitch (Working)⭐⭐
Java | 13 sec ago | 0.10 KB
-
⭐✅ Exploit 2500$ in 15 Minutes⭐⭐⭐ 1
JavaScript | 17 sec ago | 0.24 KB
-
Free Crypto Method (NEVER SEEN BEFORE)⭐⭐ D
JavaScript | 30 sec ago | 0.24 KB
-
⭐✅ Swapzone Glitch ✅ Working⭐⭐⭐ G
JavaScript | 40 sec ago | 0.24 KB
-
⭐✅ Swapzone Glitch ✅ Working⭐⭐⭐ 5
JavaScript | 44 sec ago | 0.24 KB
-
✅ Make $2500 in 20 minutes⭐⭐⭐ J
JavaScript | 52 sec ago | 0.24 KB
-
✅ Make $2500 in 20 minutes⭐⭐⭐ 6
JavaScript | 57 sec ago | 0.24 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand