Upload Untitled1.ipynb
Browse files- Untitled1.ipynb +96 -0
Untitled1.ipynb
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 17,
|
6 |
+
"id": "2e314513",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [
|
9 |
+
{
|
10 |
+
"name": "stdout",
|
11 |
+
"output_type": "stream",
|
12 |
+
"text": [
|
13 |
+
"Accuracy: 0.8417508417508418\n"
|
14 |
+
]
|
15 |
+
}
|
16 |
+
],
|
17 |
+
"source": [
|
18 |
+
"import pandas as pd\n",
|
19 |
+
"from sklearn.model_selection import train_test_split\n",
|
20 |
+
"from sklearn.ensemble import RandomForestClassifier\n",
|
21 |
+
"from sklearn.metrics import accuracy_score, classification_report\n",
|
22 |
+
"\n",
|
23 |
+
"# Load the dataset\n",
|
24 |
+
"df = pd.read_csv('dataset.csv')\n",
|
25 |
+
"\n",
|
26 |
+
"# Split the dataset into features and target variable\n",
|
27 |
+
"X = df.drop('PlacedOrNot', axis=1) # Features\n",
|
28 |
+
"y = df['PlacedOrNot'] # Target variable\n",
|
29 |
+
"\n",
|
30 |
+
"# Convert categorical features to numerical using one-hot encoding\n",
|
31 |
+
"X = pd.get_dummies(X)\n",
|
32 |
+
"\n",
|
33 |
+
"# Split the dataset into training and testing sets\n",
|
34 |
+
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
|
35 |
+
"\n",
|
36 |
+
"# Create a Random Forest Classifier\n",
|
37 |
+
"clf = RandomForestClassifier(n_estimators=100, random_state=42)\n",
|
38 |
+
"\n",
|
39 |
+
"# Train the model\n",
|
40 |
+
"clf.fit(X_train, y_train)\n",
|
41 |
+
"\n",
|
42 |
+
"accuracy = clf.score(X_test, y_test)\n",
|
43 |
+
"print('Accuracy:', accuracy)\n",
|
44 |
+
"\n",
|
45 |
+
"# Export the trained model as a pickle file\n",
|
46 |
+
"with open('random_forest_model.pkl', 'wb') as f:\n",
|
47 |
+
" pickle.dump(clf, f)"
|
48 |
+
]
|
49 |
+
},
|
50 |
+
{
|
51 |
+
"cell_type": "code",
|
52 |
+
"execution_count": null,
|
53 |
+
"id": "ad204a75",
|
54 |
+
"metadata": {},
|
55 |
+
"outputs": [],
|
56 |
+
"source": []
|
57 |
+
},
|
58 |
+
{
|
59 |
+
"cell_type": "code",
|
60 |
+
"execution_count": null,
|
61 |
+
"id": "11ad2756",
|
62 |
+
"metadata": {},
|
63 |
+
"outputs": [],
|
64 |
+
"source": []
|
65 |
+
},
|
66 |
+
{
|
67 |
+
"cell_type": "code",
|
68 |
+
"execution_count": null,
|
69 |
+
"id": "913f5ce2",
|
70 |
+
"metadata": {},
|
71 |
+
"outputs": [],
|
72 |
+
"source": []
|
73 |
+
}
|
74 |
+
],
|
75 |
+
"metadata": {
|
76 |
+
"kernelspec": {
|
77 |
+
"display_name": "Python 3 (ipykernel)",
|
78 |
+
"language": "python",
|
79 |
+
"name": "python3"
|
80 |
+
},
|
81 |
+
"language_info": {
|
82 |
+
"codemirror_mode": {
|
83 |
+
"name": "ipython",
|
84 |
+
"version": 3
|
85 |
+
},
|
86 |
+
"file_extension": ".py",
|
87 |
+
"mimetype": "text/x-python",
|
88 |
+
"name": "python",
|
89 |
+
"nbconvert_exporter": "python",
|
90 |
+
"pygments_lexer": "ipython3",
|
91 |
+
"version": "3.9.12"
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"nbformat": 4,
|
95 |
+
"nbformat_minor": 5
|
96 |
+
}
|