{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "erRKYnEAzvoF" }, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "jY6Aar2MzzPO" }, "outputs": [], "source": [ "file_url = '../Dataset/dataset_44_spambase.csv'" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "61kW2l6DzzS5" }, "outputs": [], "source": [ "df = pd.read_csv(file_url)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 255 }, "colab_type": "code", "id": "VFjr_puO5GBs", "outputId": "7b7ae28c-8e12-4209-8bb6-c3d6fe079280" }, "outputs": [], "source": [ "print(df)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "2UG8KAbF7wZD" }, "outputs": [], "source": [ "target = df.pop('class')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 221 }, "colab_type": "code", "id": "sl-jGqPF71Lc", "outputId": "ebf9bebb-566b-4866-a4c3-0f75cacd4252" }, "outputs": [], "source": [ "print(target)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "FMhAVQp676Pp" }, "outputs": [], "source": [ "from sklearn.ensemble import RandomForestClassifier" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "PC1vgs2a8DWi" }, "outputs": [], "source": [ "seed = 168" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "M_NSuDKU8BQq" }, "outputs": [], "source": [ "rf_model = RandomForestClassifier(random_state=seed)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 170 }, "colab_type": "code", "id": "H4p4BC6D8GD1", "outputId": "5ae1448c-a6fc-4033-9e09-f93970f60fe8" }, "outputs": [], "source": [ "rf_model.fit(df, target)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "4udU7PC68KSM" }, "outputs": [], "source": [ "preds = rf_model.predict(df)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "colab_type": "code", "id": "Fe6XUUSf_YbP", "outputId": "09da052f-600d-4b4f-9446-15ff85aaa4ab" }, "outputs": [], "source": [ "print(preds)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "7UtNAj-d-1JC" }, "outputs": [], "source": [ "from sklearn.metrics import accuracy_score" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "Pi0wiBZ9_j6y" }, "outputs": [], "source": [ "acc_score = accuracy_score(target, preds)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "colab_type": "code", "id": "NxfBXpEB-4Bw", "outputId": "4d174d14-1a89-412b-82d4-92aa6ae6d0e3" }, "outputs": [], "source": [ "print(acc_score)" ] } ], "metadata": { "colab": { "collapsed_sections": [], "name": "Activity1_1.ipynb", "provenance": [] }, "kernelspec": { "display_name": "Python 3", "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.8.6" } }, "nbformat": 4, "nbformat_minor": 1 }