{ "cells": [ { "cell_type": "code", "execution_count": 17, "id": "2e314513", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Accuracy: 0.8417508417508418\n" ] } ], "source": [ "import pandas as pd\n", "from sklearn.model_selection import train_test_split\n", "from sklearn.ensemble import RandomForestClassifier\n", "from sklearn.metrics import accuracy_score, classification_report\n", "\n", "# Load the dataset\n", "df = pd.read_csv('dataset.csv')\n", "\n", "# Split the dataset into features and target variable\n", "X = df.drop('PlacedOrNot', axis=1) # Features\n", "y = df['PlacedOrNot'] # Target variable\n", "\n", "# Convert categorical features to numerical using one-hot encoding\n", "X = pd.get_dummies(X)\n", "\n", "# Split the dataset into training and testing sets\n", "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n", "\n", "# Create a Random Forest Classifier\n", "clf = RandomForestClassifier(n_estimators=100, random_state=42)\n", "\n", "# Train the model\n", "clf.fit(X_train, y_train)\n", "\n", "accuracy = clf.score(X_test, y_test)\n", "print('Accuracy:', accuracy)\n", "\n", "# Export the trained model as a pickle file\n", "with open('random_forest_model.pkl', 'wb') as f:\n", " pickle.dump(clf, f)" ] }, { "cell_type": "code", "execution_count": null, "id": "ad204a75", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "11ad2756", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "913f5ce2", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.12" } }, "nbformat": 4, "nbformat_minor": 5 }