CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 12:44:13 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=67551b0d11be7811dff064f18fca498de6d527801c9d2f82bcd739eb0bb093a1a%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22AQkSGbcV7d2FuFpEqIYHPd_3JVXGt68x%22%3B%7D; HttpOnly; Path=/
cf-ray: 98ce72948f65f473-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 huge profits on trading ⭐⭐ J
JavaScript | 1 sec ago | 0.24 KB
-
⭐✅ MAKE $2500 IN 15 MIN⭐⭐⭐ 6
JavaScript | 2 sec ago | 0.24 KB
-
✅⭐ Make $2500 in 15 minutes ✅ NEVER SEEN BEFO...
JavaScript | 7 sec ago | 0.24 KB
-
⭐✅ MAKE $2500 IN 15 MIN⭐⭐⭐ 4
JavaScript | 11 sec ago | 0.24 KB
-
⭐✅ Exploit 2500$ in 15 Minutes⭐⭐⭐ 3
JavaScript | 13 sec ago | 0.24 KB
-
✅⭐ Make $2500 in 15 minutes ✅ NEVER SEEN BEFO...
JavaScript | 13 sec ago | 0.24 KB
-
⭐✅ Exploit 2500$ in 15 Minutes⭐⭐⭐ C
JavaScript | 22 sec ago | 0.24 KB
-
Free Crypto Method (NEVER SEEN BEFORE)⭐⭐ 3
JavaScript | 24 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