{ "cells": [ { "cell_type": "code", "execution_count": 83, "id": "b8786441", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "from sklearn.datasets import load_iris\n", "from sklearn.tree import DecisionTreeClassifier\n", "from sklearn. ensemble import RandomForestClassifier, AdaBoostClassifier" ] }, { "cell_type": "code", "execution_count": 77, "id": "cb138bbf", "metadata": {}, "outputs": [], "source": [ "iris = load_iris()\n", "iris_df = pd.DataFrame(data= np.c_[iris['data'], iris['target']], columns= iris['feature_names'] + ['target'])\n", "\n", "X = iris_df.drop(['target'],axis=1)\n", "y = iris_df.target\n", "\n", "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.7, random_state=i)" ] }, { "cell_type": "code", "execution_count": 80, "id": "98ddb765", "metadata": {}, "outputs": [], "source": [ "#Descision Tree\n", "\n", "dt = DecisionTreeClassifier()\n", "dt.fit(x_train,y_train)\n", "\n", "dt.score(x_test,y_test)" ] }, { "cell_type": "code", "execution_count": 81, "id": "df1363d3", "metadata": {}, "outputs": [], "source": [ "#Random Forest\n", "\n", "rf = RandomForestClassifier(n_estimators=10)\n", "rf.fit(x_train,y_train)\n", "\n", "rf.score(x_test,y_test)" ] }, { "cell_type": "code", "execution_count": null, "id": "e2f03f7f", "metadata": {}, "outputs": [], "source": [ "# Ada Boost\n", "\n", "adb = AdaBoostClassifier(DecisionTreeClassifier(),n_estimators = 10, learning_rate = 1)\n", "adb.fit(x_train,y_train)\n", "\n", "adb.score(x_test,y_test)" ] } ], "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.10.8" } }, "nbformat": 4, "nbformat_minor": 5 }